SPACERUNNER99 commited on
Commit
a88794e
·
verified ·
1 Parent(s): cc72f06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -12
app.py CHANGED
@@ -12,39 +12,55 @@ def main(url, parameters, progress=gr.Progress()):
12
  font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
13
  progress(0, desc="پردازش شروع شد")
14
  yield "پردازش شروع شد", None
15
-
16
- # Transcription
17
  progress(0.35, desc="تبدیل صوت به متن")
18
  yield "تبدیل متن به صوت", None
19
- with Client("rayesh/transcribe") as client:
20
- job = client.submit(url, api_name="/transcribe")
 
 
21
  while not job.done():
22
  time.sleep(0.5)
 
 
23
  if job.failed():
24
- raise gr.Error("Transcription failed")
 
25
  results = job.outputs()
26
  if len(results) != 3:
27
  raise ValueError(f"Expected 3 outputs, got {len(results)}")
 
28
  srt_file, video, mp3_file = results
 
 
29
 
30
- # Translation
31
  progress(0.55, desc="در حال ترجمه")
32
  yield "در حال ترجمه", None
33
- with Client("rayesh/translate") as client:
34
- job = client.submit(
 
 
35
  handle_file(srt_file),
36
  3000,
37
  api_name="/translate"
38
  )
39
  while not job.done():
40
- time.sleep(0.5)
 
 
41
  subtitle_file = job.outputs()[0]
 
 
42
 
43
- # Video Processing
44
  progress(0.75, desc="پردازش ویدئو")
45
  yield "درحال پردازش ویدئو", None
46
- with Client("SPACERUNNER99/video_edite") as client:
47
- job = client.submit(
 
 
48
  handle_file(subtitle_file),
49
  {"video": handle_file(video["video"])},
50
  font_color,
@@ -55,7 +71,11 @@ def main(url, parameters, progress=gr.Progress()):
55
  )
56
  while not job.done():
57
  time.sleep(0.5)
 
 
58
  output_video = job.outputs()[0]['video']
 
 
59
 
60
  yield "پردازش کامل شد", output_video
61
 
 
12
  font_type, font_size, font_color, service, target, style, subject = parameters.split(',')
13
  progress(0, desc="پردازش شروع شد")
14
  yield "پردازش شروع شد", None
15
+
16
+ # Transcription Stage
17
  progress(0.35, desc="تبدیل صوت به متن")
18
  yield "تبدیل متن به صوت", None
19
+
20
+ transcribe_client = Client("rayesh/transcribe")
21
+ try:
22
+ job = transcribe_client.submit(url, api_name="/transcribe")
23
  while not job.done():
24
  time.sleep(0.5)
25
+ progress(0.35 + (job.status().progress * 0.15))
26
+
27
  if job.failed():
28
+ raise gr.Error("Transcription API failed!")
29
+
30
  results = job.outputs()
31
  if len(results) != 3:
32
  raise ValueError(f"Expected 3 outputs, got {len(results)}")
33
+
34
  srt_file, video, mp3_file = results
35
+ finally:
36
+ transcribe_client.close()
37
 
38
+ # Translation Stage
39
  progress(0.55, desc="در حال ترجمه")
40
  yield "در حال ترجمه", None
41
+
42
+ translate_client = Client("rayesh/translate")
43
+ try:
44
+ job = translate_client.submit(
45
  handle_file(srt_file),
46
  3000,
47
  api_name="/translate"
48
  )
49
  while not job.done():
50
+ time.sleep(0.3)
51
+ progress(0.55 + (job.status().progress * 0.15))
52
+
53
  subtitle_file = job.outputs()[0]
54
+ finally:
55
+ translate_client.close()
56
 
57
+ # Video Processing Stage
58
  progress(0.75, desc="پردازش ویدئو")
59
  yield "درحال پردازش ویدئو", None
60
+
61
+ video_client = Client("SPACERUNNER99/video_edite")
62
+ try:
63
+ job = video_client.submit(
64
  handle_file(subtitle_file),
65
  {"video": handle_file(video["video"])},
66
  font_color,
 
71
  )
72
  while not job.done():
73
  time.sleep(0.5)
74
+ progress(0.75 + (job.status().progress * 0.25))
75
+
76
  output_video = job.outputs()[0]['video']
77
+ finally:
78
+ video_client.close()
79
 
80
  yield "پردازش کامل شد", output_video
81