hareshchander commited on
Commit
09702e1
·
verified ·
1 Parent(s): 421898a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -1,19 +1,11 @@
1
  import os
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:
@@ -22,9 +14,7 @@ if "conversation_history" not in st.session_state:
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
  ]
@@ -45,15 +35,24 @@ user_input = st.text_input("Your Message:")
45
 
46
  if st.button("Send") and user_input.strip():
47
  st.session_state.conversation_history.append({"role": "user", "content": user_input})
48
- try:
49
- response = openai.ChatCompletion.create(
50
- model="deepseek-chat",
51
- messages=st.session_state.conversation_history
52
- )
53
- assistant_reply = response.choices[0].message["content"]
54
- st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
55
- st.experimental_rerun()
56
- except Exception as e:
57
- st.error(f"Error: {e}")
 
 
 
 
 
 
 
 
 
58
  elif st.button("Send"):
59
  st.warning("Please enter a message.")
 
1
  import os
2
  import streamlit as st
 
3
 
4
  # ----- Streamlit Page Config -----
5
  st.set_page_config(page_title="HealthTrendBot: Public Health Trend Analyzer", layout="wide")
6
 
7
+ # ----- Load API Key -----
8
  api_key = os.getenv("DEEP_SEEK_API")
 
 
 
 
 
 
 
9
 
10
  # ----- Initialize conversation -----
11
  if "conversation_history" not in st.session_state:
 
14
  "role": "system",
15
  "content": (
16
  "You are a highly knowledgeable and extremely helpful assistant specialized "
17
+ "in analyzing public health trends. Your responses must be clear, concise, and highly informative."
 
 
18
  )
19
  }
20
  ]
 
35
 
36
  if st.button("Send") and user_input.strip():
37
  st.session_state.conversation_history.append({"role": "user", "content": user_input})
38
+
39
+ if api_key is None:
40
+ # Demo response when no API key is available
41
+ assistant_reply = "🤖 Demo Mode: Please set DEEP_SEEK_API to get real responses."
42
+ else:
43
+ import openai
44
+ openai.api_key = api_key
45
+ openai.api_base = "https://api.deepseek.com"
46
+ try:
47
+ response = openai.ChatCompletion.create(
48
+ model="deepseek-chat",
49
+ messages=st.session_state.conversation_history
50
+ )
51
+ assistant_reply = response.choices[0].message["content"]
52
+ except Exception as e:
53
+ assistant_reply = f"Error: {e}"
54
+
55
+ st.session_state.conversation_history.append({"role": "assistant", "content": assistant_reply})
56
+ st.experimental_rerun()
57
  elif st.button("Send"):
58
  st.warning("Please enter a message.")