File size: 1,742 Bytes
a96fdb7
 
 
 
c2f65e1
 
a96fdb7
c2f65e1
 
 
a96fdb7
 
 
 
 
c2f65e1
 
 
a96fdb7
c2f65e1
 
 
 
 
a96fdb7
c2f65e1
a96fdb7
 
 
c2f65e1
 
 
 
a96fdb7
c2f65e1
 
 
 
a96fdb7
 
 
1
2
3
4
5
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
40
41
42
import gradio as gr  # For building the chatbot UI
import random  # For generating random responses

# Chatbot response function
def chatbot_response(user_input, chat_history):
    response = ""

    if "time management" in user_input.lower():
        response = "Time management is key! Try creating a prioritized to-do list and setting specific study blocks."
    elif "study tips" in user_input.lower():
        tips = [
            "Take regular breaks while studying to stay focused.",
            "Use active recall and spaced repetition for better retention.",
            "Set a specific goal for each study session."
        ]
        response = random.choice(tips)
    elif "hello" in user_input.lower() or "hi" in user_input.lower():
        response = "Hello! How can I help you with your studies today?"
    else:
        response = "I'm here to assist with general academic questions. Feel free to ask about study tips, time management, or anything else!"
    
    chat_history.append(("You", user_input))
    chat_history.append(("Chatbot", response))
    return "", chat_history

# Gradio interface with chat history
with gr.Blocks() as demo:
    gr.Markdown("# Study Assistance Chatbot")
    gr.Markdown("Welcome! Ask me anything related to your academic studies.")

    chatbot = gr.Chatbot(label="Chatbot")
    user_input = gr.Textbox(label="Enter your question here:", placeholder="Type your question...")
    submit_button = gr.Button("Submit")
    
    # Set an initial welcome message
    chat_history = [("Chatbot", "Welcome! How can I assist you with your studies today?")]

    submit_button.click(chatbot_response, inputs=[user_input, chatbot], outputs=[user_input, chatbot])

# Launch the Gradio app
demo.launch()