Fix video input handling
Browse files
app.py
CHANGED
|
@@ -350,15 +350,36 @@ def download_video(url: str) -> str:
|
|
| 350 |
return None
|
| 351 |
|
| 352 |
|
| 353 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
if not api_key or not api_key.strip():
|
| 355 |
gr.Warning("Please enter your API Key")
|
| 356 |
return None
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
try:
|
| 359 |
-
gr.Info("
|
|
|
|
|
|
|
|
|
|
| 360 |
payload = {
|
| 361 |
-
,
|
| 362 |
}
|
| 363 |
result = call_api(api_key, MODEL_ENDPOINT, payload)
|
| 364 |
request_id = result.get("id")
|
|
@@ -442,11 +463,14 @@ with gr.Blocks(css=CUSTOM_CSS, title="Video Watermark Remover - WaveSpeed") as d
|
|
| 442 |
gr.HTML("""
|
| 443 |
<div class="section-title">
|
| 444 |
<svg width="20" height="20" fill="#8b5cf6" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z" clip-rule="evenodd"/></svg>
|
| 445 |
-
|
| 446 |
</div>
|
| 447 |
""")
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
# Right Column - Output
|
| 452 |
with gr.Column(scale=1):
|
|
@@ -475,7 +499,7 @@ with gr.Blocks(css=CUSTOM_CSS, title="Video Watermark Remover - WaveSpeed") as d
|
|
| 475 |
# Event binding
|
| 476 |
submit_btn.click(
|
| 477 |
fn=process,
|
| 478 |
-
inputs=[api_key_input],
|
| 479 |
outputs=output_video,
|
| 480 |
)
|
| 481 |
|
|
|
|
| 350 |
return None
|
| 351 |
|
| 352 |
|
| 353 |
+
def upload_video(api_key: str, file_path: str) -> str:
|
| 354 |
+
"""Upload video and return URL"""
|
| 355 |
+
headers = {"Authorization": f"Bearer {api_key.strip()}"}
|
| 356 |
+
with open(file_path, "rb") as f:
|
| 357 |
+
resp = requests.post(UPLOAD_ENDPOINT, headers=headers, files={"file": f}, timeout=120)
|
| 358 |
+
if resp.status_code == 401:
|
| 359 |
+
raise Exception("Invalid API Key")
|
| 360 |
+
elif resp.status_code >= 400:
|
| 361 |
+
raise Exception(f"Upload failed: {resp.status_code}")
|
| 362 |
+
data = resp.json()
|
| 363 |
+
if data.get("code") != 200:
|
| 364 |
+
raise Exception(data.get("message", "Upload failed"))
|
| 365 |
+
return data.get("data", {}).get("download_url")
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def process(api_key: str, video_path: str):
|
| 369 |
if not api_key or not api_key.strip():
|
| 370 |
gr.Warning("Please enter your API Key")
|
| 371 |
return None
|
| 372 |
+
if not video_path:
|
| 373 |
+
gr.Warning("Please upload a video")
|
| 374 |
+
return None
|
| 375 |
|
| 376 |
try:
|
| 377 |
+
gr.Info("Uploading video...")
|
| 378 |
+
video_url = upload_video(api_key, video_path)
|
| 379 |
+
|
| 380 |
+
gr.Info("Removing watermark...")
|
| 381 |
payload = {
|
| 382 |
+
"video": video_url,
|
| 383 |
}
|
| 384 |
result = call_api(api_key, MODEL_ENDPOINT, payload)
|
| 385 |
request_id = result.get("id")
|
|
|
|
| 463 |
gr.HTML("""
|
| 464 |
<div class="section-title">
|
| 465 |
<svg width="20" height="20" fill="#8b5cf6" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z" clip-rule="evenodd"/></svg>
|
| 466 |
+
Upload Video
|
| 467 |
</div>
|
| 468 |
""")
|
| 469 |
+
input_video = gr.Video(
|
| 470 |
+
label="",
|
| 471 |
+
sources=["upload"]
|
| 472 |
+
)
|
| 473 |
+
submit_btn = gr.Button("Remove Watermark", variant="primary", elem_classes="primary-btn")
|
| 474 |
|
| 475 |
# Right Column - Output
|
| 476 |
with gr.Column(scale=1):
|
|
|
|
| 499 |
# Event binding
|
| 500 |
submit_btn.click(
|
| 501 |
fn=process,
|
| 502 |
+
inputs=[api_key_input, input_video],
|
| 503 |
outputs=output_video,
|
| 504 |
)
|
| 505 |
|