File size: 735 Bytes
d9fd894
9695424
6c9badc
baceb4e
 
9a71b5a
baceb4e
fb0e8e6
baceb4e
fb0e8e6
baceb4e
 
 
 
 
fb0e8e6
baceb4e
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import gradio as gr

# Load ultralight model
model_id = "sshleifer/tiny-t5"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)

# Simple chat function
def chat(message, history):
    prompt = "Answer this: " + message
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=50)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response.strip()

# Gradio chat interface
gr.ChatInterface(
    fn=chat,
    title="TinyT5 Chat",
    description="Ask basic questions. Powered by the super lightweight sshleifer/tiny-t5 model.",
).launch()