Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,18 +6,15 @@ import time
|
|
6 |
# --- VirusTotal helper functions ---
|
7 |
def scan_url_vt(url, api_key):
|
8 |
headers = {"x-apikey": api_key}
|
9 |
-
# submit URL
|
10 |
resp = requests.post(
|
11 |
"https://www.virustotal.com/api/v3/urls", headers=headers, data={"url": url}
|
12 |
)
|
13 |
resp.raise_for_status()
|
14 |
analysis_id = resp.json()["data"]["id"]
|
15 |
-
# poll until complete
|
16 |
while True:
|
17 |
time.sleep(5)
|
18 |
status_resp = requests.get(
|
19 |
-
f"https://www.virustotal.com/api/v3/analyses/{analysis_id}",
|
20 |
-
headers=headers
|
21 |
)
|
22 |
status_resp.raise_for_status()
|
23 |
attr = status_resp.json()["data"]["attributes"]
|
@@ -29,14 +26,13 @@ def scan_url_vt(url, api_key):
|
|
29 |
def fetch_clean_videos(keywords, api_key, scan_enabled):
|
30 |
query = " OR ".join([f"{kw.strip().replace(' ', '+')}" for kw in keywords.split(",")])
|
31 |
ia_query = f"mediatype:(movies) AND ({query})"
|
32 |
-
# fetch default batch and cap at 50 items
|
33 |
results = list(search_items(ia_query))[:50]
|
34 |
clean_urls = []
|
35 |
for res in results:
|
36 |
item = get_item(res['identifier'])
|
37 |
for f in item.files:
|
38 |
fmt = f.get('format','').lower()
|
39 |
-
if fmt.startswith(('mpeg','mp4','avi','mov','webm')):
|
40 |
url = f"https://archive.org/download/{res['identifier']}/{f['name']}"
|
41 |
if scan_enabled and api_key:
|
42 |
try:
|
@@ -50,22 +46,26 @@ def fetch_clean_videos(keywords, api_key, scan_enabled):
|
|
50 |
return clean_urls
|
51 |
|
52 |
# --- Gradio UI setup ---
|
53 |
-
def gui(keywords, api_key, scan_enabled):
|
54 |
-
"""Perform search and optional VT scan, return list of clean URLs."""
|
55 |
-
urls = fetch_clean_videos(keywords, api_key, scan_enabled)
|
56 |
-
if not urls:
|
57 |
-
return "No clean videos found."
|
58 |
-
return "\n".join(urls)
|
59 |
-
|
60 |
with gr.Blocks() as demo:
|
61 |
-
gr.Markdown("# 📼 IA Drone‑Strike Video
|
62 |
with gr.Row():
|
63 |
kw_input = gr.Textbox(label="Search keywords (comma-separated)", value="drone strike, military uav, kamikaze drone")
|
64 |
key_input = gr.Textbox(label="VirusTotal API Key", type="password")
|
65 |
scan_toggle = gr.Checkbox(label="Enable VirusTotal scan", value=True)
|
66 |
run_btn = gr.Button("Search & Scan")
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
-
demo.launch() #
|
|
|
6 |
# --- VirusTotal helper functions ---
|
7 |
def scan_url_vt(url, api_key):
|
8 |
headers = {"x-apikey": api_key}
|
|
|
9 |
resp = requests.post(
|
10 |
"https://www.virustotal.com/api/v3/urls", headers=headers, data={"url": url}
|
11 |
)
|
12 |
resp.raise_for_status()
|
13 |
analysis_id = resp.json()["data"]["id"]
|
|
|
14 |
while True:
|
15 |
time.sleep(5)
|
16 |
status_resp = requests.get(
|
17 |
+
f"https://www.virustotal.com/api/v3/analyses/{analysis_id}", headers=headers
|
|
|
18 |
)
|
19 |
status_resp.raise_for_status()
|
20 |
attr = status_resp.json()["data"]["attributes"]
|
|
|
26 |
def fetch_clean_videos(keywords, api_key, scan_enabled):
|
27 |
query = " OR ".join([f"{kw.strip().replace(' ', '+')}" for kw in keywords.split(",")])
|
28 |
ia_query = f"mediatype:(movies) AND ({query})"
|
|
|
29 |
results = list(search_items(ia_query))[:50]
|
30 |
clean_urls = []
|
31 |
for res in results:
|
32 |
item = get_item(res['identifier'])
|
33 |
for f in item.files:
|
34 |
fmt = f.get('format','').lower()
|
35 |
+
if fmt.startswith(('mpeg','mp4','avi','mov','webm', 'm4v')):
|
36 |
url = f"https://archive.org/download/{res['identifier']}/{f['name']}"
|
37 |
if scan_enabled and api_key:
|
38 |
try:
|
|
|
46 |
return clean_urls
|
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")
|
54 |
scan_toggle = gr.Checkbox(label="Enable VirusTotal scan", value=True)
|
55 |
run_btn = gr.Button("Search & Scan")
|
56 |
+
|
57 |
+
url_dropdown = gr.Dropdown(label="Clean Video URLs", choices=[], interactive=True)
|
58 |
+
video_player = gr.Video(label="Video Player")
|
59 |
+
|
60 |
+
def search_and_populate(keywords, api_key, scan_enabled):
|
61 |
+
urls = fetch_clean_videos(keywords, api_key, scan_enabled)
|
62 |
+
return urls if urls else []
|
63 |
+
|
64 |
+
def update_player(selected_url):
|
65 |
+
return selected_url or None
|
66 |
+
|
67 |
+
run_btn.click(fn=search_and_populate, inputs=[kw_input, key_input, scan_toggle], outputs=url_dropdown)
|
68 |
+
url_dropdown.change(fn=update_player, inputs=url_dropdown, outputs=video_player)
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
+
demo.launch() # HF Spaces deployment
|