Skip to content

Commit 42da58b

Browse files
authored
Merge pull request #124 from ks6088ts-labs/feature/issue-123_refactor-frontend
move entrypoint for frontend app
2 parents 7ab5fab + c1b4f78 commit 42da58b

File tree

16 files changed

+73
-74
lines changed

16 files changed

+73
-74
lines changed

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,14 @@ ci-test-docker: docker-compose-lint ## run CI test for Docker
101101
# ---
102102
# Application
103103
# ---
104-
SOLUTION_NAME ?= "SANDBOX"
105-
BACKEND_URL ?= "http://localhost:8000"
106-
107104
.PHONY: backend
108105
backend: ## run backend
109106
poetry run python main.py backend --reload
110107

111108
.PHONY: frontend
112109
frontend: ## run frontend
113-
poetry run streamlit run main.py -- frontend -- \
114-
--solution-name=$(SOLUTION_NAME) \
115-
--backend-url=$(BACKEND_URL)
110+
cd frontend \
111+
&& poetry run streamlit run main.py
116112

117113
# ---
118114
# Azure Functions

compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
context: .
55
dockerfile: dockerfiles/backend.Dockerfile
66
image: ks6088ts/azure-ai-services-solutions:backend-latest
7-
command: python main.py backend --port 8888 --debug
7+
command: python main.py backend --port 8888
88
ports:
99
- 8888:8888
1010
volumes:
@@ -16,7 +16,7 @@ services:
1616
context: .
1717
dockerfile: dockerfiles/frontend.Dockerfile
1818
image: ks6088ts/azure-ai-services-solutions:frontend-latest
19-
command: streamlit run main.py --server.port=8501 --server.address=0.0.0.0 -- frontend --solution-name sandbox --backend-url http://backend:8888 --debug
19+
command: streamlit run frontend/main.py
2020
ports:
2121
- 8501:8501
2222
volumes:

dockerfiles/frontend.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ COPY . .
2121
# Install dependencies
2222
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
2323

24-
CMD ["python", "main.py", "frontend", "--help"]
24+
CMD ["streamlit", "run", "frontend/main.py", "--help"]
File renamed without changes.

frontend/__init__.py

Whitespace-only changes.

frontend/entrypoint.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

frontend/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import streamlit as st
2+
3+
4+
def init_page():
5+
st.set_page_config(page_title="Azure AI Solutions", page_icon="🧐")
6+
7+
8+
def main():
9+
init_page()
10+
11+
st.sidebar.success("Please select apps from the sidebar menu")
12+
13+
st.markdown(
14+
"""
15+
### Welcome to Azure AI Solutions
16+
17+
- This app shows some use cases with Azure AI Services
18+
- Got to the pages from the left menu
19+
"""
20+
)
21+
22+
23+
if __name__ == "__main__":
24+
main()

frontend/solutions/azure_ai_vision.py renamed to frontend/pages/azure_ai_vision.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
from urllib.parse import urljoin
55

66
import streamlit as st
7-
8-
from frontend.solutions.utilities import http_post_file
7+
from utilities import http_post_file
98

109
logger = logging.getLogger(__name__)
1110

1211

13-
def start(
12+
def main(
1413
backend_url: str,
1514
log_level: int,
1615
):
@@ -43,3 +42,10 @@ def start(
4342
st.write(response)
4443
else:
4544
st.warning("Please upload a file first")
45+
46+
47+
if __name__ == "__main__":
48+
main(
49+
backend_url="http://localhost:8000",
50+
log_level=logging.DEBUG,
51+
)

frontend/solutions/chat.py renamed to frontend/pages/chat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from openai import AzureOpenAI
77

88
logger = logging.getLogger(__name__)
9-
load_dotenv("./settings/frontend.env")
9+
load_dotenv()
1010

1111

12-
def start(
12+
def main(
1313
backend_url: str,
1414
log_level: int,
1515
):
@@ -52,3 +52,10 @@ def start(
5252
assistant_text += content
5353
placeholder.write(assistant_text)
5454
st.session_state.messages.append({"role": "assistant", "content": assistant_text})
55+
56+
57+
if __name__ == "__main__":
58+
main(
59+
backend_url="http://localhost:8000",
60+
log_level=logging.DEBUG,
61+
)

frontend/solutions/document_intelligence.py renamed to frontend/pages/document_intelligence.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
from urllib.parse import urljoin
55

66
import streamlit as st
7-
8-
from frontend.solutions.utilities import http_post_file
7+
from utilities import http_post_file
98

109
logger = logging.getLogger(__name__)
1110

1211

13-
def start(
12+
def main(
1413
backend_url: str,
1514
log_level: int,
1615
):
@@ -41,3 +40,10 @@ def start(
4140
)
4241
)
4342
st.write(response)
43+
44+
45+
if __name__ == "__main__":
46+
main(
47+
backend_url="http://localhost:8000",
48+
log_level=logging.DEBUG,
49+
)

0 commit comments

Comments
 (0)