Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,98 +6,66 @@ import time
|
|
| 6 |
from gradio_client import Client, handle_file
|
| 7 |
|
| 8 |
|
| 9 |
-
def main(url,
|
| 10 |
"""
|
| 11 |
This function reports progress by yielding intermediate updates.
|
| 12 |
Gradio watches these yields to update the progress bar.
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
yield "پردازش شروع شد", None
|
| 17 |
-
time.sleep(2)
|
| 18 |
-
|
| 19 |
-
progress(5, desc="در حال دریافت ویدئو")
|
| 20 |
-
yield "در حال دریافت ویدئو", None
|
| 21 |
-
video = download_video(url)
|
| 22 |
-
|
| 23 |
-
#progress(10, desc="استخراج صوت")
|
| 24 |
-
#yield "استخراج صوت", None
|
| 25 |
-
#mp3_file, duration = extract_audio(video)
|
| 26 |
-
|
| 27 |
-
progress(35, desc="تبدیل متن به صوت")
|
| 28 |
-
yield "تبدیل متن به صوت", None
|
| 29 |
-
client = Client("rayesh/transcribe")
|
| 30 |
-
srt_file = client.predict(
|
| 31 |
-
mp3_file=handle_file(video),
|
| 32 |
-
api_name="/transcribe"
|
| 33 |
-
)
|
| 34 |
-
client.close()
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
progress(55, desc="در حال ترجمه")
|
| 38 |
-
yield "در حال ترجمه", None
|
| 39 |
-
subtitle_file = translate(srt_file)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
output_video_file = dub(subtitle_file, video)
|
| 43 |
-
progress(100, desc="Dubbing complete")
|
| 44 |
-
yield "درحال پردازش ویدئو", output_video_file
|
| 45 |
-
os.remove(subtitle_file)
|
| 46 |
-
|
| 47 |
-
else:
|
| 48 |
-
# Assume parameters is a comma-separated string: "color,font"
|
| 49 |
color, font = parameters.split(",")
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
| 91 |
with gr.Column():
|
| 92 |
progress_output = gr.Textbox(label="Progress", visible=False)
|
| 93 |
-
video_file_input = gr.
|
| 94 |
-
|
| 95 |
-
parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
|
| 96 |
btn = gr.Button("Create")
|
| 97 |
video_file_output = gr.Video(label="Result Video")
|
| 98 |
btn.click(
|
| 99 |
fn=main,
|
| 100 |
-
inputs=[video_file_input,
|
| 101 |
outputs=[progress_output, video_file_output],
|
| 102 |
concurrency_limit=4,
|
| 103 |
)
|
|
|
|
| 6 |
from gradio_client import Client, handle_file
|
| 7 |
|
| 8 |
|
| 9 |
+
def main(url, parameters, progress=gr.Progress()):
|
| 10 |
"""
|
| 11 |
This function reports progress by yielding intermediate updates.
|
| 12 |
Gradio watches these yields to update the progress bar.
|
| 13 |
"""
|
| 14 |
+
# Assume parameters is a comma-separated string: "color,font"
|
| 15 |
+
if parameters:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
color, font = parameters.split(",")
|
| 17 |
+
else:
|
| 18 |
+
color, font = "yellow", "arial"
|
| 19 |
+
progress(0, desc="پردازش شروع شد")
|
| 20 |
+
yield "پردازش شروع شد", None
|
| 21 |
+
time.sleep(2)
|
| 22 |
+
|
| 23 |
+
progress(0.35, desc="تبدیل متن به صوت")
|
| 24 |
+
yield "تبدیل متن به صوت", None
|
| 25 |
+
client = Client("rayesh/transcribe")
|
| 26 |
+
srt_file, video, mp3_file = client.predict(
|
| 27 |
+
url=url,
|
| 28 |
+
api_name="/transcribe"
|
| 29 |
+
)
|
| 30 |
+
client.close()
|
| 31 |
+
print(mp3_file)
|
| 32 |
+
progress(0.55, desc="در حال ترجمه")
|
| 33 |
+
yield "در حال ترجمه", None
|
| 34 |
+
client = Client("rayesh/translate")
|
| 35 |
+
subtitle_file = client.predict(
|
| 36 |
+
file=handle_file(srt_file),
|
| 37 |
+
max_chars=3000,
|
| 38 |
+
api_name="/translate"
|
| 39 |
+
)
|
| 40 |
+
client.close()
|
| 41 |
|
| 42 |
+
progress(1.0, desc="Video editing complete")
|
| 43 |
+
yield "درحال پردازش ویدئو", None
|
| 44 |
+
client = Client("SPACERUNNER99/video_edite")
|
| 45 |
+
output_video_file = client.predict(
|
| 46 |
+
srt=handle_file(subtitle_file),
|
| 47 |
+
input_video={"video":handle_file(video["video"])},
|
| 48 |
+
color=color,
|
| 49 |
+
font=font,
|
| 50 |
+
input_audio=handle_file(mp3_file),
|
| 51 |
+
api_name="/video_edit"
|
| 52 |
+
)
|
| 53 |
+
client.close()
|
| 54 |
+
output_video_file = output_video_file['video']
|
| 55 |
+
yield "درحال پردازش ویدئو", output_video_file
|
| 56 |
|
| 57 |
|
| 58 |
with gr.Blocks() as demo:
|
| 59 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
| 60 |
with gr.Column():
|
| 61 |
progress_output = gr.Textbox(label="Progress", visible=False)
|
| 62 |
+
video_file_input = gr.Video(label="Upload Video")
|
| 63 |
+
parameters = gr.Text(label="pick font and font color(font = arial, yekan, nazanin/ colors = black, yellow, white) and input it int the following format: font,font_color")
|
|
|
|
| 64 |
btn = gr.Button("Create")
|
| 65 |
video_file_output = gr.Video(label="Result Video")
|
| 66 |
btn.click(
|
| 67 |
fn=main,
|
| 68 |
+
inputs=[video_file_input, parameters],
|
| 69 |
outputs=[progress_output, video_file_output],
|
| 70 |
concurrency_limit=4,
|
| 71 |
)
|