masadonline commited on
Commit
570a8e7
·
verified ·
1 Parent(s): 4acb7e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
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" # Make sure this folder contains a.jpg, b.jpg, etc.
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 = os.path.join(SIGN_IMAGE_FOLDER, f"{word}.jpg")
51
- if os.path.exists(word_img_path):
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 = os.path.join(SIGN_IMAGE_FOLDER, f"{char.lower()}.jpg")
57
- if os.path.exists(char_img_path):
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()}")