File size: 1,436 Bytes
39d8d0b
70b070a
87ccf2e
70b070a
 
 
 
 
 
87ccf2e
70b070a
87ccf2e
 
 
70b070a
 
87ccf2e
 
70b070a
87ccf2e
70b070a
 
 
7e0a33c
70b070a
87ccf2e
70b070a
39d8d0b
70b070a
 
 
87ccf2e
 
70b070a
 
 
 
 
87ccf2e
 
 
70b070a
87ccf2e
 
288e570
39d8d0b
87ccf2e
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
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from transformers import pipeline

# Chargement d'un modèle plus rapide mais performant pour la correction
corrector = pipeline(
    "text2text-generation",
    model="grammarly/coedit-large",
    device="cpu"  # Changez à "cuda" si vous avez un GPU
)

def correct_text(text: str, language: str = "fr") -> str:
    if not text.strip():
        return "⚠️ Veuillez entrer un texte à corriger"
    
    # Prompt optimisé pour la correction
    prompt = f"Corrige ce texte en {language}: {text[:1000]}\nCorrection:"
    
    try:
        result = corrector(
            prompt,
            max_length=512,
            num_beams=3,
            early_stopping=True
        )
        return result[0]['generated_text'].split("Correction:")[-1].strip()
    except Exception as e:
        return f"❌ Erreur: {str(e)}"

# Interface simplifiée mais fonctionnelle
with gr.Blocks() as app:
    gr.Markdown("## ✍️ Correcteur de Textes Intelligent")
    
    with gr.Row():
        text_input = gr.Textbox(label="Votre texte", lines=5)
        output = gr.Textbox(label="Correction", lines=5)
    
    lang_select = gr.Dropdown(["fr", "en"], label="Langue", value="fr")
    submit_btn = gr.Button("Corriger")
    
    submit_btn.click(
        fn=correct_text,
        inputs=[text_input, lang_select],
        outputs=output
    )

if __name__ == "__main__":
    app.launch(server_name="0.0.0.0", server_port=7860)