Naif901 commited on
Commit
708f0ce
·
1 Parent(s): 9bb2d27

Add Gradio app for Arabic text correction

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/13MWFiF9_PiWlJkoiSMYYd-MFmF5QL2Fv
8
+ """
9
+
10
+ import gradio as gr
11
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
12
+
13
+ # Load the model and tokenizer from Hugging Face
14
+ model_name = "Slenko/Arabic-Text-Correction"
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
17
+
18
+ # Define the function to correct Arabic text
19
+ def correct_arabic_text(text):
20
+ # Tokenize the input text
21
+ inputs = tokenizer(text, return_tensors="pt", truncation=True)
22
+ # Generate corrected output
23
+ outputs = model.generate(**inputs)
24
+ # Decode the output text
25
+ corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
26
+ return corrected_text
27
+
28
+ # Create the Gradio interface
29
+ interface = gr.Interface(
30
+ fn=correct_arabic_text, # Function to process the input
31
+ inputs=gr.Textbox(lines=5, label="النص"), # Arabic text input field
32
+ outputs=gr.Textbox(lines=5, label="التصحيح"), # Arabic text output field
33
+ title="Arabic Text Correction",
34
+ description="Enter Arabic text to correct grammar, spelling, and punctuation errors.",
35
+ )
36
+
37
+ # Launch the Gradio app
38
+ if __name__ == "__main__":
39
+ interface.launch()
40
+