TheOnlyHatem's picture
Update app.py
006544e verified
raw
history blame
1.03 kB
import gradio as gr
from transformers import AutoTokenizer, T5ForConditionalGeneration
import torch
model_name = "DenoKuso/t5-small-gec-fr"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
def correction_grammaticale(texte):
# Ce modèle utilise (a priori) le préfixe "gec: " pour la correction.
input_text = "gec: " + texte
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
outputs = model.generate(
input_ids,
max_length=128,
num_beams=4,
early_stopping=True
)
correction = tokenizer.decode(outputs[0], skip_special_tokens=True)
return correction
demo = gr.Interface(
fn=correction_grammaticale,
inputs=gr.Textbox(label="Texte à corriger"),
outputs=gr.Textbox(label="Texte corrigé"),
title="Correcteur de Texte Français"
)
if __name__ == "__main__":
demo.launch()