Spaces:
Build error
Build error
Update app.py
#1
by andresicedo - opened
3 unmodified lines4567891011125 unmodified lines181920212223242526272829303132333435361920213738394041423 unmodified lines# Load a text-generation modelchatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
# Load the classification modelclassifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
# Customize the bot's knowledge base with predefined responsesfaq_responses = { "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.",5 unmodified lines
# Define the chatbot's response functiondef faq_chatbot(user_input): # Classify the user input by passing the FAQ keywords as labels classified_user_input = classifier(user_input, candidate_labels=list(faq_responses.keys()))
# Get the highest confidence score label, ie. the most likely of the FAQ predicted_label = classified_user_input["labels"][0] confidence_score = classified_user_input["scores"][0]
# Confidence threshold (adjust if needed) threshold = 0.5
# If the classification confidence is high, return the corresponding FAQ response if confidence_score > threshold: return faq_responses[predicted_label] # Check if the user's input matches any FAQ keywords for key, response in faq_responses.items(): if key in user_input.lower(): return response # for key, response in faq_responses.items(): # if key in user_input.lower(): # return response
# If no FAQ match, use the AI model to generate a response conversation = chatbot(user_input, max_length=50, num_return_sequences=1)app.py+21-3