wuhp commited on
Commit
d1dde04
·
verified ·
1 Parent(s): 196cb9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -47,7 +47,7 @@ def fetch_clean_videos(keywords, api_key, scan_enabled):
47
 
48
  # --- Gradio UI setup ---
49
  with gr.Blocks() as demo:
50
- gr.Markdown("# 📼 IA Drone‑Strike Video Browser with VT Scan")
51
  with gr.Row():
52
  kw_input = gr.Textbox(label="Search keywords (comma-separated)", value="drone strike, military uav, kamikaze drone")
53
  key_input = gr.Textbox(label="VirusTotal API Key", type="password")
@@ -61,15 +61,29 @@ with gr.Blocks() as demo:
61
  allow_custom_value=True
62
  )
63
  video_player = gr.Video(label="Video Player")
 
64
 
65
  def search_and_populate(keywords, api_key, scan_enabled):
66
  urls = fetch_clean_videos(keywords, api_key, scan_enabled)
67
- # Update dropdown: use gr.update for generic component update
68
  return gr.update(choices=urls, value=urls[0] if urls else None)
69
 
70
  def update_player(selected_url):
71
- # Update video component with selected URL
72
- return gr.update(value=selected_url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  run_btn.click(
75
  fn=search_and_populate,
@@ -79,8 +93,8 @@ with gr.Blocks() as demo:
79
  url_dropdown.change(
80
  fn=update_player,
81
  inputs=[url_dropdown],
82
- outputs=[video_player]
83
  )
84
 
85
  if __name__ == "__main__":
86
- demo.launch() # HF Spaces deployment
 
47
 
48
  # --- Gradio UI setup ---
49
  with gr.Blocks() as demo:
50
+ gr.Markdown("# 📼 IA Drone‑Strike Video Browser with VT Scan + Metadata")
51
  with gr.Row():
52
  kw_input = gr.Textbox(label="Search keywords (comma-separated)", value="drone strike, military uav, kamikaze drone")
53
  key_input = gr.Textbox(label="VirusTotal API Key", type="password")
 
61
  allow_custom_value=True
62
  )
63
  video_player = gr.Video(label="Video Player")
64
+ metadata_display = gr.JSON(label="Video Metadata")
65
 
66
  def search_and_populate(keywords, api_key, scan_enabled):
67
  urls = fetch_clean_videos(keywords, api_key, scan_enabled)
 
68
  return gr.update(choices=urls, value=urls[0] if urls else None)
69
 
70
  def update_player(selected_url):
71
+ # parse out the IA identifier from the URL
72
+ # URL format: https://archive.org/download/{identifier}/{filename}
73
+ parts = selected_url.split("/")
74
+ identifier = parts[4] if len(parts) > 4 else None
75
+
76
+ # load metadata
77
+ metadata = {}
78
+ if identifier:
79
+ try:
80
+ item = get_item(identifier)
81
+ # item.metadata is already a dict
82
+ metadata = item.metadata
83
+ except Exception:
84
+ metadata = {"error": "could not retrieve metadata"}
85
+
86
+ return gr.update(value=selected_url), metadata
87
 
88
  run_btn.click(
89
  fn=search_and_populate,
 
93
  url_dropdown.change(
94
  fn=update_player,
95
  inputs=[url_dropdown],
96
+ outputs=[video_player, metadata_display]
97
  )
98
 
99
  if __name__ == "__main__":
100
+ demo.launch()