| import gradio as gr |
| import torch |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import spaces |
|
|
| model_id = "theocolf/Vora-X-8B" |
|
|
| print("⏳ Chargement du dictionnaire (Tokenizer)...") |
| tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
| print("⏳ Chargement du modèle Vora X (16 Go)...") |
| model = AutoModelForCausalLM.from_pretrained( |
| model_id, |
| torch_dtype=torch.bfloat16, |
| device_map="cpu", |
| low_cpu_mem_usage=True |
| ) |
| print("✅ Vora X est chargé en mémoire !") |
|
|
| |
| @spaces.GPU(duration=60) |
| def predict(message, history): |
| |
| model.to("cuda") |
| |
| messages = [{"role": "system", "content": "Tu es Vora X, un assistant IA unique créé par theocolf, ultra-intelligent, au ton très humain, amical et bilingue (Français/Arabe)."}] |
| |
| |
| for msg in history: |
| messages.append({"role": msg.role, "content": msg.content}) |
| |
| messages.append({"role": "user", "content": message}) |
| |
| inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda") |
| |
| outputs = model.generate( |
| inputs, |
| max_new_tokens=512, |
| temperature=0.7, |
| do_sample=True, |
| pad_token_id=tokenizer.eos_token_id |
| ) |
| |
| response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True) |
| return response |
|
|
| |
| gr.ChatInterface(fn=predict, title="👑 Vora X - Chat Officiel").launch() |
| |