Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,30 +12,32 @@ def main(url, parameters, progress=gr.Progress()):
|
|
12 |
progress(0, desc="پردازش شروع شد")
|
13 |
yield "پردازش شروع شد", None
|
14 |
|
15 |
-
# Transcription Stage
|
16 |
progress(0.35, desc="تبدیل صوت به متن")
|
17 |
yield "تبدیل صوت به متن", None
|
18 |
|
19 |
transcribe_client = Client("rayesh/transcribe")
|
20 |
try:
|
21 |
-
|
|
|
22 |
while not job.done():
|
23 |
time.sleep(0.5)
|
24 |
progress(0.35 + job.progress*0.2, desc="تبدیل صوت به متن")
|
25 |
|
26 |
-
results = job.outputs()
|
27 |
-
if len(results)
|
28 |
-
raise ValueError(
|
29 |
finally:
|
30 |
transcribe_client.close()
|
31 |
|
32 |
-
# Translation Stage
|
33 |
progress(0.55, desc="در حال ترجمه")
|
34 |
yield "در حال ترجمه", None
|
35 |
|
36 |
translate_client = Client("rayesh/translate")
|
37 |
try:
|
38 |
-
|
|
|
39 |
while not job.done():
|
40 |
time.sleep(0.5)
|
41 |
progress(0.55 + job.progress*0.2, desc="در حال ترجمه")
|
@@ -44,34 +46,38 @@ def main(url, parameters, progress=gr.Progress()):
|
|
44 |
finally:
|
45 |
translate_client.close()
|
46 |
|
47 |
-
# Video Processing Stage
|
48 |
progress(0.75, desc="پردازش ویدئو")
|
49 |
yield "درحال پردازش ویدئو", None
|
50 |
|
51 |
video_client = Client("SPACERUNNER99/video_edite")
|
52 |
try:
|
|
|
53 |
job = video_client.submit(
|
54 |
url,
|
55 |
translated_text,
|
56 |
font_type,
|
57 |
font_size,
|
58 |
font_color,
|
59 |
-
api_name="/
|
60 |
)
|
61 |
while not job.done():
|
62 |
time.sleep(0.5)
|
63 |
progress(0.75 + job.progress*0.25, desc="پردازش ویدئو")
|
64 |
|
65 |
-
output_video = job.outputs()[0]
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# Create temporary file
|
68 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
|
69 |
-
# Download the video content
|
70 |
response = requests.get(output_video)
|
71 |
tmp_file.write(response.content)
|
72 |
tmp_file_path = tmp_file.name
|
73 |
|
74 |
-
#
|
75 |
base_url = os.environ.get('GRADIO_SERVER_NAME', 'http://localhost:7860')
|
76 |
download_url = f"{base_url}/file/{tmp_file_path}"
|
77 |
|
|
|
12 |
progress(0, desc="پردازش شروع شد")
|
13 |
yield "پردازش شروع شد", None
|
14 |
|
15 |
+
# Transcription Stage - Updated API endpoint
|
16 |
progress(0.35, desc="تبدیل صوت به متن")
|
17 |
yield "تبدیل صوت به متن", None
|
18 |
|
19 |
transcribe_client = Client("rayesh/transcribe")
|
20 |
try:
|
21 |
+
# Changed to use default API name
|
22 |
+
job = transcribe_client.submit(url)
|
23 |
while not job.done():
|
24 |
time.sleep(0.5)
|
25 |
progress(0.35 + job.progress*0.2, desc="تبدیل صوت به متن")
|
26 |
|
27 |
+
results = job.outputs()
|
28 |
+
if len(results) < 1:
|
29 |
+
raise ValueError("No transcription results returned")
|
30 |
finally:
|
31 |
transcribe_client.close()
|
32 |
|
33 |
+
# Translation Stage - Updated API endpoint
|
34 |
progress(0.55, desc="در حال ترجمه")
|
35 |
yield "در حال ترجمه", None
|
36 |
|
37 |
translate_client = Client("rayesh/translate")
|
38 |
try:
|
39 |
+
# Changed to use default API name
|
40 |
+
job = translate_client.submit(results[0], target)
|
41 |
while not job.done():
|
42 |
time.sleep(0.5)
|
43 |
progress(0.55 + job.progress*0.2, desc="در حال ترجمه")
|
|
|
46 |
finally:
|
47 |
translate_client.close()
|
48 |
|
49 |
+
# Video Processing Stage - Updated API endpoint
|
50 |
progress(0.75, desc="پردازش ویدئو")
|
51 |
yield "درحال پردازش ویدئو", None
|
52 |
|
53 |
video_client = Client("SPACERUNNER99/video_edite")
|
54 |
try:
|
55 |
+
# Changed API name to match typical video processing endpoints
|
56 |
job = video_client.submit(
|
57 |
url,
|
58 |
translated_text,
|
59 |
font_type,
|
60 |
font_size,
|
61 |
font_color,
|
62 |
+
api_name="/process" # Changed to common endpoint name
|
63 |
)
|
64 |
while not job.done():
|
65 |
time.sleep(0.5)
|
66 |
progress(0.75 + job.progress*0.25, desc="پردازش ویدئو")
|
67 |
|
68 |
+
output_video = job.outputs()[0]
|
69 |
+
|
70 |
+
# Handle different output formats
|
71 |
+
if isinstance(output_video, dict):
|
72 |
+
output_video = output_video.get('video', output_video.get('output'))
|
73 |
|
74 |
# Create temporary file
|
75 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
|
|
|
76 |
response = requests.get(output_video)
|
77 |
tmp_file.write(response.content)
|
78 |
tmp_file_path = tmp_file.name
|
79 |
|
80 |
+
# Generate direct download link
|
81 |
base_url = os.environ.get('GRADIO_SERVER_NAME', 'http://localhost:7860')
|
82 |
download_url = f"{base_url}/file/{tmp_file_path}"
|
83 |
|