Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,23 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import os
|
5 |
import time
|
6 |
-
from gradio_client import Client,
|
|
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
9 |
def main(url, parameters, progress=gr.Progress()):
|
10 |
try:
|
11 |
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
|
12 |
progress(0, desc="پردازش شروع شد")
|
13 |
-
yield "پردازش شروع شد",
|
14 |
|
15 |
# Transcription Stage
|
16 |
progress(0.35, desc="تبدیل صوت به متن")
|
17 |
-
yield "تبدیل صوت به متن",
|
18 |
|
19 |
transcribe_client = Client("rayesh/transcribe")
|
20 |
try:
|
@@ -23,7 +28,6 @@ def main(url, parameters, progress=gr.Progress()):
|
|
23 |
time.sleep(0.5)
|
24 |
|
25 |
results = job.outputs()[0]
|
26 |
-
print(results)
|
27 |
if len(results) != 3:
|
28 |
raise ValueError(f"Expected 3 outputs, got {len(results)}")
|
29 |
|
@@ -33,7 +37,7 @@ def main(url, parameters, progress=gr.Progress()):
|
|
33 |
|
34 |
# Translation Stage
|
35 |
progress(0.55, desc="در حال ترجمه")
|
36 |
-
yield "در حال ترجمه",
|
37 |
|
38 |
translate_client = Client("rayesh/translate")
|
39 |
try:
|
@@ -50,7 +54,7 @@ def main(url, parameters, progress=gr.Progress()):
|
|
50 |
|
51 |
# Video Processing Stage
|
52 |
progress(0.75, desc="پردازش ویدئو")
|
53 |
-
yield "درحال پردازش ویدئو",
|
54 |
|
55 |
video_client = Client("SPACERUNNER99/video_edite")
|
56 |
try:
|
@@ -67,27 +71,53 @@ def main(url, parameters, progress=gr.Progress()):
|
|
67 |
time.sleep(0.5)
|
68 |
|
69 |
output_video = job.outputs()[0]['video']
|
|
|
|
|
|
|
|
|
|
|
70 |
finally:
|
71 |
video_client.close()
|
72 |
|
73 |
-
yield "پردازش کامل شد",
|
74 |
|
75 |
except Exception as e:
|
76 |
raise gr.Error(f"خطا در پردازش: {str(e)}")
|
77 |
|
|
|
|
|
|
|
78 |
with gr.Blocks() as demo:
|
79 |
-
gr.Markdown("
|
80 |
with gr.Column():
|
81 |
-
progress_output = gr.Textbox(label="
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
demo.launch(debug=True)
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
import time
|
6 |
+
from gradio_client import Client, handle_filefrom
|
7 |
+
from pathlib import Path
|
8 |
|
9 |
|
10 |
+
# Store processed videos temporarily
|
11 |
+
PROCESSED_DIR = "processed_videos"
|
12 |
+
Path(PROCESSED_DIR).mkdir(exist_ok=True)
|
13 |
+
|
14 |
def main(url, parameters, progress=gr.Progress()):
|
15 |
try:
|
16 |
font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
|
17 |
progress(0, desc="پردازش شروع شد")
|
18 |
+
yield "پردازش شروع شد", gr.DownloadButton.update(visible=False)
|
19 |
|
20 |
# Transcription Stage
|
21 |
progress(0.35, desc="تبدیل صوت به متن")
|
22 |
+
yield "تبدیل صوت به متن", gr.DownloadButton.update(visible=False)
|
23 |
|
24 |
transcribe_client = Client("rayesh/transcribe")
|
25 |
try:
|
|
|
28 |
time.sleep(0.5)
|
29 |
|
30 |
results = job.outputs()[0]
|
|
|
31 |
if len(results) != 3:
|
32 |
raise ValueError(f"Expected 3 outputs, got {len(results)}")
|
33 |
|
|
|
37 |
|
38 |
# Translation Stage
|
39 |
progress(0.55, desc="در حال ترجمه")
|
40 |
+
yield "در حال ترجمه", gr.DownloadButton.update(visible=False)
|
41 |
|
42 |
translate_client = Client("rayesh/translate")
|
43 |
try:
|
|
|
54 |
|
55 |
# Video Processing Stage
|
56 |
progress(0.75, desc="پردازش ویدئو")
|
57 |
+
yield "درحال پردازش ویدئو", gr.DownloadButton.update(visible=False)
|
58 |
|
59 |
video_client = Client("SPACERUNNER99/video_edite")
|
60 |
try:
|
|
|
71 |
time.sleep(0.5)
|
72 |
|
73 |
output_video = job.outputs()[0]['video']
|
74 |
+
|
75 |
+
# Save to processed directory with unique name
|
76 |
+
final_path = str(Path(PROCESSED_DIR) / f"output_{int(time.time())}.mp4")
|
77 |
+
Path(output_video).rename(final_path)
|
78 |
+
|
79 |
finally:
|
80 |
video_client.close()
|
81 |
|
82 |
+
yield "پردازش کامل شد", gr.DownloadButton.update(value=final_path, visible=True)
|
83 |
|
84 |
except Exception as e:
|
85 |
raise gr.Error(f"خطا در پردازش: {str(e)}")
|
86 |
|
87 |
+
def after_download():
|
88 |
+
return [gr.DownloadButton.update(visible=False), gr.Button.update(visible=True)]
|
89 |
+
|
90 |
with gr.Blocks() as demo:
|
91 |
+
gr.Markdown("## ویدئو خود را آپلود کنید یا لینک وارد نمایید")
|
92 |
with gr.Column():
|
93 |
+
progress_output = gr.Textbox(label="وضعیت پردازش", visible=False)
|
94 |
+
with gr.Row():
|
95 |
+
video_file_input = gr.Text(label="لینک ویدئو")
|
96 |
+
upload_btn = gr.UploadButton("فایل ویدئویی", file_types=["video/*"])
|
97 |
+
parameters = gr.Text(label="تنظیمات زیرنویس (فونت,اندازه,رنگ)")
|
98 |
+
create_btn = gr.Button("شروع پردازش")
|
99 |
+
download_btn = gr.DownloadButton("دانلود ویدئو نهایی", visible=False)
|
100 |
+
|
101 |
+
# Handle file upload
|
102 |
+
upload_btn.upload(
|
103 |
+
lambda f: [gr.Textbox.update(value=f.name), gr.DownloadButton.update(visible=False)],
|
104 |
+
upload_btn,
|
105 |
+
[video_file_input, download_btn]
|
106 |
+
)
|
107 |
+
|
108 |
+
# Processing handler
|
109 |
+
create_btn.click(
|
110 |
+
fn=main,
|
111 |
+
inputs=[video_file_input, parameters],
|
112 |
+
outputs=[progress_output, download_btn],
|
113 |
+
concurrency_limit=4,
|
114 |
+
)
|
115 |
+
|
116 |
+
# Download completion handler
|
117 |
+
download_btn.click(
|
118 |
+
fn=after_download,
|
119 |
+
inputs=None,
|
120 |
+
outputs=[download_btn, create_btn]
|
121 |
+
)
|
122 |
|
123 |
+
demo.launch(debug=True)
|