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)