Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,33 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, T5ForConditionalGeneration
|
3 |
+
import torch
|
4 |
|
5 |
+
# Modèle : à adapter avec le chemin ou le nom du modèle
|
6 |
+
model_name = "NomOuCheminDuModele"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
model.to(device)
|
11 |
+
|
12 |
+
def correction_grammaticale(texte):
|
13 |
+
# Préfixe à adapter selon l'entraînement de ton modèle
|
14 |
+
input_text = "corriger: " + texte
|
15 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
16 |
+
|
17 |
+
outputs = model.generate(
|
18 |
+
input_ids,
|
19 |
+
max_length=128,
|
20 |
+
num_beams=4,
|
21 |
+
early_stopping=True
|
22 |
+
)
|
23 |
+
correction = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
+
return correction
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=correction_grammaticale,
|
28 |
+
inputs=gr.Textbox(label="Texte à corriger"),
|
29 |
+
outputs=gr.Textbox(label="Texte corrigé"),
|
30 |
+
title="Correcteur de Texte Français"
|
31 |
+
)
|
32 |
|
|
|
33 |
demo.launch()
|