File size: 4,047 Bytes
736d327
 
 
3c163a9
6903bca
3c163a9
85175e3
736d327
85175e3
 
 
b6ea9e6
 
 
 
 
 
3eba90e
e89f57c
 
 
576929d
a88794e
369ad25
e89f57c
576929d
a88794e
f9eb3d4
a88794e
369ad25
3c163a9
e89f57c
369ad25
115a03f
 
 
 
 
 
3c163a9
 
 
369ad25
e89f57c
576929d
a88794e
e58ef3a
a88794e
369ad25
 
 
 
 
3c163a9
369ad25
 
3c163a9
 
3eba90e
369ad25
e89f57c
576929d
a88794e
e58ef3a
a88794e
3c163a9
369ad25
 
 
3c163a9
 
369ad25
 
3c163a9
 
e89f57c
369ad25
115a03f
4f894e0
ae57c03
a88794e
 
e89f57c
ae57c03
3eba90e
e89f57c
 
736d327
b6ea9e6
736d327
b6ea9e6
 
 
 
 
 
 
 
 
 
 
 
58fa0c2
0d43ef2
58fa0c2
b6ea9e6
 
 
 
58fa0c2
b6ea9e6
 
 
0d43ef2
b6ea9e6
 
 
 
 
 
 
 
 
 
 
0d43ef2
3c163a9
ae57c03
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import requests
import os
import time
import tempfile
from gradio_client import Client, handle_file
import gradio as gr
from pathlib import Path

def download_file():
    return  gr.DownloadButton(visible=False)
    
        # Connect the output video to both components
def update_download(output_video):
            return [
                gr.DownloadButton(visible=True, value=output_video),
                gr.File(value=output_video)
            ]
def main(url, parameters, progress=gr.Progress()):
    try:
        font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
        progress(0, desc="پردازش شروع شد")
        yield "پردازش شروع شد", None

        # Transcription Stage
        progress(0.35, desc="تبدیل صوت به متن")
        yield "تبدیل صوت به متن", None
        
        transcribe_client = Client("https://transcribe.liara.run/")
        try:
            job = transcribe_client.submit(url, api_name="/transcribe")
            while not job.done():
                time.sleep(0.5)
                
            results = job.outputs()[0]
            print(results)
            if len(results) != 3:
                raise ValueError(f"Expected 3 outputs, got {len(results)}")
                
            srt_file, video, mp3_file = results
        finally:
            transcribe_client.close()

        # Translation Stage
        progress(0.55, desc="در حال ترجمه")
        yield "در حال ترجمه", None
        
        translate_client = Client("rayesh/translate")
        try:
            job = translate_client.submit(
                handle_file(srt_file),
                3000,
                api_name="/translate"
            )
            while not job.done():
                time.sleep(0.3)
            subtitle_file = job.outputs()[0]
        finally:
            translate_client.close()

        # Video Processing Stage
        progress(0.75, desc="پردازش ویدئو")
        yield "درحال پردازش ویدئو", None
        
        video_client = Client("SPACERUNNER99/video_edite")
        try:
            job = video_client.submit(
                handle_file(subtitle_file),
                {"video": handle_file(video["video"])},
                font_color,
                font_type,
                font_size,
                handle_file(mp3_file),
                api_name="/video_edit"
            )
            while not job.done():
                time.sleep(0.5)
                
            output_video = job.outputs()[0]['video']
            
                
        finally:
            video_client.close()

        yield "پردازش کامل شد", output_video

    except Exception as e:
        raise gr.Error(f"خطا در پردازش: {str(e)}")


with gr.Blocks() as demo:
    gr.Markdown("## سیستم پردازش ویدئو")

    with gr.Row():
        video_input = gr.Textbox(label="لینک ویدئو")
        params = gr.Textbox(label="پارامترها (قلم,اندازه,رنگ)")
        submit_btn = gr.Button("شروع پردازش", variant="primary")

    progress_report = gr.Textbox(label="وضعیت", interactive=False)
    download_btn = gr.DownloadButton(
        label="دانلود ویدئو",
        visible=False,
    )
    vid_out = gr.Video()
    #hidden_file = gr.File(visible=False)
    #file_pa = gr.Text()
    # First chain: Process data and update hidden file
    submit_btn.click(
        fn=main,
        inputs=[video_input, params],
        outputs=[progress_report, vid_out],
        concurrency_limit=4,
    )

"""    # Second chain: Update download button when file is ready
    def toggle_download(file_path):
        if file_path:
            return gr.DownloadButton(visible=True, value=file_path)
        return gr.DownloadButton(visible=False)

    hidden_file.change(
        fn=toggle_download,
        inputs=hidden_file,
        outputs=download_btn,
        queue=False
    )
"""
demo.launch(debug=True)