Suprito commited on
Commit
6e21dc9
·
verified ·
1 Parent(s): 4e26fb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -1,41 +1,41 @@
1
- import streamlit as st
2
- import requests # Standard library for sending API requests
3
-
4
- st.set_page_config(page_title="Medical AI Assistant", layout="centered")
5
- st.title("⚕️ General Medicine Chatbot")
6
-
7
- # This is the address of your FastAPI "Brain"
8
- API_URL = "http://127.0.0.1:8000/ask"
9
-
10
- # Initialize chat history
11
- if "messages" not in st.session_state:
12
- st.session_state.messages = []
13
-
14
- # Display previous messages
15
- for message in st.session_state.messages:
16
- with st.chat_message(message["role"]):
17
- st.markdown(message["content"])
18
-
19
- if prompt := st.chat_input("Ask a medical question..."):
20
- # 1. Display user message
21
- st.chat_message("user").markdown(prompt)
22
- st.session_state.messages.append({"role": "user", "content": prompt})
23
-
24
- # 2. Call the API
25
- with st.chat_message("assistant"):
26
- with st.spinner("Thinking..."):
27
- try:
28
- # We send the query to your FastAPI server
29
- # Note: 'query' must match the Pydantic model in main.py
30
- payload = {"query": prompt}
31
- response = requests.post(API_URL, json=payload)
32
-
33
- if response.status_code == 200:
34
- answer = response.json().get("answer", "No answer found.")
35
- st.markdown(answer)
36
- st.session_state.messages.append({"role": "assistant", "content": answer})
37
- else:
38
- st.error(f"API Error {response.status_code}: {response.text}")
39
-
40
- except Exception as e:
41
  st.error(f"Could not connect to the API. Is Uvicorn running? Error: {e}")
 
1
+ import streamlit as st
2
+ import requests # Standard library for sending API requests
3
+
4
+ st.set_page_config(page_title="Medical AI Assistant", layout="centered")
5
+ st.title("⚕️ General Medicine Chatbot")
6
+
7
+ # This is the address of your FastAPI "Brain"
8
+ API_URL = "http://0.0.0.0:8000/ask"
9
+
10
+ # Initialize chat history
11
+ if "messages" not in st.session_state:
12
+ st.session_state.messages = []
13
+
14
+ # Display previous messages
15
+ for message in st.session_state.messages:
16
+ with st.chat_message(message["role"]):
17
+ st.markdown(message["content"])
18
+
19
+ if prompt := st.chat_input("Ask a medical question..."):
20
+ # 1. Display user message
21
+ st.chat_message("user").markdown(prompt)
22
+ st.session_state.messages.append({"role": "user", "content": prompt})
23
+
24
+ # 2. Call the API
25
+ with st.chat_message("assistant"):
26
+ with st.spinner("Thinking..."):
27
+ try:
28
+ # We send the query to your FastAPI server
29
+ # Note: 'query' must match the Pydantic model in main.py
30
+ payload = {"query": prompt}
31
+ response = requests.post(API_URL, json=payload)
32
+
33
+ if response.status_code == 200:
34
+ answer = response.json().get("answer", "No answer found.")
35
+ st.markdown(answer)
36
+ st.session_state.messages.append({"role": "assistant", "content": answer})
37
+ else:
38
+ st.error(f"API Error {response.status_code}: {response.text}")
39
+
40
+ except Exception as e:
41
  st.error(f"Could not connect to the API. Is Uvicorn running? Error: {e}")