File size: 1,334 Bytes
708f0ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- 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()