File size: 1,030 Bytes
bd0aafe
41b46aa
 
a574616
006544e
bd0aafe
41b46aa
 
a574616
41b46aa
 
 
 
006544e
df0a6e2
41b46aa
 
 
a574616
 
 
41b46aa
 
a574616
41b46aa
 
 
 
 
 
 
 
 
bd0aafe
a574616
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()