Spaces:
Sleeping
Sleeping
concurrent
Browse files
app.py
CHANGED
@@ -12,8 +12,7 @@ import os
|
|
12 |
import requests
|
13 |
from modules.audio import convert, get_audio_duration
|
14 |
from modules.r2 import upload_to_s3
|
15 |
-
from
|
16 |
-
import threading
|
17 |
|
18 |
vpv_webhook = os.environ.get("VPV_WEBHOOK")
|
19 |
|
@@ -71,7 +70,8 @@ class ProcessRequest(BaseModel):
|
|
71 |
format: str = "wav"
|
72 |
speed: float = 0.8
|
73 |
crossfade: float = 0.1
|
74 |
-
|
|
|
75 |
|
76 |
def process_queue(item):
|
77 |
key, censor, offset, text, format, speed, crossfade, id, receiver, webhook = item
|
@@ -92,16 +92,7 @@ def process_queue(item):
|
|
92 |
}
|
93 |
|
94 |
requests.post(webhook, json=payload)
|
95 |
-
|
96 |
-
queue = Queue()
|
97 |
-
worker = Worker(queue, process_queue, concurrency=8)
|
98 |
-
def start_worker():
|
99 |
-
worker.run()
|
100 |
|
101 |
-
thread = threading.Thread(target=start_worker)
|
102 |
-
thread.daemon = True
|
103 |
-
thread.start()
|
104 |
-
|
105 |
@app.post("/process")
|
106 |
def process_audio(payload: ProcessRequest):
|
107 |
key = payload.key
|
@@ -119,7 +110,7 @@ def process_audio(payload: ProcessRequest):
|
|
119 |
raise HTTPException(status_code=500, detail=str(e))
|
120 |
|
121 |
try:
|
122 |
-
|
123 |
return {"success": True, "err": ""}
|
124 |
|
125 |
except ValueError as e:
|
|
|
12 |
import requests
|
13 |
from modules.audio import convert, get_audio_duration
|
14 |
from modules.r2 import upload_to_s3
|
15 |
+
from concurrent.futures import ThreadPoolExecutor
|
|
|
16 |
|
17 |
vpv_webhook = os.environ.get("VPV_WEBHOOK")
|
18 |
|
|
|
70 |
format: str = "wav"
|
71 |
speed: float = 0.8
|
72 |
crossfade: float = 0.1
|
73 |
+
|
74 |
+
executor = ThreadPoolExecutor(max_workers=8)
|
75 |
|
76 |
def process_queue(item):
|
77 |
key, censor, offset, text, format, speed, crossfade, id, receiver, webhook = item
|
|
|
92 |
}
|
93 |
|
94 |
requests.post(webhook, json=payload)
|
|
|
|
|
|
|
|
|
|
|
95 |
|
|
|
|
|
|
|
|
|
96 |
@app.post("/process")
|
97 |
def process_audio(payload: ProcessRequest):
|
98 |
key = payload.key
|
|
|
110 |
raise HTTPException(status_code=500, detail=str(e))
|
111 |
|
112 |
try:
|
113 |
+
executor.submit(process_queue, (key, censor, offset, text, format, speed, crossfade, id, receiver, webhook))
|
114 |
return {"success": True, "err": ""}
|
115 |
|
116 |
except ValueError as e:
|