Spaces:
Configuration error
Configuration error
Upload 3 files
Browse files- README.md +23 -12
- msa_translator_app.py +32 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,13 +1,24 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: MSA
|
| 3 |
-
emoji: 🏃
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: blue
|
| 6 |
-
sdk: streamlit
|
| 7 |
-
sdk_version: 1.44.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
short_description: Translator
|
| 11 |
-
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
# MSA Translator
|
| 3 |
+
|
| 4 |
+
**MSA Translator** is a Streamlit web application that translates Egyptian Arabic dialect into Modern Standard Arabic (MSA) using a fine-tuned transformer model.
|
| 5 |
+
|
| 6 |
+
## ✨ Features
|
| 7 |
+
|
| 8 |
+
- Real-time translation of dialectal Arabic to MSA.
|
| 9 |
+
- Powered by the `PRAli22/arat5-arabic-dialects-translation` model.
|
| 10 |
+
- Simple and user-friendly web interface.
|
| 11 |
+
- Built with Streamlit and Hugging Face Transformers.
|
| 12 |
+
|
| 13 |
+
## 🚀 How to Run
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
pip install -r requirements.txt
|
| 17 |
+
streamlit run msa_translator_app.py
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
## 🌐 Demo
|
| 21 |
+
|
| 22 |
+
You can deploy this app easily on [Hugging Face Spaces](https://huggingface.co/spaces) with Streamlit UI.
|
| 23 |
+
|
| 24 |
+
---
|
msa_translator_app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# تحميل النموذج والـ tokenizer
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
model_name = "PRAli22/arat5-arabic-dialects-translation"
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 12 |
+
return tokenizer, model
|
| 13 |
+
|
| 14 |
+
tokenizer, model = load_model()
|
| 15 |
+
|
| 16 |
+
# تصميم الواجهة
|
| 17 |
+
st.set_page_config(page_title="MSA Translator", layout="centered")
|
| 18 |
+
st.title("🔁 MSA Translator")
|
| 19 |
+
st.markdown("ترجم من اللهجة المصرية إلى العربية الفصحى باستخدام الذكاء الاصطناعي.")
|
| 20 |
+
|
| 21 |
+
user_input = st.text_area("🗣️ اكتب جملة باللهجة المصرية", height=100)
|
| 22 |
+
|
| 23 |
+
if st.button("ترجم"):
|
| 24 |
+
if user_input.strip() == "":
|
| 25 |
+
st.warning("من فضلك اكتب جملة باللهجة.")
|
| 26 |
+
else:
|
| 27 |
+
inputs = tokenizer(user_input, return_tensors="pt", padding=True)
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
outputs = model.generate(**inputs, max_length=50, num_beams=5, early_stopping=True)
|
| 30 |
+
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
+
st.success("✅ الترجمة الفصحى:")
|
| 32 |
+
st.write(f"📜 {translated_text}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
streamlit
|
| 3 |
+
transformers
|
| 4 |
+
torch
|