st192011 commited on
Commit
c450334
Β·
verified Β·
1 Parent(s): 6bf42f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -45
app.py CHANGED
@@ -5,61 +5,62 @@ import gradio as gr
5
  from gradio_client import Client, handle_file
6
  from huggingface_hub import hf_hub_download, list_repo_files
7
 
8
- # 1. SECRETS & BACKEND LINK
9
  HF_TOKEN = os.environ.get("HF_TOKEN")
10
  PRIVATE_SPACE = "st192011/ASL-VLS-Private"
11
 
12
- try:
13
- api_client = Client(PRIVATE_SPACE, hf_token=HF_TOKEN)
14
- except Exception as e:
15
- print(f"Connection Error: {e}")
16
- api_client = None
17
-
18
- # 2. LOAD SUPPORTED GLOSSARY
19
- # We load the JSON just to get the list of words for the UI
20
  KB_FILE = "asl_rag_knowledge_base.json"
21
  supported_glosses = []
22
  if os.path.exists(KB_FILE):
23
- with open(KB_FILE, 'r') as f:
24
- kb_data = json.load(f)
25
- supported_glosses = sorted(list(set([item['gloss'].upper() for item in kb_data])))
 
 
 
26
 
27
  # 3. DATASET DISCOVERY
28
  print("Syncing with WLASL Archive...")
29
- all_files = list_repo_files(repo_id="Voxel51/WLASL", repo_type="dataset")
30
- # Filter for data_0 videos only
31
- data_0_mp4s = [f for f in all_files if f.startswith("data/data_0/") and f.endswith(".mp4")]
32
- dataset_choices = {os.path.basename(f): f for f in data_0_mp4s}
 
 
33
 
34
  # 4. LOGIC FUNCTIONS
35
  def update_video_display(selection):
36
- """Downloads the file and moves it to a Gradio-accessible directory"""
37
  if not selection: return None
38
-
39
- hf_path = dataset_choices[selection]
40
- # Download from HF cache
41
- cache_path = hf_hub_download(repo_id="Voxel51/WLASL", filename=hf_path, repo_type="dataset")
42
-
43
- # FIX: Copy to /tmp to bypass Gradio InvalidPathError
44
- local_path = os.path.join("/tmp", selection)
45
- shutil.copy(cache_path, local_path)
46
-
47
- return local_path
48
 
49
  def run_omnisign_analysis(video):
50
- """Sends the active video (sample or user-recorded) to the private VLM engine"""
51
- if not video: return {"Error: No Video Detected": 0.0}
52
- if not api_client: return {"Error: Neural Backend Offline": 0.0}
 
 
 
 
 
53
 
54
  try:
55
- # Use handle_file to safely stream the video to the private space
56
  result = api_client.predict(
57
  video_file=handle_file(video),
58
  api_name="/predict"
59
  )
60
  return result
61
  except Exception as e:
62
- return {f"Neural Engine Error: {str(e)}": 0.0}
63
 
64
  # 5. UI DESIGN (PITCH FORMAT)
65
  with gr.Blocks(theme="glass") as demo:
@@ -67,30 +68,29 @@ with gr.Blocks(theme="glass") as demo:
67
  # 🧠 OmniSign VLM
68
  ### **Universal Neural Sign Language Protocol**
69
 
70
- This demonstration introduces a revolutionary **VLM-based architecture** for sign language interpretation.
71
- Unlike traditional models that are prone to overfitting, the OmniSign protocol leverages **Temporal Neural Transduction** to generalize across all environments and signers instantly.
72
 
73
- **Proprietary Core Advantages:**
74
- * **Universal Generalization:** Robust performance in any environment, lighting, or camera angle.
75
- * **Instant Lexical Scaling:** The protocol allows for adding any new sign language word instantly without retraining.
76
- * **Person-Agnostic Reasoning:** The system analyzes movement logic rather than memorizing specific signers.
77
 
78
  ---
79
- *Notice: This is a structural demonstration. The current engine is non-optimized and operates on a limited vocabulary subset.*
80
  """)
81
 
82
  with gr.Row():
83
  with gr.Column():
84
  gr.Markdown("### 🎦 1. Input Interface")
85
- # This player handles BOTH uploads and the samples from the dropdown
86
  video_display = gr.Video(label="Neural Input Buffer")
87
 
88
  dataset_drop = gr.Dropdown(
89
  choices=[""] + sorted(list(dataset_choices.keys())),
90
- label="Explore WLASL data_0 Samples"
 
91
  )
92
 
93
- gr.Markdown("*Tip: Select a sample above to watch it, then sign it yourself or analyze the sample.*")
94
  run_btn = gr.Button("πŸš€ Execute Neural Analysis", variant="primary")
95
 
96
  with gr.Column():
@@ -98,12 +98,11 @@ with gr.Blocks(theme="glass") as demo:
98
  output_label = gr.Label(num_top_classes=3, label="Neural Confidence Score")
99
 
100
  with gr.Accordion("πŸ” Supported Glossary", open=True):
101
- gr.Markdown(f"**The system currently recognizes {len(supported_glosses)} signs:**")
102
  gr.Markdown(", ".join(supported_glosses))
103
 
104
- # Event Mapping
105
  dataset_drop.change(fn=update_video_display, inputs=dataset_drop, outputs=video_display)
106
  run_btn.click(fn=run_omnisign_analysis, inputs=video_display, outputs=output_label)
107
 
108
  if __name__ == "__main__":
109
- demo.launch()
 
 
5
  from gradio_client import Client, handle_file
6
  from huggingface_hub import hf_hub_download, list_repo_files
7
 
8
+ # 1. SECRETS
9
  HF_TOKEN = os.environ.get("HF_TOKEN")
10
  PRIVATE_SPACE = "st192011/ASL-VLS-Private"
11
 
12
+ # 2. LOAD SUPPORTED GLOSSARY (UI only)
 
 
 
 
 
 
 
13
  KB_FILE = "asl_rag_knowledge_base.json"
14
  supported_glosses = []
15
  if os.path.exists(KB_FILE):
16
+ try:
17
+ with open(KB_FILE, 'r') as f:
18
+ kb_data = json.load(f)
19
+ supported_glosses = sorted(list(set([item['gloss'].upper() for item in kb_data])))
20
+ except:
21
+ supported_glosses = ["Error loading glossary"]
22
 
23
  # 3. DATASET DISCOVERY
24
  print("Syncing with WLASL Archive...")
25
+ try:
26
+ all_files = list_repo_files(repo_id="Voxel51/WLASL", repo_type="dataset")
27
+ data_0_mp4s = [f for f in all_files if f.startswith("data/data_0/") and f.endswith(".mp4")]
28
+ dataset_choices = {os.path.basename(f): f for f in data_0_mp4s}
29
+ except:
30
+ dataset_choices = {}
31
 
32
  # 4. LOGIC FUNCTIONS
33
  def update_video_display(selection):
 
34
  if not selection: return None
35
+ try:
36
+ hf_path = dataset_choices[selection]
37
+ cache_path = hf_hub_download(repo_id="Voxel51/WLASL", filename=hf_path, repo_type="dataset")
38
+ local_path = os.path.join("/tmp", selection)
39
+ shutil.copy(cache_path, local_path)
40
+ return local_path
41
+ except Exception as e:
42
+ print(f"File Error: {e}")
43
+ return None
 
44
 
45
  def run_omnisign_analysis(video):
46
+ if not video:
47
+ return {"Error": "No video input detected."}
48
+
49
+ # LAZY LOADING: Initialize client here to avoid startup crashes
50
+ try:
51
+ api_client = Client(PRIVATE_SPACE, hf_token=HF_TOKEN)
52
+ except Exception as e:
53
+ return {"Connection Error": f"Could not reach private engine. Please ensure it is running. ({str(e)})"}
54
 
55
  try:
56
+ # Pass the video file to the private space
57
  result = api_client.predict(
58
  video_file=handle_file(video),
59
  api_name="/predict"
60
  )
61
  return result
62
  except Exception as e:
63
+ return {"Processing Error": f"The neural engine timed out or failed: {str(e)}"}
64
 
65
  # 5. UI DESIGN (PITCH FORMAT)
66
  with gr.Blocks(theme="glass") as demo:
 
68
  # 🧠 OmniSign VLM
69
  ### **Universal Neural Sign Language Protocol**
70
 
71
+ OmniSign is a proprietary architecture for sign language interpretation powered by **Large Vision-Language Models (VLM)**.
72
+ Our **Temporal Neural Transduction** protocol enables zero-shot generalization across signers and environments.
73
 
74
+ **Core Advantages:**
75
+ * **Universal Generalization:** High performance regardless of lighting, background, or camera.
76
+ * **Instant Lexical Scaling:** Vocabulary updates in seconds via semantic indexing.
77
+ * **Person-Agnostic:** Analyzes movement logic rather than memorizing individual signers.
78
 
79
  ---
80
+ *Notice: This is a structural demonstration. The engine is currently non-optimized and operates on a limited vocabulary.*
81
  """)
82
 
83
  with gr.Row():
84
  with gr.Column():
85
  gr.Markdown("### 🎦 1. Input Interface")
 
86
  video_display = gr.Video(label="Neural Input Buffer")
87
 
88
  dataset_drop = gr.Dropdown(
89
  choices=[""] + sorted(list(dataset_choices.keys())),
90
+ label="Explore WLASL data_0 Samples (Verified Support)",
91
+ value=""
92
  )
93
 
 
94
  run_btn = gr.Button("πŸš€ Execute Neural Analysis", variant="primary")
95
 
96
  with gr.Column():
 
98
  output_label = gr.Label(num_top_classes=3, label="Neural Confidence Score")
99
 
100
  with gr.Accordion("πŸ” Supported Glossary", open=True):
 
101
  gr.Markdown(", ".join(supported_glosses))
102
 
 
103
  dataset_drop.change(fn=update_video_display, inputs=dataset_drop, outputs=video_display)
104
  run_btn.click(fn=run_omnisign_analysis, inputs=video_display, outputs=output_label)
105
 
106
  if __name__ == "__main__":
107
+ # Set ssr_mode=False to improve stability on Hugging Face
108
+ demo.launch(ssr_mode=False)