SPACERUNNER99 commited on
Commit
4767b5f
·
verified ·
1 Parent(s): 4129b5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -76
app.py CHANGED
@@ -6,98 +6,66 @@ import time
6
  from gradio_client import Client, handle_file
7
 
8
 
9
- def main(url, clip_type, 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
- if clip_type == "dub":
15
- progress(0, desc="پردازش شروع شد")
16
- yield "پردازش شروع شد", None
17
- time.sleep(2)
18
-
19
- progress(5, desc="در حال دریافت ویدئو")
20
- yield "در حال دریافت ویدئو", None
21
- video = download_video(url)
22
-
23
- #progress(10, desc="استخراج صوت")
24
- #yield "استخراج صوت", None
25
- #mp3_file, duration = extract_audio(video)
26
-
27
- progress(35, desc="تبدیل متن به صوت")
28
- yield "تبدیل متن به صوت", None
29
- client = Client("rayesh/transcribe")
30
- srt_file = client.predict(
31
- mp3_file=handle_file(video),
32
- api_name="/transcribe"
33
- )
34
- client.close()
35
-
36
-
37
- progress(55, desc="در حال ترجمه")
38
- yield "در حال ترجمه", None
39
- subtitle_file = translate(srt_file)
40
-
41
-
42
- output_video_file = dub(subtitle_file, video)
43
- progress(100, desc="Dubbing complete")
44
- yield "درحال پردازش ویدئو", output_video_file
45
- os.remove(subtitle_file)
46
-
47
- else:
48
- # Assume parameters is a comma-separated string: "color,font"
49
  color, font = parameters.split(",")
50
- progress(0, desc="پردازش شروع شد")
51
- yield "پردازش شروع شد", None
52
- time.sleep(2)
53
-
54
- progress(0.35, desc="تبدیل متن به صوت")
55
- yield "تبدیل متن به صوت", None
56
- client = Client("rayesh/transcribe")
57
- srt_file, video, mp3_file = client.predict(
58
- url=url,
59
- api_name="/transcribe"
60
- )
61
- client.close()
62
- print(mp3_file)
63
- progress(0.55, desc="در حال ترجمه")
64
- yield "در حال ترجمه", None
65
- client = Client("rayesh/translate")
66
- subtitle_file = client.predict(
67
- file=handle_file(srt_file),
68
- max_chars=3000,
69
- api_name="/translate"
70
- )
71
- client.close()
 
 
72
 
73
- progress(1.0, desc="Video editing complete")
74
- yield "درحال پردازش ویدئو", None
75
- client = Client("SPACERUNNER99/video_edite")
76
- output_video_file = client.predict(
77
- srt=handle_file(subtitle_file),
78
- input_video={"video":handle_file(video["video"])},
79
- color=color,
80
- font=font,
81
- input_audio=handle_file(mp3_file),
82
- api_name="/video_edit"
83
- )
84
- client.close()
85
- output_video_file = output_video_file['video']
86
- yield "درحال پردازش ویدئو", output_video_file
87
 
88
 
89
  with gr.Blocks() as demo:
90
  gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
91
  with gr.Column():
92
  progress_output = gr.Textbox(label="Progress", visible=False)
93
- video_file_input = gr.Text(label="Video URL")
94
- clip_type = gr.Dropdown(["dub", "sub"], label="Clip Type")
95
- parameters = gr.Text(label="Additional Parameters (for subtitles: color,font)")
96
  btn = gr.Button("Create")
97
  video_file_output = gr.Video(label="Result Video")
98
  btn.click(
99
  fn=main,
100
- inputs=[video_file_input, clip_type, parameters],
101
  outputs=[progress_output, video_file_output],
102
  concurrency_limit=4,
103
  )
 
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
+ # Assume parameters is a comma-separated string: "color,font"
15
+ if parameters:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  color, font = parameters.split(",")
17
+ else:
18
+ color, font = "yellow", "arial"
19
+ progress(0, desc="پردازش شروع شد")
20
+ yield "پردازش شروع شد", None
21
+ time.sleep(2)
22
+
23
+ progress(0.35, desc="تبدیل متن به صوت")
24
+ yield "تبدیل متن به صوت", None
25
+ client = Client("rayesh/transcribe")
26
+ srt_file, video, mp3_file = client.predict(
27
+ url=url,
28
+ api_name="/transcribe"
29
+ )
30
+ client.close()
31
+ print(mp3_file)
32
+ progress(0.55, desc="در حال ترجمه")
33
+ yield "در حال ترجمه", None
34
+ client = Client("rayesh/translate")
35
+ subtitle_file = client.predict(
36
+ file=handle_file(srt_file),
37
+ max_chars=3000,
38
+ api_name="/translate"
39
+ )
40
+ client.close()
41
 
42
+ progress(1.0, desc="Video editing complete")
43
+ yield "درحال پردازش ویدئو", None
44
+ client = Client("SPACERUNNER99/video_edite")
45
+ output_video_file = client.predict(
46
+ srt=handle_file(subtitle_file),
47
+ input_video={"video":handle_file(video["video"])},
48
+ color=color,
49
+ font=font,
50
+ input_audio=handle_file(mp3_file),
51
+ api_name="/video_edit"
52
+ )
53
+ client.close()
54
+ output_video_file = output_video_file['video']
55
+ yield "درحال پردازش ویدئو", output_video_file
56
 
57
 
58
  with gr.Blocks() as demo:
59
  gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
60
  with gr.Column():
61
  progress_output = gr.Textbox(label="Progress", visible=False)
62
+ video_file_input = gr.Video(label="Upload Video")
63
+ 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")
 
64
  btn = gr.Button("Create")
65
  video_file_output = gr.Video(label="Result Video")
66
  btn.click(
67
  fn=main,
68
+ inputs=[video_file_input, parameters],
69
  outputs=[progress_output, video_file_output],
70
  concurrency_limit=4,
71
  )