hd-video / test_api.py
Bot
Enhance diagnostics: stream rife-ncnn stdout real-time and expose live logs in status endpoint
851c10b
Raw
History Blame Contribute Delete
2.33 kB
import sys
import time
import requests
# Menggunakan URL Space Hugging Face Anda
API_URL = "https://skyvoidwalker-hd-video.hf.space/enhance"
STATUS_URL = "https://skyvoidwalker-hd-video.hf.space/status/"
def test_enhance():
print("=" * 50)
print("[TEST CLIENT] Menghubungi API Asinkron:", API_URL)
# Kirim video test.mp4
files = {'file': open('test.mp4', 'rb')}
data = {'crf': '20'}
try:
response = requests.post(API_URL, files=files, data=data)
if response.status_code != 200:
print("[TEST CLIENT] Gagal menghubungi server:", response.text)
return
res_data = response.json()
task_id = res_data.get("task_id")
print(f"[TEST CLIENT] Antrean berhasil dibuat! Task ID: {task_id}")
# Polling status kemajuan dan print log debug penuh secara real-time
print("[TEST CLIENT] Mulai Polling Kemajuan & Log Debug...")
last_log_len = 0
while True:
status_res = requests.get(STATUS_URL + task_id)
if status_res.status_code != 200:
print("[TEST CLIENT] Gagal mengambil status:", status_res.text)
break
status_data = status_res.json()
status = status_data.get("status")
progress = status_data.get("processed_frames", 0)
total = status_data.get("total_frames", 0)
logs = status_data.get("logs", [])
# Print log debug baru saja
if len(logs) > last_log_len:
for log_line in logs[last_log_len:]:
print(log_line)
last_log_len = len(logs)
if status == "completed":
print(f"\n[TEST CLIENT] Sukses! Video selesai diproses: {progress}/{total} frame.")
print(f"[TEST CLIENT] File output dapat diunduh di: https://skyvoidwalker-hd-video.hf.space/download/{task_id}")
break
elif status == "failed":
print(f"\n[TEST CLIENT] Pemrosesan Gagal di Server: {status_data.get('error')}")
break
time.sleep(3)
except Exception as e:
print("[TEST CLIENT] Exception:", e)
if __name__ == "__main__":
test_enhance()