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.")