Spaces:
Sleeping
Sleeping
| from moviepy import VideoFileClip | |
| import gradio as gr | |
| import requests | |
| import os | |
| import time | |
| from gradio_client import Client, handle_file | |
| def main(url, parameters, progress=gr.Progress()): | |
| """ | |
| This function reports progress by yielding intermediate updates. | |
| Gradio watches these yields to update the progress bar. | |
| """ | |
| # Assume parameters is a comma-separated string: "color,font" | |
| if parameters: | |
| color, font = parameters.split(",") | |
| else: | |
| color, font = "yellow", "arial" | |
| progress(0, desc="پردازش شروع شد") | |
| yield "پردازش شروع شد", None | |
| time.sleep(2) | |
| progress(0.35, desc="تبدیل متن به صوت") | |
| yield "تبدیل متن به صوت", None | |
| client = Client("rayesh/transcribe") | |
| srt_file, video, mp3_file = client.predict( | |
| url=url, | |
| api_name="/transcribe" | |
| ) | |
| client.close() | |
| print(mp3_file) | |
| progress(0.55, desc="در حال ترجمه") | |
| yield "در حال ترجمه", None | |
| client = Client("rayesh/translate") | |
| subtitle_file = client.predict( | |
| file=handle_file(srt_file), | |
| max_chars=3000, | |
| api_name="/translate" | |
| ) | |
| client.close() | |
| progress(1.0, desc="Video editing complete") | |
| yield "درحال پردازش ویدئو", None | |
| client = Client("SPACERUNNER99/video_edite") | |
| output_video_file = client.predict( | |
| srt=handle_file(subtitle_file), | |
| input_video={"video":handle_file(video["video"])}, | |
| color=color, | |
| font=font, | |
| input_audio=handle_file(mp3_file), | |
| api_name="/video_edit" | |
| ) | |
| client.close() | |
| output_video_file = output_video_file['video'] | |
| yield "درحال پردازش ویدئو", output_video_file | |
| with gr.Blocks() as demo: | |
| gr.Markdown("Start typing below and then click **Run** to see the progress and final output.") | |
| with gr.Column(): | |
| progress_output = gr.Textbox(label="Progress", visible=False) | |
| video_file_input = gr.Video(label="Upload Video") | |
| 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") | |
| btn = gr.Button("Create") | |
| video_file_output = gr.Video(label="Result Video") | |
| btn.click( | |
| fn=main, | |
| inputs=[video_file_input, parameters], | |
| outputs=[progress_output, video_file_output], | |
| concurrency_limit=4, | |
| ) | |
| demo.launch(debug=True) |