File size: 3,729 Bytes
2a3df7f
 
 
 
f37b1e0
6aa29cc
2a3df7f
 
 
 
 
 
 
 
 
 
6aa29cc
 
2a3df7f
 
6aa29cc
2a3df7f
6aa29cc
 
 
 
2a3df7f
 
6aa29cc
 
 
 
 
 
 
2a3df7f
 
 
6aa29cc
 
2a3df7f
 
 
 
 
 
 
 
 
 
 
21b63dc
 
6aa29cc
2a3df7f
6aa29cc
4129b5b
21b63dc
6aa29cc
 
 
4129b5b
6aa29cc
2a3df7f
caa238e
6aa29cc
 
 
 
 
 
2a3df7f
6aa29cc
c121fb0
6aa29cc
 
 
1c35365
6aa29cc
 
ea3304c
6aa29cc
 
 
bf327cd
c121fb0
21b63dc
 
2a3df7f
 
 
 
 
 
 
 
 
 
 
 
 
5f56fba
2a3df7f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from moviepy import VideoFileClip
import gradio as gr
import requests
import os
import time
from gradio_client import Client, handle_file


def main(url, clip_type, parameters, progress=gr.Progress()):
    """
    This function reports progress by yielding intermediate updates. 
    Gradio watches these yields to update the progress bar.
    """
    if clip_type == "dub":
        progress(0, desc="پردازش شروع شد")
        yield "پردازش شروع شد", None
        time.sleep(2)
        
        progress(5, desc="در حال دریافت ویدئو")
        yield "در حال دریافت ویدئو", None
        video = download_video(url)

        #progress(10, desc="استخراج صوت")
        #yield "استخراج صوت", None
        #mp3_file, duration = extract_audio(video)
        
        progress(35, desc="تبدیل متن به صوت")
        yield "تبدیل متن به صوت", None
        client = Client("rayesh/transcribe")
        srt_file = client.predict(
        		mp3_file=handle_file(video),
        		api_name="/transcribe"
        )
        client.close()
        

        progress(55, desc="در حال ترجمه")
        yield "در حال ترجمه", None
        subtitle_file = translate(srt_file)


        output_video_file = dub(subtitle_file, video)
        progress(100, desc="Dubbing complete")
        yield "درحال پردازش ویدئو", output_video_file
        os.remove(subtitle_file)

    else:
        # Assume parameters is a comma-separated string: "color,font"
        color, font = parameters.split(",")
        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.Text(label="Video URL")
        clip_type = gr.Dropdown(["dub", "sub"], label="Clip Type")
        parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
        btn = gr.Button("Create")
        video_file_output = gr.Video(label="Result Video")
        btn.click(
            fn=main,
            inputs=[video_file_input, clip_type, parameters],
            outputs=[progress_output, video_file_output],
            concurrency_limit=4,
        )

demo.launch(debug=True)