File size: 2,332 Bytes
dad6d6e
851c10b
 
ccefa5f
851c10b
ccefa5f
dad6d6e
ccefa5f
851c10b
 
 
 
 
 
 
 
dad6d6e
851c10b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dad6d6e
851c10b
dad6d6e
851c10b
dad6d6e
851c10b
 
 
 
 
 
dad6d6e
851c10b
 
dad6d6e
 
851c10b
dad6d6e
851c10b
 
 
dad6d6e
851c10b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()