arielleharris commited on
Commit
015b3a6
·
verified ·
1 Parent(s): f59f402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -7,17 +7,23 @@ chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
7
  # Load the classification model
8
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
9
 
 
10
  # Customize the bot's knowledge base with predefined responses
11
  faq_responses = {
12
- "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."
 
 
 
 
13
  }
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, i.e., the most likely FAQ
 
21
  predicted_label = classified_user_input["labels"][0]
22
  confidence_score = classified_user_input["scores"][0]
23
 
@@ -27,9 +33,12 @@ 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
- # If no FAQ match, use the AI model to generate a response
32
- conversation = chatbot(user_input, max_length=50, num_return_sequences=1)
33
- return conversation[0]["generated_text"]
34
-
35
-
 
 
 
 
7
  # Load the classification model
8
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
9
 
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
+ "resources for studying": "You can find free study resources on websites like Khan Academy, Coursera, and edX. For research papers, check Google Scholar.",
15
+ "how to focus": "To improve focus, try studying in a quiet place, remove distractions like your phone, and use apps like Forest or Focus@Will.",
16
+ "time management tips": "Start by creating a to-do list each morning. Prioritize tasks using methods like Eisenhower Matrix and allocate specific time blocks for each task.",
17
+ "how to avoid procrastination": "Break tasks into smaller steps, set deadlines, and reward yourself after completing milestones. Tools like Trello can help you stay organized."
18
  }
19
 
20
  # Define the chatbot's response function
21
  def faq_chatbot(user_input):
22
+ # Classify the user input by passing the FAQ keywords as labels
23
  classified_user_input = classifier(user_input, candidate_labels=list(faq_responses.keys()))
24
 
25
+
26
+ # Get the highest confidence score label, ie. the most likely of the FAQ
27
  predicted_label = classified_user_input["labels"][0]
28
  confidence_score = classified_user_input["scores"][0]
29
 
 
33
  # If the classification confidence is high, return the corresponding FAQ response
34
  if confidence_score > threshold:
35
  return faq_responses[predicted_label]
36
+
37
+
38
+ # Check if the user's input matches any FAQ keywords
39
+ # for key, response in faq_responses.items():
40
+ # if key in user_input.lower():
41
+ # return response
42
+
43
+ # If no FAQ match, use the AI model to generate a response
44
+ conversation = chatbot(user_input, max_length=50, num_return_sequences=1)