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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -26
app.py CHANGED
@@ -4,10 +4,6 @@ import gradio as gr # Import Gradio for the interface
4
  # Load a text-generation model
5
  chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
6
 
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.",
@@ -19,26 +15,23 @@ faq_responses = {
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
-
30
- # Confidence threshold (adjust if needed)
31
- threshold = 0.5
32
-
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Load a text-generation model
5
  chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
6
 
 
 
 
 
7
  # Customize the bot's knowledge base with predefined responses
8
  faq_responses = {
9
  "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.",
 
15
 
16
  # Define the chatbot's response function
17
  def faq_chatbot(user_input):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  # Check if the user's input matches any FAQ keywords
19
+ for key, response in faq_responses.items():
20
+ if key in user_input.lower():
21
+ return response
22
+
23
+ # If no FAQ match, use the AI model to generate a response
24
+ conversation = chatbot(user_input, max_length=50, num_return_sequences=1)
25
+ return conversation[0]['generated_text']
26
+
27
+ # Create the Gradio interface
28
+ interface = gr.Interface(
29
+ fn=faq_chatbot, # The function to handle user input
30
+ inputs=gr.Textbox(lines=2, placeholder="Ask me about studying tips or resources..."), # Input text box
31
+ outputs="text", # Output as text
32
+ title="Student FAQ Chatbot",
33
+ description="Ask me for study tips, time management advice, or about resources to help with your studies!"
34
+ )
35
+
36
+ # Launch the chatbot and make it public
37
+ interface.launch(share=True)