Spaces:
Sleeping
Sleeping
File size: 802 Bytes
853095d f027d6d 853095d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
MODEL_NAME = "Ronaldodev/llama"
# Charger modèle et tokenizer UNE SEULE FOIS
print("Chargement du modèle...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
def chat(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.7
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
iface = gr.Interface(
fn=chat,
inputs=gr.Textbox(lines=5, placeholder="Écris ton message ici..."),
outputs=gr.Textbox(),
title="Assistant IA (Llama 3.2 1B CPU)",
)
if __name__ == "__main__":
iface.launch()
|