Ajout de l'interface Gradio pour le modèle de génération de texte
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "CHARKA/Llama-2-7b-chat-h-maroc_edu"
|
| 5 |
+
|
| 6 |
+
# Charger le modèle et le tokenizer depuis le Hub
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Fonction de génération de texte
|
| 11 |
+
def generate_text(input_text):
|
| 12 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
| 13 |
+
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
| 14 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
|
| 16 |
+
# Créer l'interface Gradio
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=generate_text,
|
| 19 |
+
inputs=gr.Textbox(lines=2, placeholder="أدخل طلبك هنا"),
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="التفاعل مع النموذج",
|
| 22 |
+
description="اجهة تفاعل تستخدم نموذج توليد النصوص"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Lancer l'interface
|
| 26 |
+
interface.launch()
|
| 27 |
+
|
| 28 |
+
|