hamaadayubkhan commited on
Commit
8c988d8
1 Parent(s): ee151ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
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
- # Call Groq API to generate a response
27
- brief_response = client.predict(user_input)
28
  except Exception as e:
29
- return f"Error calling Groq API: {str(e)}"
30
-
31
- # Randomly select a response from the dataset
32
- idx = random.randint(0, len(context)-1)
33
- reply = response[idx]
34
- context_text = context[idx]
35
- knowledge_text = knowledge[idx]
36
-
37
- # Combine dataset info with the Groq response
38
- complete_response = (
39
- f"**Personalized Advice**\n{brief_response}\n\n"
40
- f"**Additional Insight**\n{reply}\n\n"
41
- f"**Contextual Information**\n{context_text}\n"
42
- f"**Knowledge Base**\n{knowledge_text}"
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