File size: 551 Bytes
0e5ebb3
633a29d
0e5ebb3
2c29db9
8e83f83
0e5ebb3
633a29d
 
2c29db9
0e5ebb3
633a29d
 
8e83f83
 
0e5ebb3
 
633a29d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gradio as gr
from transformers import pipeline

# Modello più piccolo e CPU esplicita
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2", device="cpu")

def chat_function(message, history):
    response = generator(message, max_length=50, num_return_sequences=1)[0]["generated_text"]
    return history + [{"role": "user", "content": message}, {"role": "assistant", "content": response}]

interface = gr.ChatInterface(
    fn=chat_function,
    chatbot=gr.Chatbot(type="messages"),
    title="Chatbot IA"
)

interface.launch()