Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
This function reports progress by yielding intermediate updates.
|
| 12 |
+
Gradio watches these yields to update the progress bar.
|
| 13 |
+
"""
|
| 14 |
+
font_type, font_size, background_color, font_color, service, target, style, subject = params_string.split(',')
|
| 15 |
+
# Assume parameters is a comma-separated string: "color,font"
|
| 16 |
+
progress(0, desc="پردازش شروع شد")
|
| 17 |
+
yield "پردازش شروع شد", None
|
| 18 |
+
time.sleep(2)
|
| 19 |
+
|
| 20 |
+
progress(0.35, desc="تبدیل متن به صوت")
|
| 21 |
+
yield "تبدیل متن به صوت", None
|
| 22 |
+
client = Client("rayesh/transcribe")
|
| 23 |
+
srt_file, video, mp3_file = client.predict(
|
| 24 |
+
url=url,
|
| 25 |
+
api_name="/transcribe"
|
| 26 |
+
)
|
| 27 |
+
client.close()
|
| 28 |
+
print(mp3_file)
|
| 29 |
+
progress(0.55, desc="در حال ترجمه")
|
| 30 |
+
yield "در حال ترجمه", None
|
| 31 |
+
client = Client("rayesh/translate")
|
| 32 |
+
subtitle_file = client.predict(
|
| 33 |
+
file=handle_file(srt_file),
|
| 34 |
+
max_chars=3000,
|
| 35 |
+
api_name="/translate"
|
| 36 |
+
)
|
| 37 |
+
client.close()
|
| 38 |
+
|
| 39 |
+
progress(1.0, desc="Video editing complete")
|
| 40 |
+
yield "درحال پردازش ویدئو", None
|
| 41 |
+
client = Client("SPACERUNNER99/video_edite")
|
| 42 |
+
output_video_file = client.predict(
|
| 43 |
+
srt=handle_file(subtitle_file),
|
| 44 |
+
input_video={"video":handle_file(video["video"])},
|
| 45 |
+
color=font_color,
|
| 46 |
+
font=font_type,
|
| 47 |
+
font_size=font_size,
|
| 48 |
+
background_color=background_color,
|
| 49 |
+
input_audio=handle_file(mp3_file),
|
| 50 |
+
api_name="/video_edit"
|
| 51 |
+
)
|
| 52 |
+
client.close()
|
| 53 |
+
output_video_file = output_video_file['video']
|
| 54 |
+
yield "درحال پردازش ویدئو", output_video_file
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
with gr.Blocks() as demo:
|
| 58 |
+
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
| 59 |
+
with gr.Column():
|
| 60 |
+
progress_output = gr.Textbox(label="Progress", visible=False)
|
| 61 |
+
video_file_input = gr.Text(label="Video URL")
|
| 62 |
+
clip_type = gr.Dropdown(["dub", "sub"], label="Clip Type")
|
| 63 |
+
parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
|
| 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 |
+
)
|
| 72 |
+
|
| 73 |
+
demo.launch(debug=True)
|