Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
MODEL_NAME = "Mattimax/DACMini-IT"
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(device)
|
| 10 |
+
|
| 11 |
+
def chat_fn(message, history):
|
| 12 |
+
inputs = tokenizer(message, return_tensors="pt").to(device)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model.generate(
|
| 15 |
+
**inputs,
|
| 16 |
+
max_new_tokens=150,
|
| 17 |
+
do_sample=True,
|
| 18 |
+
top_p=0.9,
|
| 19 |
+
temperature=0.7
|
| 20 |
+
)
|
| 21 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
demo = gr.ChatInterface(
|
| 25 |
+
fn=chat_fn,
|
| 26 |
+
title="💬 Demo DACMini-IT",
|
| 27 |
+
description="Una semplice demo del modello italiano DACMini-IT. Scrivi un messaggio e il modello risponde.",
|
| 28 |
+
theme="soft",
|
| 29 |
+
examples=[
|
| 30 |
+
"Ciao, come stai?",
|
| 31 |
+
"Raccontami una curiosità sulla lingua italiana.",
|
| 32 |
+
"Scrivi una breve poesia."
|
| 33 |
+
],
|
| 34 |
+
retry_btn="🔄 Riprova",
|
| 35 |
+
undo_btn="↩️ Annulla",
|
| 36 |
+
clear_btn="🗑️ Pulisci chat"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
demo.launch()
|