Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Chargement robuste
|
| 6 |
+
model_name = "AllanF-SSU/Qwen2.5-G3V-Sovereign"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
| 9 |
+
|
| 10 |
+
def chat_res(message, history):
|
| 11 |
+
# On prépare l'entrée
|
| 12 |
+
inputs = tokenizer(message, return_tensors="pt").to(model.device)
|
| 13 |
+
|
| 14 |
+
# On génère avec des réglages "Souverains" (anti-répétition et température)
|
| 15 |
+
outputs = model.generate(
|
| 16 |
+
**inputs,
|
| 17 |
+
max_new_tokens=512, # Plus de place pour répondre
|
| 18 |
+
do_sample=True, # Active la créativité
|
| 19 |
+
temperature=0.8, # Équilibre entre logique et intuition
|
| 20 |
+
repetition_penalty=1.2, # CASSE les boucles de bégaiement
|
| 21 |
+
pad_token_id=tokenizer.eos_token_id
|
| 22 |
)
|
| 23 |
+
|
| 24 |
+
# ON COUPE LA QUESTION : on ne décode que ce qui vient APRÈS l'entrée
|
| 25 |
+
input_length = inputs.input_ids.shape[1]
|
| 26 |
+
response_tokens = outputs[0][input_length:]
|
| 27 |
+
|
| 28 |
+
return tokenizer.decode(response_tokens, skip_special_tokens=True)
|
| 29 |
+
|
| 30 |
+
# L'interface avec un titre digne du G3V
|
| 31 |
+
gr.ChatInterface(chat_res, title="Qwen2.5-G3V-Sovereign").launch()
|