File size: 1,299 Bytes
a8e7c75
b26fbd2
 
 
 
 
 
 
 
 
a8e7c75
b26fbd2
2f27609
b26fbd2
 
b760005
b26fbd2
 
b760005
b26fbd2
b760005
b26fbd2
b760005
 
 
 
 
 
 
 
b26fbd2
b760005
 
 
a8e7c75
cbb60b6
a8e7c75
d20e712
4c522a2
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
import gradio as gr
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer

# Initialize pre-trained model and tokenizer
model_name = "gpt2"  # You can change this to another model if needed
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Create a pipeline for text generation
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)

# Chatbot response function
def chatbot_response(user_input):
    # Generate a response using the model
    response = generator(user_input, max_length=100, num_return_sequences=1, temperature=0.7, top_k=50)
    
    # Extract and return the generated text
    return response[0]['generated_text']

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Study Assistance Chatbot")
    gr.Markdown("Welcome! Ask me anything related to your academic studies.")
    
    with gr.Row():
        with gr.Column():
            user_input = gr.Textbox(label="Enter your question here:")
            submit_button = gr.Button("Submit")
        with gr.Column():
            chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)

    submit_button.click(chatbot_response, inputs=user_input, outputs=chatbot_output)

demo.launch()