Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,33 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Prompt maître
|
| 8 |
-
system_message = "
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
token = chunk.choices[0].delta.content
|
| 32 |
-
response += token
|
| 33 |
-
yield response
|
| 34 |
-
|
| 35 |
-
# Interface Gradio
|
| 36 |
-
demo = gr.ChatInterface(respond)
|
| 37 |
-
|
| 38 |
-
if __name__ == "__main__":
|
| 39 |
-
demo.launch(share=True)
|
| 40 |
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import torch
|
| 3 |
|
| 4 |
+
# Charger le modèle
|
| 5 |
+
model_name = "Qwen/Qwen3-4B-Thinking-2507"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
|
| 8 |
|
| 9 |
# Prompt maître
|
| 10 |
+
system_message = "Tu es un formateur de formateurs spécialisé en analyse réflexive des pratiques enseignantes."
|
| 11 |
+
|
| 12 |
+
# Exemple de conversation
|
| 13 |
+
messages = [
|
| 14 |
+
{"role": "system", "content": system_message},
|
| 15 |
+
{"role": "user", "content": "Salut, peux-tu analyser cette situation ?"}
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
# Préparer l'entrée pour le modèle
|
| 19 |
+
inputs = tokenizer.apply_chat_template(
|
| 20 |
+
messages,
|
| 21 |
+
add_generation_prompt=True,
|
| 22 |
+
tokenize=True,
|
| 23 |
+
return_dict=True,
|
| 24 |
+
return_tensors="pt"
|
| 25 |
+
).to(model.device)
|
| 26 |
+
|
| 27 |
+
# Génération de réponse
|
| 28 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 29 |
+
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
|
| 30 |
+
|
| 31 |
+
print("Réponse de l'IA :", response)
|
| 32 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|