Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,61 +4,40 @@ from huggingface_hub import InferenceClient
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
)
|
61 |
|
|
|
|
|
|
|
62 |
|
63 |
-
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
+
# Load a pre-trained conversational AI model
|
8 |
+
# This model can generate responses based on user inputs
|
9 |
+
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
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 |
+
# Check if the user's input matches any FAQ keywords
|
23 |
+
for key, response in faq_responses.items():
|
24 |
+
if key in user_input.lower():
|
25 |
+
return response
|
26 |
+
|
27 |
+
# If no FAQ match, use the AI model to generate a response
|
28 |
+
conversation = chatbot(user_input)
|
29 |
+
return conversation[0]['generated_text']
|
30 |
+
|
31 |
+
# Create the Gradio interface
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=faq_chatbot, # The function to handle user input
|
34 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask me about studying tips or resources..."), # Input text box
|
35 |
+
outputs="text", # Output as text
|
36 |
+
title="Student FAQ Chatbot",
|
37 |
+
description="Ask me for study tips, time management advice, or about resources to help with your studies!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
)
|
39 |
|
40 |
+
# Launch the chatbot
|
41 |
+
interface.launch()
|
42 |
+
|
43 |
|
|
|
|