Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch | |
| MODEL_NAME = "Mattimax/DACMini-IT" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) | |
| model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(device) | |
| def chat_fn(message, history): | |
| inputs = tokenizer(message, return_tensors="pt").to(device) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=150, | |
| do_sample=True, | |
| top_p=0.9, | |
| temperature=0.7 | |
| ) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return response | |
| demo = gr.ChatInterface( | |
| fn=chat_fn, | |
| title="๐ฌ Demo DACMini-IT", | |
| description="Una semplice demo del modello italiano DACMini-IT. Scrivi un messaggio e il modello risponde.", | |
| theme="soft", | |
| examples=[ | |
| "Ciao, come stai?", | |
| "Raccontami una curiositร sulla lingua italiana.", | |
| "Scrivi una breve poesia." | |
| ], | |
| retry_btn="๐ Riprova", | |
| undo_btn="โฉ๏ธ Annulla", | |
| clear_btn="๐๏ธ Pulisci chat" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |