Spaces:
Running
Running
hamaadayubkhan
commited on
Commit
•
8c988d8
1
Parent(s):
ee151ec
Update app.py
Browse files
app.py
CHANGED
@@ -23,24 +23,27 @@ def chatbot(user_input):
|
|
23 |
return "Please enter a question or concern to receive guidance."
|
24 |
|
25 |
try:
|
26 |
-
#
|
27 |
-
brief_response = client.predict(user_input)
|
28 |
except Exception as e:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
|
45 |
return complete_response
|
46 |
|
|
|
23 |
return "Please enter a question or concern to receive guidance."
|
24 |
|
25 |
try:
|
26 |
+
# Try to call Groq API to generate a response
|
27 |
+
brief_response = client.predict(user_input) # Ensure that 'predict' or correct method is available
|
28 |
except Exception as e:
|
29 |
+
brief_response = None # If Groq API fails, set brief_response to None
|
30 |
+
|
31 |
+
if not brief_response:
|
32 |
+
# If Groq API does not return a response, fall back to dataset
|
33 |
+
idx = random.randint(0, len(context)-1)
|
34 |
+
reply = response[idx]
|
35 |
+
context_text = context[idx]
|
36 |
+
knowledge_text = knowledge[idx]
|
37 |
+
|
38 |
+
# Combine dataset info with fallback response
|
39 |
+
complete_response = (
|
40 |
+
f"**Contextual Information**\n{context_text}\n\n"
|
41 |
+
f"**Knowledge Base**\n{knowledge_text}\n\n"
|
42 |
+
f"**Fallback Response**\n{reply}"
|
43 |
+
)
|
44 |
+
else:
|
45 |
+
# If Groq API returns a response, use that as the final output
|
46 |
+
complete_response = f"**Personalized Response**\n{brief_response}"
|
47 |
|
48 |
return complete_response
|
49 |
|