Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,38 +4,6 @@ import requests
|
|
4 |
import os
|
5 |
from gradio_client import Client, handle_file
|
6 |
|
7 |
-
def extract_audio(input_video_name):
|
8 |
-
# Define the input video file and output audio file
|
9 |
-
mp3_file = "audio.mp3"
|
10 |
-
# Load the video clip
|
11 |
-
video_clip = VideoFileClip(input_video_name)
|
12 |
-
|
13 |
-
# Extract the audio from the video clip
|
14 |
-
audio_clip = video_clip.audio
|
15 |
-
duration = audio_clip.duration
|
16 |
-
print(f"Audio duration: {duration}")
|
17 |
-
# Write the audio to a separate file
|
18 |
-
audio_clip.write_audiofile(mp3_file)
|
19 |
-
|
20 |
-
# Close the video and audio clips
|
21 |
-
audio_clip.close()
|
22 |
-
video_clip.close()
|
23 |
-
|
24 |
-
print("Audio extraction successful!")
|
25 |
-
return mp3_file, duration
|
26 |
-
|
27 |
-
|
28 |
-
def download_video(url):
|
29 |
-
response = requests.get(url, stream=True)
|
30 |
-
response.raise_for_status()
|
31 |
-
video_file = "video.mp4"
|
32 |
-
with open(video_file, 'wb') as file:
|
33 |
-
for chunk in response.iter_content(chunk_size=8192):
|
34 |
-
if chunk:
|
35 |
-
file.write(chunk)
|
36 |
-
print("Video downloaded successfully!")
|
37 |
-
return video_file
|
38 |
-
|
39 |
|
40 |
def main(url, clip_type, parameters, progress=gr.Progress()):
|
41 |
"""
|
@@ -80,20 +48,13 @@ def main(url, clip_type, parameters, progress=gr.Progress()):
|
|
80 |
color, font = parameters.split(",")
|
81 |
progress(0, desc="پردازش شروع شد")
|
82 |
yield "پردازش شروع شد", None
|
83 |
-
|
84 |
-
|
85 |
-
yield "در حال دریافت ویدئو", None
|
86 |
-
video = download_video(url)
|
87 |
-
|
88 |
-
progress(10, desc="استخراج صوت")
|
89 |
-
yield "استخراج صوت", None
|
90 |
-
mp3_file, duration = extract_audio(video)
|
91 |
-
|
92 |
progress(0.35, desc="تبدیل متن به صوت")
|
93 |
yield "تبدیل متن به صوت", None
|
94 |
client = Client("rayesh/transcribe")
|
95 |
srt_file = client.predict(
|
96 |
-
|
97 |
api_name="/transcribe"
|
98 |
)
|
99 |
client.close()
|
@@ -122,6 +83,8 @@ def main(url, clip_type, parameters, progress=gr.Progress()):
|
|
122 |
client.close()
|
123 |
output_video_file = output_video_file['video']
|
124 |
yield "درحال پردازش ویدئو", output_video_file
|
|
|
|
|
125 |
with gr.Blocks() as demo:
|
126 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
127 |
with gr.Column():
|
|
|
4 |
import os
|
5 |
from gradio_client import Client, handle_file
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def main(url, clip_type, parameters, progress=gr.Progress()):
|
9 |
"""
|
|
|
48 |
color, font = parameters.split(",")
|
49 |
progress(0, desc="پردازش شروع شد")
|
50 |
yield "پردازش شروع شد", None
|
51 |
+
time.sleep(2)
|
52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
progress(0.35, desc="تبدیل متن به صوت")
|
54 |
yield "تبدیل متن به صوت", None
|
55 |
client = Client("rayesh/transcribe")
|
56 |
srt_file = client.predict(
|
57 |
+
url=url,
|
58 |
api_name="/transcribe"
|
59 |
)
|
60 |
client.close()
|
|
|
83 |
client.close()
|
84 |
output_video_file = output_video_file['video']
|
85 |
yield "درحال پردازش ویدئو", output_video_file
|
86 |
+
|
87 |
+
|
88 |
with gr.Blocks() as demo:
|
89 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
90 |
with gr.Column():
|