File size: 1,024 Bytes
0efd337
2ad20f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0efd337
 
2ad20f5
 
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
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration

# Load the tokenizer and model for flan-t5
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-base")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-base")

# Define the chatbot function
def chat_with_flan(input_text):
    # Prepare the input for the model
    input_ids = tokenizer.encode(input_text, return_tensors="pt")
    
    # Generate the response from the model
    outputs = model.generate(input_ids, max_length=200, num_return_sequences=1)
    
    # Decode and return the response
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response

# Set up the Gradio interface
interface = gr.Interface(
    fn=chat_with_flan,
    inputs=gr.Textbox(label="Chat with FLAN-T5"),
    outputs=gr.Textbox(label="FLAN-T5's Response"),
    title="FLAN-T5 Chatbot",
    description="This is a simple chatbot powered by the FLAN-T5 model.",
)

# Launch the Gradio app
interface.launch()