SPACERUNNER99 commited on
Commit
e89f57c
·
verified ·
1 Parent(s): d69663d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -77
app.py CHANGED
@@ -1,81 +1,54 @@
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, font_color, service, target, style, subject = parameters.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
- job = client.submit(
24
- url=url,
25
- api_name="/transcribe"
26
- )
27
- while not job.done():
28
- time.sleep(0.1)
29
- srt_file, video, mp3_file = job.outputs()
30
- client.close()
31
- print(mp3_file)
32
- progress(0.55, desc="در حال ترجمه")
33
- yield "در حال ترجمه", None
34
- client = Client("rayesh/translate")
35
- job = client.submit(
36
- file=handle_file(srt_file),
37
- max_chars=3000,
38
- api_name="/translate"
39
- )
40
- while not job.done():
41
- time.sleep(0.1)
42
- subtitle_file = job.outputs()
43
- client.close()
44
 
45
- progress(1.0, desc="Video editing complete")
46
- yield "درحال پردازش ویدئو", None
47
- client = Client("SPACERUNNER99/video_edite")
48
- job = client.submit(
49
- srt=handle_file(subtitle_file),
50
- input_video={"video":handle_file(video["video"])},
51
- color=font_color,
52
- font=font_type,
53
- font_size=font_size,
54
- input_audio=handle_file(mp3_file),
55
- api_name="/video_edit"
56
- )
57
- while not job.done():
58
- time.sleep(0.1)
59
- output_video_file = job.outputs()
60
- client.close()
61
- output_video_file = output_video_file['video']
62
- yield "درحال پردازش ویدئو", output_video_file
63
 
64
-
65
- with gr.Blocks() as demo:
66
- gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
67
- with gr.Column():
68
- progress_output = gr.Textbox(label="Progress", visible=False)
69
- video_file_input = gr.Text(label="Video URL")
70
- #clip_type = gr.Dropdown(["dub", "sub"], label="Clip Type")
71
- parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
72
- btn = gr.Button("Create")
73
- video_file_output = gr.Video(label="Result Video")
74
- btn.click(
75
- fn=main,
76
- inputs=[video_file_input, parameters],
77
- outputs=[progress_output, video_file_output],
78
- concurrency_limit=4,
79
- )
 
 
80
 
81
- demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
1
  def main(url, parameters, progress=gr.Progress()):
2
+ try:
3
+ font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
4
+ progress(0, desc="پردازش شروع شد")
5
+ yield "پردازش شروع شد", None
6
+
7
+ # Transcription
8
+ progress(0.35, desc="تبدیل صوت به متن")
9
+ yield "تبدیل متن به صوت", None
10
+ with Client("rayesh/transcribe") as client:
11
+ job = client.submit(url, api_name="/transcribe")
12
+ while not job.done():
13
+ time.sleep(0.5)
14
+ if job.failed():
15
+ raise gr.Error("Transcription failed")
16
+ results = job.outputs()
17
+ if len(results) != 3:
18
+ raise ValueError(f"Expected 3 outputs, got {len(results)}")
19
+ srt_file, video, mp3_file = results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Translation
22
+ progress(0.55, desc="در حال ترجمه")
23
+ yield "در حال ترجمه", None
24
+ with Client("rayesh/translate") as client:
25
+ job = client.submit(
26
+ handle_file(srt_file),
27
+ 3000,
28
+ api_name="/translate"
29
+ )
30
+ while not job.done():
31
+ time.sleep(0.5)
32
+ subtitle_file = job.outputs()[0]
 
 
 
 
 
 
33
 
34
+ # Video Processing
35
+ progress(0.75, desc="پردازش ویدئو")
36
+ yield "درحال پردازش ویدئو", None
37
+ with Client("SPACERUNNER99/video_edite") as client:
38
+ job = client.submit(
39
+ handle_file(subtitle_file),
40
+ {"video": handle_file(video["video"])},
41
+ font_color,
42
+ font_type,
43
+ font_size,
44
+ handle_file(mp3_file),
45
+ api_name="/video_edit"
46
+ )
47
+ while not job.done():
48
+ time.sleep(0.5)
49
+ output_video = job.outputs()[0]['video']
50
+
51
+ yield "پردازش کامل شد", output_video
52
 
53
+ except Exception as e:
54
+ raise gr.Error(f"خطا در پردازش: {str(e)}")