Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ st.set_page_config(page_title="DeafTranslator", layout="centered")
|
|
9 |
st.title("🤟 DeafTranslator")
|
10 |
st.markdown("Translate **Urdu** text to **English** and view it in **Sign Language** (ASL).")
|
11 |
|
12 |
-
SIGN_IMAGE_FOLDER = "sign_images" #
|
13 |
|
14 |
@st.cache_resource
|
15 |
def load_argos_urdu_to_english():
|
@@ -43,18 +43,26 @@ def translate_urdu_to_english(urdu_text):
|
|
43 |
st.error("Translation model not loaded.")
|
44 |
return ""
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def display_sign_language(english_text):
|
47 |
words = english_text.lower().split()
|
48 |
st.markdown("### 👐 Sign Language Representation")
|
49 |
for word in words:
|
50 |
-
word_img_path =
|
51 |
-
if
|
52 |
st.image(word_img_path, caption=word, width=120)
|
53 |
else:
|
54 |
for char in word:
|
55 |
if char.isalpha():
|
56 |
-
char_img_path =
|
57 |
-
if
|
58 |
st.image(char_img_path, caption=char.upper(), width=80)
|
59 |
else:
|
60 |
st.warning(f"Missing image for: {char.upper()}")
|
|
|
9 |
st.title("🤟 DeafTranslator")
|
10 |
st.markdown("Translate **Urdu** text to **English** and view it in **Sign Language** (ASL).")
|
11 |
|
12 |
+
SIGN_IMAGE_FOLDER = "sign_images" # Place images like a.jpg, A.JPG, hello.jpg, etc. here
|
13 |
|
14 |
@st.cache_resource
|
15 |
def load_argos_urdu_to_english():
|
|
|
43 |
st.error("Translation model not loaded.")
|
44 |
return ""
|
45 |
|
46 |
+
def find_image_path(name):
|
47 |
+
"""Try to find image with common extensions."""
|
48 |
+
for ext in ["jpg", "JPG"]:
|
49 |
+
path = os.path.join(SIGN_IMAGE_FOLDER, f"{name}.{ext}")
|
50 |
+
if os.path.exists(path):
|
51 |
+
return path
|
52 |
+
return None
|
53 |
+
|
54 |
def display_sign_language(english_text):
|
55 |
words = english_text.lower().split()
|
56 |
st.markdown("### 👐 Sign Language Representation")
|
57 |
for word in words:
|
58 |
+
word_img_path = find_image_path(word)
|
59 |
+
if word_img_path:
|
60 |
st.image(word_img_path, caption=word, width=120)
|
61 |
else:
|
62 |
for char in word:
|
63 |
if char.isalpha():
|
64 |
+
char_img_path = find_image_path(char.lower())
|
65 |
+
if char_img_path:
|
66 |
st.image(char_img_path, caption=char.upper(), width=80)
|
67 |
else:
|
68 |
st.warning(f"Missing image for: {char.upper()}")
|