arielleharris commited on
Commit
9e91338
·
verified ·
1 Parent(s): 82849e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,6 +1,4 @@
1
  from transformers import pipeline
2
- import gradio as gr # Import Gradio for the interface
3
-
4
 
5
  # Load a text-generation model
6
  chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
@@ -10,14 +8,15 @@ classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnl
10
 
11
  # Customize the bot's knowledge base with predefined responses
12
  faq_responses = {
13
- "study tips": "Here are some study tips: 1) Break your study sessions into 25-minute chunks (Pomodoro Technique). 2) Test yourself frequently. 3) Stay organized using planners or apps like Notion or Todoist.",
 
14
 
15
  # Define the chatbot's response function
16
  def faq_chatbot(user_input):
17
  # Classify the user input by passing the FAQ keywords as labels
18
  classified_user_input = classifier(user_input, candidate_labels=list(faq_responses.keys()))
19
 
20
- # Get the highest confidence score label, ie. the most likely of the FAQ
21
  predicted_label = classified_user_input["labels"][0]
22
  confidence_score = classified_user_input["scores"][0]
23
 
@@ -27,12 +26,9 @@ def faq_chatbot(user_input):
27
  # If the classification confidence is high, return the corresponding FAQ response
28
  if confidence_score > threshold:
29
  return faq_responses[predicted_label]
30
-
31
-
32
- # Check if the user's input matches any FAQ keywords
33
- # for key, response in faq_responses.items():
34
- # if key in user_input.lower():
35
- # return response
36
-
37
- # If no FAQ match, use the AI model to generate a response
38
  conversation = chatbot(user_input, max_length=50, num_return_sequences=1)
 
 
 
 
1
  from transformers import pipeline
 
 
2
 
3
  # Load a text-generation model
4
  chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
 
8
 
9
  # Customize the bot's knowledge base with predefined responses
10
  faq_responses = {
11
+ "study tips": "Here are some study tips: 1) Break your study sessions into 25-minute chunks (Pomodoro Technique). 2) Test yourself frequently. 3) Stay organized using planners or apps like Notion or Todoist."
12
+ }
13
 
14
  # Define the chatbot's response function
15
  def faq_chatbot(user_input):
16
  # Classify the user input by passing the FAQ keywords as labels
17
  classified_user_input = classifier(user_input, candidate_labels=list(faq_responses.keys()))
18
 
19
+ # Get the highest confidence score label, i.e., the most likely FAQ
20
  predicted_label = classified_user_input["labels"][0]
21
  confidence_score = classified_user_input["scores"][0]
22
 
 
26
  # If the classification confidence is high, return the corresponding FAQ response
27
  if confidence_score > threshold:
28
  return faq_responses[predicted_label]
29
+
30
+ # If no FAQ match, use the AI model to generate a response
 
 
 
 
 
 
31
  conversation = chatbot(user_input, max_length=50, num_return_sequences=1)
32
+ return conversation[0]["generated_text"]
33
+
34
+