plice13 commited on
Commit
6078c21
·
verified ·
1 Parent(s): 63fa1ad

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +15 -4
  2. predict_pose.py +4 -18
app.py CHANGED
@@ -18,6 +18,11 @@ os.environ["UNISIGN_WEIGHTS"] = model_path
18
  def process_video(input_video_path):
19
  # Generate a translation in the backend.
20
  translation = process_input(input_video_path)
 
 
 
 
 
21
 
22
  # Return just the translation if no visualization is found
23
  return translation, None
@@ -52,17 +57,23 @@ with gr.Blocks(title="Sign Language Translation", css=custom_css, theme=gr.theme
52
  gr.Markdown("<h1>Sign Language to Text Translation</h1>")
53
  gr.Markdown("<h3>Upload an ASL video and get a text translation.</h3>")
54
 
55
- # Everything inside this column will be centered based on the CSS above
56
  with gr.Column(elem_id="center-column"):
57
  video_input = gr.Video(label="Upload a video")
58
  submit_btn = gr.Button("Translate", variant="primary")
59
- text_output = gr.Textbox(label="Translation")
 
 
 
 
 
 
60
 
61
  submit_btn.click(
62
  fn=process_video,
63
  inputs=video_input,
64
- outputs=text_output,
65
- )
66
 
67
  if __name__ == "__main__":
68
  app.launch()
 
18
  def process_video(input_video_path):
19
  # Generate a translation in the backend.
20
  translation = process_input(input_video_path)
21
+
22
+ # Kontrola existence vytvořeného JSON souboru a jeho následné odeslání
23
+ json_path = "latest_keypoints.json"
24
+ if os.path.exists(json_path):
25
+ return translation, json_path
26
 
27
  # Return just the translation if no visualization is found
28
  return translation, None
 
57
  gr.Markdown("<h1>Sign Language to Text Translation</h1>")
58
  gr.Markdown("<h3>Upload an ASL video and get a text translation.</h3>")
59
 
60
+ # Everything inside this column will be centered based on the CSS above
61
  with gr.Column(elem_id="center-column"):
62
  video_input = gr.Video(label="Upload a video")
63
  submit_btn = gr.Button("Translate", variant="primary")
64
+
65
+ # Sekce pro překlad s legendou nahoře
66
+ gr.HTML("<fieldset><legend>Translation Output</legend></fieldset>")
67
+ text_output = gr.Textbox(show_label=False, placeholder="Your translation will appear here...")
68
+
69
+ # Pole pro stažení JSON souboru
70
+ json_output = gr.File(label="Stažené Keypoints (JSON)")
71
 
72
  submit_btn.click(
73
  fn=process_video,
74
  inputs=video_input,
75
+ outputs=[text_output, json_output],
76
+ )
77
 
78
  if __name__ == "__main__":
79
  app.launch()
predict_pose.py CHANGED
@@ -533,33 +533,19 @@ def predict_pose(video: List[np.ndarray], models: tuple, sign_space=4, yolo_sign
533
  results["images"] = video
534
 
535
  # ==========================================
536
- # NOVÉ: ULOŽENÍ KEYPOINTS DO JSON SOUBORU
537
  # ==========================================
538
-
539
- # 1. Vytvoříme složku, kam se budou JSONy ukládat
540
- output_dir = "pose_results"
541
- os.makedirs(output_dir, exist_ok=True)
542
-
543
- # 2. Vytvoříme unikátní jméno souboru s časovým razítkem
544
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
545
- json_filename = os.path.join(output_dir, f"keypoints_{timestamp}.json")
546
-
547
- # 3. Připravíme data pro JSON.
548
- # Musíme je vybrat z results, protože ty obsahují i obrázky (numpy arrays),
549
- # které do JSONu nejdou přímo uložit.
550
  json_data = {
551
  "keypoints": results["keypoints"],
552
  "cropped_keypoints": results["cropped_keypoints"]
553
  }
554
 
555
- # 4. Uložíme do souboru
556
  try:
557
- with open(json_filename, "w", encoding="utf-8") as f:
 
558
  json.dump(json_data, f, indent=4)
559
- print(f"DEBUG: Keypoints úspěšně uloženy do souboru: {json_filename}")
560
  except Exception as e:
561
  print(f"VAROVÁNÍ: Nepodařilo se uložit JSON soubor. Chyba: {e}")
562
 
563
- # ==========================================
564
-
565
  return results
 
533
  results["images"] = video
534
 
535
  # ==========================================
536
+ # NOVÉ: Uložení JSONu pro stažení přes web
537
  # ==========================================
 
 
 
 
 
 
 
 
 
 
 
 
538
  json_data = {
539
  "keypoints": results["keypoints"],
540
  "cropped_keypoints": results["cropped_keypoints"]
541
  }
542
 
 
543
  try:
544
+ # Uložíme to rovnou do hlavní složky aplikace
545
+ with open("latest_keypoints.json", "w", encoding="utf-8") as f:
546
  json.dump(json_data, f, indent=4)
547
+ print("DEBUG: JSON úspěšně uložen jako latest_keypoints.json")
548
  except Exception as e:
549
  print(f"VAROVÁNÍ: Nepodařilo se uložit JSON soubor. Chyba: {e}")
550
 
 
 
551
  return results