Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Service に Streamlit アプリをデプロイする #17

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,5 @@ cython_debug/

# Project
*.env
requirements.txt
artifacts/
generated/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ To publish the docker image to Docker Hub, you need to set the following secrets
gh secret set DOCKERHUB_USERNAME --body $DOCKERHUB_USERNAME
gh secret set DOCKERHUB_TOKEN --body $DOCKERHUB_TOKEN
```

## Deployment

### App Service

以下の 2 点の設定を行うことで、Streamlit アプリケーションを Azure App Service にデプロイすることができる。

1. Settings > Configuration > Startup Command に streamlit 用のコマンド `python -m streamlit run apps/4_streamlit_chat_history/main.py --server.port 8000 --server.address 0.0.0.0` をセット (※ 実行スクリプトは適宜変更すること。App Service はデフォルトで 8000 ポートを listen しているため、`--server.port 8000` が必要。)
1. `SCM_DO_BUILD_DURING_DEPLOYMENT` を `true` に設定する

#### 参考資料

- [Streamlit を Azure App Service で動かす!](https://qiita.com/takashiuesaka/items/491b21e9afb34bbb6e6d)
- [WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv](https://stackoverflow.com/a/61720957)
- [How to deploy a streamlit application on Azure App Service (WebApp)](https://learn.microsoft.com/en-us/answers/questions/1470782/how-to-deploy-a-streamlit-application-on-azure-app)
1 change: 0 additions & 1 deletion apps/2_streamlit_chat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
azure_openai_api_key = st.text_input(
label="AZURE_OPENAI_API_KEY",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

フロントから API Key が参照できてしまうためデフォルト値をクリア。他も同じ。

value=getenv("AZURE_OPENAI_API_KEY"),
key="AZURE_OPENAI_API_KEY",
type="password",
)
Expand Down
1 change: 0 additions & 1 deletion apps/4_streamlit_chat_history/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def store_chat_history(container: ContainerProxy):
)
azure_openai_api_key = st.text_input(
label="AZURE_OPENAI_API_KEY",
value=getenv("AZURE_OPENAI_API_KEY"),
key="AZURE_OPENAI_API_KEY",
type="password",
)
Expand Down
1 change: 0 additions & 1 deletion apps/99_streamlit_llm_examples/pages/1_File_Q&A.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
azure_openai_api_key = st.text_input(
label="AZURE_OPENAI_API_KEY",
value=getenv("AZURE_OPENAI_API_KEY"),
key="AZURE_OPENAI_API_KEY",
type="password",
)
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poetry.toml がマスター。重複管理になり避けたいが、App Service のデプロイでリポジトリルートに requirements.txt を配置することが前提になっているためやむなし。

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openai==1.37.1
python-dotenv==1.0.1
streamlit==1.37.0
azure-cosmos==4.7.0