Spaces:
Sleeping
Sleeping
Update frontend.py
Browse files- frontend.py +10 -13
frontend.py
CHANGED
|
@@ -6,14 +6,18 @@ import os
|
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
# Define the URL of your FastAPI endpoint
|
| 9 |
-
url = "https://shahabkahn-medical-assistant.hf.space"
|
| 10 |
|
| 11 |
# Initialize the session state
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Function to handle the new chat button click
|
| 15 |
def new_chat():
|
| 16 |
st.session_state.chat_history = [] # Clear the chat history
|
|
|
|
| 17 |
|
| 18 |
# Streamlit app
|
| 19 |
def app():
|
|
@@ -26,17 +30,8 @@ def app():
|
|
| 26 |
unsafe_allow_html=True)
|
| 27 |
|
| 28 |
# Placeholder text for the input box
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# JavaScript to handle the placeholder behavior
|
| 33 |
-
placeholder_script = f"""
|
| 34 |
-
<script>
|
| 35 |
-
const inputElement = document.querySelector('input[data-baseweb="input"]');
|
| 36 |
-
inputElement.placeholder = "Enter your question";
|
| 37 |
-
</script>
|
| 38 |
-
"""
|
| 39 |
-
st.markdown(placeholder_script, unsafe_allow_html=True)
|
| 40 |
|
| 41 |
# Handle form submission
|
| 42 |
submit_button = st.button("➡️")
|
|
@@ -54,6 +49,8 @@ def app():
|
|
| 54 |
answer = response.json().get("answer")
|
| 55 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 56 |
st.session_state.chat_history.append({"role": "assistant", "content": answer})
|
|
|
|
|
|
|
| 57 |
else:
|
| 58 |
st.error(f"Error: {response.status_code} {response.text}")
|
| 59 |
except requests.RequestException as e:
|
|
|
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
# Define the URL of your FastAPI endpoint
|
| 9 |
+
url = "https://shahabkahn-medical-assistant.hf.space/query"
|
| 10 |
|
| 11 |
# Initialize the session state
|
| 12 |
+
if "chat_history" not in st.session_state:
|
| 13 |
+
st.session_state.chat_history = []
|
| 14 |
+
if "user_input" not in st.session_state:
|
| 15 |
+
st.session_state.user_input = ""
|
| 16 |
|
| 17 |
# Function to handle the new chat button click
|
| 18 |
def new_chat():
|
| 19 |
st.session_state.chat_history = [] # Clear the chat history
|
| 20 |
+
st.session_state.user_input = "" # Clear the user input
|
| 21 |
|
| 22 |
# Streamlit app
|
| 23 |
def app():
|
|
|
|
| 30 |
unsafe_allow_html=True)
|
| 31 |
|
| 32 |
# Placeholder text for the input box
|
| 33 |
+
input_text = st.text_input("Your Question", placeholder="Enter your question here...",
|
| 34 |
+
key="user_input", help="Type your question here...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Handle form submission
|
| 37 |
submit_button = st.button("➡️")
|
|
|
|
| 49 |
answer = response.json().get("answer")
|
| 50 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 51 |
st.session_state.chat_history.append({"role": "assistant", "content": answer})
|
| 52 |
+
# Clear the user input after submission
|
| 53 |
+
st.session_state.user_input = ""
|
| 54 |
else:
|
| 55 |
st.error(f"Error: {response.status_code} {response.text}")
|
| 56 |
except requests.RequestException as e:
|