Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| """app.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/13MWFiF9_PiWlJkoiSMYYd-MFmF5QL2Fv | |
| """ | |
| import gradio as gr | |
| from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
| # Load the model and tokenizer from Hugging Face | |
| model_name = "Slenko/Arabic-Text-Correction" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
| # Define the function to correct Arabic text | |
| def correct_arabic_text(text): | |
| # Tokenize the input text | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True) | |
| # Generate corrected output | |
| outputs = model.generate(**inputs) | |
| # Decode the output text | |
| corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return corrected_text | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=correct_arabic_text, # Function to process the input | |
| inputs=gr.Textbox(lines=5, label="النص"), # Arabic text input field | |
| outputs=gr.Textbox(lines=5, label="التصحيح"), # Arabic text output field | |
| title="Arabic Text Correction", | |
| description="Enter Arabic text to correct grammar, spelling, and punctuation errors.", | |
| ) | |
| # Launch the Gradio app | |
| if __name__ == "__main__": | |
| interface.launch() | |