Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="HealthTrendBot", layout="wide")
|
| 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 required
|
| 14 |
+
|
| 15 |
+
if 'conversation_history' not in st.session_state:
|
| 16 |
+
st.session_state.conversation_history = [
|
| 17 |
+
{"role": "system", "content": "You are a knowledgeable assistant specializing in public health trends."}
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
st.title("HealthTrendBot: Public Health Trend Analyzer")
|
| 21 |
+
|
| 22 |
+
# Display conversation
|
| 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():
|
| 32 |
+
st.session_state.conversation_history.append({"role": "user", "content": user_input})
|
| 33 |
+
try:
|
| 34 |
+
response = openai.ChatCompletion.create(
|
| 35 |
+
model="deepseek-chat",
|
| 36 |
+
messages=st.session_state.conversation_history
|
| 37 |
+
)
|
| 38 |
+
assistant_reply = response.choices[0].message["content"]
|
| 39 |
+
st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
|
| 40 |
+
st.experimental_rerun()
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"Error: {e}")
|
| 43 |
+
elif st.button("Send"):
|
| 44 |
+
st.warning("Please enter a message.")
|