Spaces:
Runtime error
Runtime error
File size: 2,041 Bytes
19c451c 8d6bae1 19c451c 09702e1 19c451c 8d6bae1 19c451c 8d6bae1 09702e1 8d6bae1 19c451c 8d6bae1 19c451c 8d6bae1 19c451c 8d6bae1 19c451c 09702e1 19c451c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import os
import streamlit as st
# ----- Streamlit Page Config -----
st.set_page_config(page_title="HealthTrendBot: Public Health Trend Analyzer", layout="wide")
# ----- Load API Key -----
api_key = os.getenv("DEEP_SEEK_API")
# ----- Initialize conversation -----
if "conversation_history" not in st.session_state:
st.session_state.conversation_history = [
{
"role": "system",
"content": (
"You are a highly knowledgeable and extremely helpful assistant specialized "
"in analyzing public health trends. Your responses must be clear, concise, and highly informative."
)
}
]
# ----- App Title -----
st.title("HealthTrendBot: Public Health Trend Analyzer")
# ----- Display Conversation -----
st.subheader("Conversation:")
for msg in st.session_state.conversation_history[1:]:
if msg["role"] == "user":
st.markdown(f"**You:** {msg['content']}")
else:
st.markdown(f"**HealthTrendBot:** {msg['content']}")
# ----- User Input -----
user_input = st.text_input("Your Message:")
if st.button("Send") and user_input.strip():
st.session_state.conversation_history.append({"role": "user", "content": user_input})
if api_key is None:
# Demo response when no API key is available
assistant_reply = "🤖 Demo Mode: Please set DEEP_SEEK_API to get real responses."
else:
import openai
openai.api_key = api_key
openai.api_base = "https://api.deepseek.com"
try:
response = openai.ChatCompletion.create(
model="deepseek-chat",
messages=st.session_state.conversation_history
)
assistant_reply = response.choices[0].message["content"]
except Exception as e:
assistant_reply = f"Error: {e}"
st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
st.experimental_rerun()
elif st.button("Send"):
st.warning("Please enter a message.")
|