Spaces:
Sleeping
Sleeping
Delete ui.py
Browse files
ui.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import tensorflow as tf
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import numpy as np
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import re
|
| 7 |
-
|
| 8 |
-
st.set_page_config(page_title="مترجم لغة الإشارة", layout="centered")
|
| 9 |
-
|
| 10 |
-
def normalize_arabic(text):
|
| 11 |
-
text = str(text).strip()
|
| 12 |
-
text = re.sub("[إأآ]", "ا", text)
|
| 13 |
-
text = re.sub("ة", "ه", text)
|
| 14 |
-
return text
|
| 15 |
-
|
| 16 |
-
@st.cache_resource
|
| 17 |
-
def load_all():
|
| 18 |
-
df = pd.read_excel("KARSL-100_Labels (1).xlsx")
|
| 19 |
-
word_to_id = {normalize_arabic(row['Sign-Arabic']): row['SignID'] for _, row in df.iterrows()}
|
| 20 |
-
model = tf.keras.models.load_model("word_to_sign_model.h5", compile=False)
|
| 21 |
-
return word_to_id, model
|
| 22 |
-
|
| 23 |
-
try:
|
| 24 |
-
word_to_id, text_to_sign_model = load_all()
|
| 25 |
-
except Exception as e:
|
| 26 |
-
st.error(f"خطأ في تحميل الملفات: {e}")
|
| 27 |
-
|
| 28 |
-
st.title("📂 مترجم النص إلى لغة إشارة")
|
| 29 |
-
word_input = st.text_input("أدخل الكلمة بالعربية:", placeholder="مثلاً: هيكل عظمي")
|
| 30 |
-
|
| 31 |
-
if st.button("تحويل"):
|
| 32 |
-
if word_input:
|
| 33 |
-
clean_text = normalize_arabic(word_input)
|
| 34 |
-
label_id = word_to_id.get(clean_text)
|
| 35 |
-
|
| 36 |
-
if label_id is not None:
|
| 37 |
-
one_hot_input = np.zeros((1, 100), dtype=np.float32)
|
| 38 |
-
idx = int(label_id) - 1 if int(label_id) > 0 else 0
|
| 39 |
-
if idx < 100: one_hot_input[0, idx] = 1.0
|
| 40 |
-
|
| 41 |
-
# التنبؤ
|
| 42 |
-
prediction = text_to_sign_model.predict(one_hot_input)
|
| 43 |
-
|
| 44 |
-
# --- معالجة الصورة للعرض (الحل هنا) ---
|
| 45 |
-
img_data = prediction[0]
|
| 46 |
-
# 1. تحجيم القيم لـ 0-255
|
| 47 |
-
img_data = (img_data - img_data.min()) / (img_data.max() - img_data.min() + 1e-5)
|
| 48 |
-
img_data = (img_data * 255).astype("uint8")
|
| 49 |
-
|
| 50 |
-
# 2. التأكد من الأبعاد
|
| 51 |
-
if len(img_data.shape) == 3 and img_data.shape[-1] == 1:
|
| 52 |
-
img_data = img_data.reshape(img_data.shape[0], img_data.shape[1])
|
| 53 |
-
|
| 54 |
-
# 3. تحويلها لصورة واضحة
|
| 55 |
-
img = Image.fromarray(img_data).convert("L")
|
| 56 |
-
|
| 57 |
-
st.success(f"✅ تم العثور على إشارة: {word_input}")
|
| 58 |
-
st.image(img, caption=f"إشارة {word_input}", width=400)
|
| 59 |
-
else:
|
| 60 |
-
st.error("الكلمة غير موجودة في القاموس")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|