Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
model = T5ForConditionalGeneration.from_pretrained("Baldezo313/t5-finetuned-squad-mamadou")
|
6 |
+
tokenizer = T5Tokenizer.from_pretrained("Baldezo313/t5-finetuned-squad-mamadou")
|
7 |
+
|
8 |
+
def generate_answer(context, question):
|
9 |
+
inputs = tokenizer(context, question, return_tensors="pt", padding="max_length", truncation=True, max_length=512)
|
10 |
+
outputs = model.generate(**inputs, max_length=64, num_beams=4, early_stopping=True)
|
11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
demo = gr.Interface(
|
14 |
+
fn=generate_answer,
|
15 |
+
inputs=[
|
16 |
+
gr.Textbox(label="Contexte", lines=6, placeholder="Entrez ici le contexte..."),
|
17 |
+
gr.Textbox(label="Question", placeholder="Entrez votre question...")
|
18 |
+
],
|
19 |
+
outputs=gr.Textbox(label="Réponse générée"),
|
20 |
+
title="🧠 Générateur de Réponses T5",
|
21 |
+
description="Donnez un contexte et une question — le modèle T5 fine-tuné génère une réponse cohérente."
|
22 |
+
)
|
23 |
+
|
24 |
+
demo.launch()
|