CCockrum commited on
Commit
6db00e7
·
verified ·
1 Parent(s): ab8074b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -42
app.py CHANGED
@@ -22,16 +22,6 @@ if NASA_API_KEY is None:
22
  # Must be the first Streamlit command!
23
  st.set_page_config(page_title="HAL - NASA ChatBot", page_icon="🚀")
24
 
25
- # --- Helper to load spaCy model with fallback ---
26
- def load_spacy_model():
27
- try:
28
- return spacy.load("en_core_web_sm")
29
- except OSError:
30
- subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"], check=True)
31
- return spacy.load("en_core_web_sm")
32
-
33
- nlp_spacy = load_spacy_model()
34
-
35
  # --- Initialize Session State Variables ---
36
  if "chat_history" not in st.session_state:
37
  st.session_state.chat_history = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
@@ -40,38 +30,6 @@ if "response_ready" not in st.session_state:
40
  if "follow_up" not in st.session_state:
41
  st.session_state.follow_up = ""
42
 
43
- # --- Appearance CSS ---
44
- st.markdown("""
45
- <style>
46
- .user-msg {
47
- background-color: #696969;
48
- color: white;
49
- padding: 10px;
50
- border-radius: 10px;
51
- margin-bottom: 5px;
52
- width: fit-content;
53
- max-width: 80%;
54
- }
55
- .assistant-msg {
56
- background-color: #333333;
57
- color: white;
58
- padding: 10px;
59
- border-radius: 10px;
60
- margin-bottom: 5px;
61
- width: fit-content;
62
- max-width: 80%;
63
- }
64
- .container {
65
- display: flex;
66
- flex-direction: column;
67
- align-items: flex-start;
68
- }
69
- @media (max-width: 600px) {
70
- .user-msg, .assistant-msg { font-size: 16px; max-width: 100%; }
71
- }
72
- </style>
73
- """, unsafe_allow_html=True)
74
-
75
  # --- Set Up Model & API Functions ---
76
  model_id = "mistralai/Mistral-7B-Instruct-v0.3"
77
  sentiment_analyzer = pipeline(
@@ -80,6 +38,16 @@ sentiment_analyzer = pipeline(
80
  revision="714eb0f"
81
  )
82
 
 
 
 
 
 
 
 
 
 
 
83
  def get_llm_hf_inference(model_id=model_id, max_new_tokens=128, temperature=0.7):
84
  return HuggingFaceEndpoint(
85
  repo_id=model_id,
@@ -220,6 +188,38 @@ if st.sidebar.button("Reset Chat"):
220
  st.session_state.follow_up = ""
221
  st.experimental_rerun()
222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  st.markdown("<div class='container'>", unsafe_allow_html=True)
224
  for message in st.session_state.chat_history:
225
  if message["role"] == "user":
 
22
  # Must be the first Streamlit command!
23
  st.set_page_config(page_title="HAL - NASA ChatBot", page_icon="🚀")
24
 
 
 
 
 
 
 
 
 
 
 
25
  # --- Initialize Session State Variables ---
26
  if "chat_history" not in st.session_state:
27
  st.session_state.chat_history = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
 
30
  if "follow_up" not in st.session_state:
31
  st.session_state.follow_up = ""
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # --- Set Up Model & API Functions ---
34
  model_id = "mistralai/Mistral-7B-Instruct-v0.3"
35
  sentiment_analyzer = pipeline(
 
38
  revision="714eb0f"
39
  )
40
 
41
+ # --- Helper to load spaCy model with fallback ---
42
+ def load_spacy_model():
43
+ try:
44
+ return spacy.load("en_core_web_sm")
45
+ except OSError:
46
+ subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"], check=True)
47
+ return spacy.load("en_core_web_sm")
48
+
49
+ nlp_spacy = load_spacy_model()
50
+
51
  def get_llm_hf_inference(model_id=model_id, max_new_tokens=128, temperature=0.7):
52
  return HuggingFaceEndpoint(
53
  repo_id=model_id,
 
188
  st.session_state.follow_up = ""
189
  st.experimental_rerun()
190
 
191
+ # --- Appearance CSS ---
192
+ st.markdown("""
193
+ <style>
194
+ .user-msg {
195
+ background-color: #696969;
196
+ color: white;
197
+ padding: 10px;
198
+ border-radius: 10px;
199
+ margin-bottom: 5px;
200
+ width: fit-content;
201
+ max-width: 80%;
202
+ }
203
+ .assistant-msg {
204
+ background-color: #333333;
205
+ color: white;
206
+ padding: 10px;
207
+ border-radius: 10px;
208
+ margin-bottom: 5px;
209
+ width: fit-content;
210
+ max-width: 80%;
211
+ }
212
+ .container {
213
+ display: flex;
214
+ flex-direction: column;
215
+ align-items: flex-start;
216
+ }
217
+ @media (max-width: 600px) {
218
+ .user-msg, .assistant-msg { font-size: 16px; max-width: 100%; }
219
+ }
220
+ </style>
221
+ """, unsafe_allow_html=True)
222
+
223
  st.markdown("<div class='container'>", unsafe_allow_html=True)
224
  for message in st.session_state.chat_history:
225
  if message["role"] == "user":