Spaces:
Sleeping
Sleeping
KrSharangrav
commited on
Commit
·
b9a2016
1
Parent(s):
84326e0
changed in UI
Browse files- chatbot.py +5 -7
chatbot.py
CHANGED
@@ -72,7 +72,6 @@ def is_entry_query(prompt):
|
|
72 |
return False, None
|
73 |
|
74 |
# Helper: Detect if the query is a basic dataset question.
|
75 |
-
# Examples: "What is the dataset summary?", "Show me the sentiment distribution", etc.
|
76 |
def is_basic_dataset_question(prompt):
|
77 |
lower = prompt.lower()
|
78 |
keywords = ["dataset summary", "total tweets", "sentiment distribution", "overall dataset", "data overview", "data summary"]
|
@@ -87,7 +86,6 @@ def chatbot_response(user_prompt):
|
|
87 |
if is_basic_dataset_question(user_prompt):
|
88 |
summary = get_dataset_summary()
|
89 |
ai_response = "Dataset Summary:\n" + summary
|
90 |
-
# Run analysis on the summary text
|
91 |
sentiment_label, sentiment_confidence = analyze_sentiment(summary)
|
92 |
topic_label, topic_confidence = extract_topic(summary)
|
93 |
return ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence
|
@@ -102,18 +100,18 @@ def chatbot_response(user_prompt):
|
|
102 |
entry_text = entry.get("text", "No text available.")
|
103 |
entry_user = entry.get("user", "Unknown")
|
104 |
entry_date = entry.get("date", "Unknown")
|
105 |
-
# Build a static response message with
|
106 |
ai_response = (
|
107 |
"Let's break down this tweet-like MongoDB entry:\n\n"
|
108 |
-
f"Tweet
|
109 |
-
f"User
|
110 |
-
f"Date
|
111 |
)
|
112 |
sentiment_label, sentiment_confidence = analyze_sentiment(entry_text)
|
113 |
topic_label, topic_confidence = extract_topic(entry_text)
|
114 |
return ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence
|
115 |
|
116 |
-
# For other queries, use the generative model
|
117 |
model_gen = genai.GenerativeModel("gemini-1.5-pro")
|
118 |
ai_response_obj = model_gen.generate_content(user_prompt)
|
119 |
ai_response = ai_response_obj.text
|
|
|
72 |
return False, None
|
73 |
|
74 |
# Helper: Detect if the query is a basic dataset question.
|
|
|
75 |
def is_basic_dataset_question(prompt):
|
76 |
lower = prompt.lower()
|
77 |
keywords = ["dataset summary", "total tweets", "sentiment distribution", "overall dataset", "data overview", "data summary"]
|
|
|
86 |
if is_basic_dataset_question(user_prompt):
|
87 |
summary = get_dataset_summary()
|
88 |
ai_response = "Dataset Summary:\n" + summary
|
|
|
89 |
sentiment_label, sentiment_confidence = analyze_sentiment(summary)
|
90 |
topic_label, topic_confidence = extract_topic(summary)
|
91 |
return ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence
|
|
|
100 |
entry_text = entry.get("text", "No text available.")
|
101 |
entry_user = entry.get("user", "Unknown")
|
102 |
entry_date = entry.get("date", "Unknown")
|
103 |
+
# Build a static response message with new lines for each field.
|
104 |
ai_response = (
|
105 |
"Let's break down this tweet-like MongoDB entry:\n\n"
|
106 |
+
f"**Tweet:** {entry_text}\n\n"
|
107 |
+
f"**User:** {entry_user}\n\n"
|
108 |
+
f"**Date:** {entry_date}"
|
109 |
)
|
110 |
sentiment_label, sentiment_confidence = analyze_sentiment(entry_text)
|
111 |
topic_label, topic_confidence = extract_topic(entry_text)
|
112 |
return ai_response, sentiment_label, sentiment_confidence, topic_label, topic_confidence
|
113 |
|
114 |
+
# For other queries, use the generative model.
|
115 |
model_gen = genai.GenerativeModel("gemini-1.5-pro")
|
116 |
ai_response_obj = model_gen.generate_content(user_prompt)
|
117 |
ai_response = ai_response_obj.text
|