arielleharris's picture
Update app.py
39f243d verified
raw
history blame
2.07 kB
from transformers import pipeline
import gradio as gr # Import Gradio for the interface
# Load a text-generation model
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
# Customize the bot's knowledge base with predefined responses
faq_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.",
"resources for studying": "You can find free study resources on websites like Khan Academy, Coursera, and edX. For research papers, check Google Scholar.",
"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.",
"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.",
"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."
}
# Define the chatbot's response function
def faq_chatbot(user_input):
# 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
# If no FAQ match, use the AI model to generate a response
conversation = chatbot(user_input, max_length=50, num_return_sequences=1)
return conversation[0]['generated_text']
# Create the Gradio interface
interface = gr.Interface(
fn=faq_chatbot, # The function to handle user input
inputs=gr.Textbox(lines=2, placeholder="Ask me about studying tips or resources..."), # Input text box
outputs="text", # Output as text
title="Student FAQ Chatbot",
description="Ask me for study tips, time management advice, or about resources to help with your studies!"
)
# Launch the chatbot and make it public
interface.launch(share=True)