CCockrum commited on
Commit
68577cc
·
verified ·
1 Parent(s): b9e2074

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -51,6 +51,20 @@ def predict_action(user_text):
51
  return "weather_info"
52
  return "general_query"
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def get_response(system_message, chat_history, user_text,
55
  eos_token_id=['User'], max_new_tokens=256, get_llm_hf_kws={}):
56
  sentiment = analyze_sentiment(user_text)
@@ -60,7 +74,10 @@ def get_response(system_message, chat_history, user_text,
60
  nasa_response = get_nasa_apod()
61
  chat_history.append({'role': 'user', 'content': user_text})
62
  chat_history.append({'role': 'assistant', 'content': nasa_response})
63
- return nasa_response, chat_history
 
 
 
64
 
65
  hf = get_llm_hf_inference(max_new_tokens=max_new_tokens, temperature=0.1)
66
 
@@ -81,9 +98,12 @@ def get_response(system_message, chat_history, user_text,
81
 
82
  # Modify response based on sentiment analysis (e.g., offer help for negative sentiments)
83
  if sentiment == "NEGATIVE":
84
- response = "I'm sorry to hear that. How can I assist you further?"
 
 
 
85
 
86
- return response, chat_history
87
 
88
  # Streamlit setup
89
  st.set_page_config(page_title="HuggingFace ChatBot", page_icon="🤗")
 
51
  return "weather_info"
52
  return "general_query"
53
 
54
+ def generate_follow_up(user_text):
55
+ """
56
+ Generates a relevant follow-up question based on the user's input.
57
+ """
58
+ prompt_text = (
59
+ f"Given the user's message: '{user_text}', suggest a natural follow-up question "
60
+ "that continues the conversation and encourages engagement."
61
+ )
62
+
63
+ hf = get_llm_hf_inference(max_new_tokens=64, temperature=0.7)
64
+ chat = hf.invoke(input=prompt_text)
65
+
66
+ return chat.strip()
67
+
68
  def get_response(system_message, chat_history, user_text,
69
  eos_token_id=['User'], max_new_tokens=256, get_llm_hf_kws={}):
70
  sentiment = analyze_sentiment(user_text)
 
74
  nasa_response = get_nasa_apod()
75
  chat_history.append({'role': 'user', 'content': user_text})
76
  chat_history.append({'role': 'assistant', 'content': nasa_response})
77
+
78
+ follow_up = generate_follow_up(user_text)
79
+ chat_history.append({'role': 'assistant', 'content': follow_up})
80
+ return f"{nasa_response}\n\n{follow_up}", chat_history
81
 
82
  hf = get_llm_hf_inference(max_new_tokens=max_new_tokens, temperature=0.1)
83
 
 
98
 
99
  # Modify response based on sentiment analysis (e.g., offer help for negative sentiments)
100
  if sentiment == "NEGATIVE":
101
+ response += "\nI'm sorry to hear that. How can I assist you further?"
102
+
103
+ follow_up = generate_follow_up(user_text)
104
+ chat_history.append({'role': 'assistant', 'content': follow_up})
105
 
106
+ return f"{response}\n\n{follow_up}", chat_history
107
 
108
  # Streamlit setup
109
  st.set_page_config(page_title="HuggingFace ChatBot", page_icon="🤗")