Develop GenAI Apps with Gemini and Streamlit : Cloud Run에서 Gemini Pro와 통합된 Streamlit 앱 배포하기

JIEUN JANG·2024년 8월 4일
0

Google Cloud Skills Boost

목록 보기
12/13

1. 애플리케이션을 로컬로 실행

Cloud Shell 실행

1-1. 저장소 복제

# 저장소 클론
git clone https://github.com/GoogleCloudPlatform/generative-ai.git

# Cloud Shell에서 gemini-streamlit-cloudrun 디렉터리로 이동
cd generative-ai/gemini/sample-apps/gemini-streamlit-cloudrun

1-2. 애플리케이션 실행

# Python 가상 환경을 설정하고 종속 항목을 설치
python3 -m venv gemini-streamlit
source gemini-streamlit/bin/activate
pip install -r requirements.txt
# GCP_PROJECT, GCP_REGION 설정
GCP_PROJECT='Project ID'
GCP_REGION='Region'

# 애플리케이션 로컬 실행
streamlit run app.py \
  --browser.serverAddress=localhost \
  --server.enableCORS=false \
  --server.enableXsrfProtection=false \
  --server.port 8080

서버가 실행된 해당 url로 들어가보면 이런 API가 실행된다.
Generate story를 선택해서 키워드 값을 입력하면 그에 맞는 Love, Adventure에 대한 스토리가 생성된다.


2. 애플리케이션을 빌드하여 Cloud Run에 배포

# 애플리케이션의 Docker 이미지를 빌드하고 Artifact Registry에 푸시, Artifact Registry 이름을 가리키는 하나의 환경 변수를 설정
AR_REPO='gemini-repo'
SERVICE_NAME='gemini-streamlit-app' 
gcloud artifacts repositories create "$AR_REPO" --location="$GCP_REGION" --repository-format=Docker
gcloud builds submit --tag "$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$AR_REPO/$SERVICE_NAME"

# 이전 단계에서 빌드하고 Artifact Registry에 푸시한 이미지로 Cloud Run에서 서비스를 배포
gcloud run deploy "$SERVICE_NAME" \
  --port=8080 \
  --image="$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$AR_REPO/$SERVICE_NAME" \
  --allow-unauthenticated \
  --region=$GCP_REGION \
  --platform=managed  \
  --project=$GCP_PROJECT \
  --set-env-vars=GCP_PROJECT=$GCP_PROJECT,GCP_REGION=$GCP_REGION

도커로 빌드해서 Cloud에 배포한 url에 접속해서 API를 테스트해본다.
비디오에 대한 요약도 잘 해준다. 생성형 AI 최고다.

0개의 댓글