File size: 2,958 Bytes
736d327
 
 
 
 
 
 
 
 
3eba90e
e89f57c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3eba90e
e89f57c
 
 
 
 
 
 
 
 
 
 
 
3eba90e
e89f57c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3eba90e
e89f57c
 
736d327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()):
    try:
        font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
        progress(0, desc="پردازش شروع شد")
        yield "پردازش شروع شد", None
        
        # Transcription
        progress(0.35, desc="تبدیل صوت به متن")
        yield "تبدیل متن به صوت", None
        with Client("rayesh/transcribe") as client:
            job = client.submit(url, api_name="/transcribe")
            while not job.done():
                time.sleep(0.5)
            if job.failed():
                raise gr.Error("Transcription failed")
            results = job.outputs()
            if len(results) != 3:
                raise ValueError(f"Expected 3 outputs, got {len(results)}")
            srt_file, video, mp3_file = results

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

        # Video Processing
        progress(0.75, desc="پردازش ویدئو")
        yield "درحال پردازش ویدئو", None
        with Client("SPACERUNNER99/video_edite") as client:
            job = 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']

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

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

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)