Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2", device="cpu")
|
6 |
|
7 |
def chat_function(message, history):
|
8 |
-
# Inizializza history come lista vuota se non esiste
|
9 |
-
if history is None:
|
10 |
-
history = []
|
11 |
-
# Genera la risposta
|
12 |
response = generator(message, max_length=50, num_return_sequences=1)[0]["generated_text"]
|
13 |
-
|
14 |
-
history.append({"role": "user", "content": message})
|
15 |
-
history.append({"role": "assistant", "content": response})
|
16 |
-
return history
|
17 |
|
18 |
interface = gr.ChatInterface(
|
19 |
fn=chat_function,
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Modello più piccolo e CPU esplicita
|
5 |
generator = pipeline("text-generation", model="sshleifer/tiny-gpt2", device="cpu")
|
6 |
|
7 |
def chat_function(message, history):
|
|
|
|
|
|
|
|
|
8 |
response = generator(message, max_length=50, num_return_sequences=1)[0]["generated_text"]
|
9 |
+
return history + [{"role": "user", "content": message}, {"role": "assistant", "content": response}]
|
|
|
|
|
|
|
10 |
|
11 |
interface = gr.ChatInterface(
|
12 |
fn=chat_function,
|