Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
def clean_arabic_text(text):
|
| 5 |
+
if not text:
|
| 6 |
+
return ""
|
| 7 |
+
# إزالة التشكيل
|
| 8 |
+
tashkeel_pattern = re.compile(r'[\u0617-\u061A\u064B-\u0652]')
|
| 9 |
+
text = re.sub(tashkeel_pattern, '', text)
|
| 10 |
+
# توحيد الهمزات
|
| 11 |
+
text = re.sub(r'[أإآ]', 'ا', text)
|
| 12 |
+
# تحويل التاء المربوطة إلى هاء
|
| 13 |
+
text = re.sub(r'ة\b', 'ه', text)
|
| 14 |
+
# تحويل الألف المقصورة إلى ياء
|
| 15 |
+
text = re.sub(r'ى\b', 'ي', text)
|
| 16 |
+
# إزالة الرموز الخاصة
|
| 17 |
+
text = re.sub(r'[^\w\s]', '', text)
|
| 18 |
+
# إزالة المسافات الزائدة
|
| 19 |
+
text = " ".join(text.split())
|
| 20 |
+
return text
|
| 21 |
+
|
| 22 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 23 |
+
gr.Markdown("# Post Process")
|
| 24 |
+
gr.Markdown("قم بلصق النص العربي هنا ليتم تنظيفه.")
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
input_text = gr.Textbox(label="النص الأصلي", lines=10, placeholder="أدخل النص هنا...")
|
| 28 |
+
output_text = gr.Textbox(label="النص بعد التنظيف", lines=10)
|
| 29 |
+
|
| 30 |
+
btn = gr.Button("تنظيف النص")
|
| 31 |
+
btn.click(fn=clean_arabic_text, inputs=input_text, outputs=output_text)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|