Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,45 @@ import os
|
|
| 2 |
import streamlit as st
|
| 3 |
import openai
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
|
|
|
| 7 |
api_key = os.getenv("DEEP_SEEK_API")
|
| 8 |
if not api_key:
|
| 9 |
-
st.error("Please set the DEEP_SEEK_API environment variable.")
|
| 10 |
st.stop()
|
| 11 |
|
|
|
|
| 12 |
openai.api_key = api_key
|
| 13 |
-
openai.api_base = "https://api.deepseek.com" # if
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
st.session_state.conversation_history = [
|
| 17 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
]
|
| 19 |
|
|
|
|
| 20 |
st.title("HealthTrendBot: Public Health Trend Analyzer")
|
| 21 |
|
| 22 |
-
# Display
|
|
|
|
| 23 |
for msg in st.session_state.conversation_history[1:]:
|
| 24 |
if msg["role"] == "user":
|
| 25 |
st.markdown(f"**You:** {msg['content']}")
|
| 26 |
else:
|
| 27 |
st.markdown(f"**HealthTrendBot:** {msg['content']}")
|
| 28 |
|
|
|
|
| 29 |
user_input = st.text_input("Your Message:")
|
| 30 |
|
| 31 |
if st.button("Send") and user_input.strip():
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import openai
|
| 4 |
|
| 5 |
+
# ----- Streamlit Page Config -----
|
| 6 |
+
st.set_page_config(page_title="HealthTrendBot: Public Health Trend Analyzer", layout="wide")
|
| 7 |
|
| 8 |
+
# ----- Load API Key from Hugging Face Secrets -----
|
| 9 |
api_key = os.getenv("DEEP_SEEK_API")
|
| 10 |
if not api_key:
|
| 11 |
+
st.error("Please set the DEEP_SEEK_API environment variable in your Hugging Face Space secrets.")
|
| 12 |
st.stop()
|
| 13 |
|
| 14 |
+
# ----- OpenAI / DeepSeek Client Setup -----
|
| 15 |
openai.api_key = api_key
|
| 16 |
+
openai.api_base = "https://api.deepseek.com" # Adjust if needed
|
| 17 |
|
| 18 |
+
# ----- Initialize conversation -----
|
| 19 |
+
if "conversation_history" not in st.session_state:
|
| 20 |
st.session_state.conversation_history = [
|
| 21 |
+
{
|
| 22 |
+
"role": "system",
|
| 23 |
+
"content": (
|
| 24 |
+
"You are a highly knowledgeable and extremely helpful assistant specialized "
|
| 25 |
+
"in analyzing public health trends and providing data-driven insights. "
|
| 26 |
+
"Your responses must be clear, concise, and highly informative. "
|
| 27 |
+
"Always provide detailed, accurate, and well-researched explanations."
|
| 28 |
+
)
|
| 29 |
+
}
|
| 30 |
]
|
| 31 |
|
| 32 |
+
# ----- App Title -----
|
| 33 |
st.title("HealthTrendBot: Public Health Trend Analyzer")
|
| 34 |
|
| 35 |
+
# ----- Display Conversation -----
|
| 36 |
+
st.subheader("Conversation:")
|
| 37 |
for msg in st.session_state.conversation_history[1:]:
|
| 38 |
if msg["role"] == "user":
|
| 39 |
st.markdown(f"**You:** {msg['content']}")
|
| 40 |
else:
|
| 41 |
st.markdown(f"**HealthTrendBot:** {msg['content']}")
|
| 42 |
|
| 43 |
+
# ----- User Input -----
|
| 44 |
user_input = st.text_input("Your Message:")
|
| 45 |
|
| 46 |
if st.button("Send") and user_input.strip():
|