Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,81 +1,54 @@
|
|
1 |
-
from moviepy import VideoFileClip
|
2 |
-
import gradio as gr
|
3 |
-
import requests
|
4 |
-
import os
|
5 |
-
import time
|
6 |
-
from gradio_client import Client, handle_file
|
7 |
-
|
8 |
-
|
9 |
def main(url, parameters, progress=gr.Progress()):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
time.sleep(0.1)
|
29 |
-
srt_file, video, mp3_file = job.outputs()
|
30 |
-
client.close()
|
31 |
-
print(mp3_file)
|
32 |
-
progress(0.55, desc="در حال ترجمه")
|
33 |
-
yield "در حال ترجمه", None
|
34 |
-
client = Client("rayesh/translate")
|
35 |
-
job = client.submit(
|
36 |
-
file=handle_file(srt_file),
|
37 |
-
max_chars=3000,
|
38 |
-
api_name="/translate"
|
39 |
-
)
|
40 |
-
while not job.done():
|
41 |
-
time.sleep(0.1)
|
42 |
-
subtitle_file = job.outputs()
|
43 |
-
client.close()
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
while not job.done():
|
58 |
-
time.sleep(0.1)
|
59 |
-
output_video_file = job.outputs()
|
60 |
-
client.close()
|
61 |
-
output_video_file = output_video_file['video']
|
62 |
-
yield "درحال پردازش ویدئو", output_video_file
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def main(url, parameters, progress=gr.Progress()):
|
2 |
+
try:
|
3 |
+
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
|
4 |
+
progress(0, desc="پردازش شروع شد")
|
5 |
+
yield "پردازش شروع شد", None
|
6 |
+
|
7 |
+
# Transcription
|
8 |
+
progress(0.35, desc="تبدیل صوت به متن")
|
9 |
+
yield "تبدیل متن به صوت", None
|
10 |
+
with Client("rayesh/transcribe") as client:
|
11 |
+
job = client.submit(url, api_name="/transcribe")
|
12 |
+
while not job.done():
|
13 |
+
time.sleep(0.5)
|
14 |
+
if job.failed():
|
15 |
+
raise gr.Error("Transcription failed")
|
16 |
+
results = job.outputs()
|
17 |
+
if len(results) != 3:
|
18 |
+
raise ValueError(f"Expected 3 outputs, got {len(results)}")
|
19 |
+
srt_file, video, mp3_file = results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Translation
|
22 |
+
progress(0.55, desc="در حال ترجمه")
|
23 |
+
yield "در حال ترجمه", None
|
24 |
+
with Client("rayesh/translate") as client:
|
25 |
+
job = client.submit(
|
26 |
+
handle_file(srt_file),
|
27 |
+
3000,
|
28 |
+
api_name="/translate"
|
29 |
+
)
|
30 |
+
while not job.done():
|
31 |
+
time.sleep(0.5)
|
32 |
+
subtitle_file = job.outputs()[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# Video Processing
|
35 |
+
progress(0.75, desc="پردازش ویدئو")
|
36 |
+
yield "درحال پردازش ویدئو", None
|
37 |
+
with Client("SPACERUNNER99/video_edite") as client:
|
38 |
+
job = client.submit(
|
39 |
+
handle_file(subtitle_file),
|
40 |
+
{"video": handle_file(video["video"])},
|
41 |
+
font_color,
|
42 |
+
font_type,
|
43 |
+
font_size,
|
44 |
+
handle_file(mp3_file),
|
45 |
+
api_name="/video_edit"
|
46 |
+
)
|
47 |
+
while not job.done():
|
48 |
+
time.sleep(0.5)
|
49 |
+
output_video = job.outputs()[0]['video']
|
50 |
+
|
51 |
+
yield "پردازش کامل شد", output_video
|
52 |
|
53 |
+
except Exception as e:
|
54 |
+
raise gr.Error(f"خطا در پردازش: {str(e)}")
|