Spaces:
Runtime error
Runtime error
Commit
·
f36ca6d
1
Parent(s):
eb6aaad
file name fixes
Browse files- adjust.py +4 -4
- file_name.py +29 -10
- set_up.py +12 -12
- utils.py +13 -13
- video_tool.py +6 -4
adjust.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
from ui import *
|
|
|
|
| 2 |
from pydub import AudioSegment
|
| 3 |
from utils import load_groups_json
|
| 4 |
from video_tool import add_subtitle_to_video
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
import utils
|
| 8 |
-
import file_name
|
| 9 |
|
| 10 |
min_duration_ms = 10000
|
| 11 |
current_pos = 0
|
|
@@ -102,16 +102,16 @@ def start_adjust(to_name, progress=gr.Progress()):
|
|
| 102 |
# Adding subtitle to video
|
| 103 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
| 104 |
add_subtitle_to_video(
|
| 105 |
-
|
| 106 |
|
| 107 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
| 108 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(True)
|
| 109 |
print(line for line in transcribe_txt_list)
|
| 110 |
transcribe_txt = "\n".join(transcribe_txt_list)
|
| 111 |
return [
|
| 112 |
-
|
| 113 |
transcribe_txt,
|
| 114 |
-
[
|
| 115 |
]
|
| 116 |
|
| 117 |
|
|
|
|
| 1 |
from ui import *
|
| 2 |
+
from file_name import *
|
| 3 |
from pydub import AudioSegment
|
| 4 |
from utils import load_groups_json
|
| 5 |
from video_tool import add_subtitle_to_video
|
| 6 |
import gradio as gr
|
| 7 |
import os
|
| 8 |
import utils
|
|
|
|
| 9 |
|
| 10 |
min_duration_ms = 10000
|
| 11 |
current_pos = 0
|
|
|
|
| 102 |
# Adding subtitle to video
|
| 103 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
| 104 |
add_subtitle_to_video(
|
| 105 |
+
current_input_file, get_subtitle_adjusted_file(), get_video_subtitle_file(), start_time_for_adjustment(), end_time_for_adjustment)
|
| 106 |
|
| 107 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
| 108 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(True)
|
| 109 |
print(line for line in transcribe_txt_list)
|
| 110 |
transcribe_txt = "\n".join(transcribe_txt_list)
|
| 111 |
return [
|
| 112 |
+
get_video_subtitle_file(),
|
| 113 |
transcribe_txt,
|
| 114 |
+
[get_transcribe_adjusted_file(), get_subtitle_adjusted_file()]
|
| 115 |
]
|
| 116 |
|
| 117 |
|
file_name.py
CHANGED
|
@@ -1,22 +1,41 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def get_title():
|
| 5 |
-
return os.path.basename(
|
| 6 |
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
input_file = ""
|
| 11 |
-
audio_file = f"{current_working_directory}/input_{get_title()}.wav"
|
| 12 |
-
transcribe_file = f"{current_working_directory}/transcribe_{get_title()}.txt"
|
| 13 |
-
subtitle_file = f"{current_working_directory}/subtitle_{get_title()}.srt"
|
| 14 |
-
transcribe_adjusted_file = f"{current_working_directory}/transcribe_adjusted_{get_title()}.txt"
|
| 15 |
-
subtitle_adjusted_file = f"{current_working_directory}/subtitle_adjusted_{get_title()}.srt"
|
| 16 |
-
video_subtitle_file = f"{current_working_directory}/output_{get_title()}.mp4"
|
| 17 |
|
| 18 |
start_time_for_adjustment = "00:00:00"
|
| 19 |
-
end_time_for_adjustment = "00:
|
| 20 |
|
| 21 |
sample_groups_json = "sample_groups.json"
|
| 22 |
speaker_groups_json = "speaker_groups.json"
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
|
| 4 |
+
current_working_directory = os.getcwd()
|
| 5 |
+
|
| 6 |
+
current_input_file = ""
|
| 7 |
+
|
| 8 |
+
|
| 9 |
def get_title():
|
| 10 |
+
return os.path.basename(current_input_file)
|
| 11 |
|
| 12 |
|
| 13 |
+
def get_audio_file():
|
| 14 |
+
return f"{current_working_directory}/input_{get_title()}.wav"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_transcribe_file():
|
| 18 |
+
return f"{current_working_directory}/transcribe_{get_title()}.txt"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_subtitle_file():
|
| 22 |
+
return f"{current_working_directory}/subtitle_{get_title()}.srt"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_transcribe_adjusted_file():
|
| 26 |
+
return f"{current_working_directory}/transcribe_adjusted_{get_title()}.txt"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def get_subtitle_adjusted_file():
|
| 30 |
+
return f"{current_working_directory}/subtitle_adjusted_{get_title()}.srt"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_video_subtitle_file():
|
| 34 |
+
return f"{current_working_directory}/output_{get_title()}.mp4"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
start_time_for_adjustment = "00:00:00"
|
| 38 |
+
end_time_for_adjustment = "01:00:00"
|
| 39 |
|
| 40 |
sample_groups_json = "sample_groups.json"
|
| 41 |
speaker_groups_json = "speaker_groups.json"
|
set_up.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
from ui import *
|
|
|
|
| 2 |
from diarization import start_diarization
|
| 3 |
from transcribe import start_transcribe
|
| 4 |
from video_tool import convert_video_to_audio, add_subtitle_to_video
|
| 5 |
import gradio as gr
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
-
import file_name
|
| 9 |
import utils
|
| 10 |
|
| 11 |
|
|
@@ -28,22 +28,22 @@ def prepare_input(input_file, start_time, end_time, lang, model_size, use_summar
|
|
| 28 |
gr.Warning(ui_lang["model_dropdown_warning"])
|
| 29 |
return [None, None, [None, None]]
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
print(f"SOURCE: {input_file}")
|
| 36 |
-
print(f"VIDEO FILE: {
|
| 37 |
-
print(f"AUDIO FILE: {
|
| 38 |
|
| 39 |
# Convert video to audio
|
| 40 |
progress(0.2, desc=ui_lang["progress_preparing_video"])
|
| 41 |
convert_video_to_audio(
|
| 42 |
-
input_file,
|
| 43 |
|
| 44 |
# Start diarization
|
| 45 |
progress(0.4, desc=ui_lang["progress_acquiring_diarization"])
|
| 46 |
-
start_diarization(
|
| 47 |
|
| 48 |
# Start transcribing
|
| 49 |
progress(0.6, desc=ui_lang["progress_transcribing_audio"])
|
|
@@ -51,16 +51,16 @@ def prepare_input(input_file, start_time, end_time, lang, model_size, use_summar
|
|
| 51 |
|
| 52 |
# Add subtitle to video
|
| 53 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
| 54 |
-
add_subtitle_to_video(input_file,
|
| 55 |
-
|
| 56 |
|
| 57 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
| 58 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(False)
|
| 59 |
transcribe_txt = "\n".join(transcribe_txt_list)
|
| 60 |
return [
|
| 61 |
-
|
| 62 |
transcribe_txt,
|
| 63 |
-
[
|
| 64 |
]
|
| 65 |
|
| 66 |
|
|
|
|
| 1 |
from ui import *
|
| 2 |
+
from file_name import *
|
| 3 |
from diarization import start_diarization
|
| 4 |
from transcribe import start_transcribe
|
| 5 |
from video_tool import convert_video_to_audio, add_subtitle_to_video
|
| 6 |
import gradio as gr
|
| 7 |
import re
|
| 8 |
import os
|
|
|
|
| 9 |
import utils
|
| 10 |
|
| 11 |
|
|
|
|
| 28 |
gr.Warning(ui_lang["model_dropdown_warning"])
|
| 29 |
return [None, None, [None, None]]
|
| 30 |
|
| 31 |
+
current_input_file = input_file
|
| 32 |
+
start_time_for_adjustment = start_time
|
| 33 |
+
end_time_for_adjustment = end_time
|
| 34 |
|
| 35 |
print(f"SOURCE: {input_file}")
|
| 36 |
+
print(f"VIDEO FILE: {current_input_file}")
|
| 37 |
+
print(f"AUDIO FILE: {get_audio_file()}")
|
| 38 |
|
| 39 |
# Convert video to audio
|
| 40 |
progress(0.2, desc=ui_lang["progress_preparing_video"])
|
| 41 |
convert_video_to_audio(
|
| 42 |
+
input_file, get_audio_file(), start_time, end_time)
|
| 43 |
|
| 44 |
# Start diarization
|
| 45 |
progress(0.4, desc=ui_lang["progress_acquiring_diarization"])
|
| 46 |
+
start_diarization(get_audio_file())
|
| 47 |
|
| 48 |
# Start transcribing
|
| 49 |
progress(0.6, desc=ui_lang["progress_transcribing_audio"])
|
|
|
|
| 51 |
|
| 52 |
# Add subtitle to video
|
| 53 |
progress(0.8, desc=ui_lang["progress_add_subtitle"])
|
| 54 |
+
add_subtitle_to_video(input_file, get_subtitle_file,
|
| 55 |
+
get_video_subtitle_file, start_time, end_time)
|
| 56 |
|
| 57 |
# Return video file link, transcribe string, transcribe.txt, subtitle.txt
|
| 58 |
transcribe_txt_list, _ = utils.read_transcribe_subtitle_file(False)
|
| 59 |
transcribe_txt = "\n".join(transcribe_txt_list)
|
| 60 |
return [
|
| 61 |
+
get_video_subtitle_file,
|
| 62 |
transcribe_txt,
|
| 63 |
+
[get_transcribe_file, get_subtitle_file]
|
| 64 |
]
|
| 65 |
|
| 66 |
|
utils.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
import json
|
| 2 |
-
import
|
| 3 |
import os
|
| 4 |
|
| 5 |
|
| 6 |
def load_groups_json():
|
| 7 |
sample_groups_list = []
|
| 8 |
speaker_groups_dict = []
|
| 9 |
-
if os.path.exists(
|
| 10 |
-
with open(
|
| 11 |
sample_groups_list: list = json.load(json_file_sample)
|
| 12 |
-
if os.path.exists(
|
| 13 |
-
with open(
|
| 14 |
speaker_groups_dict: dict = json.load(json_file_speaker)
|
| 15 |
return sample_groups_list, speaker_groups_dict
|
| 16 |
|
| 17 |
|
| 18 |
def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list: list, adjustment: bool):
|
| 19 |
-
transcribe =
|
| 20 |
-
subtitle =
|
| 21 |
if adjustment:
|
| 22 |
-
transcribe =
|
| 23 |
-
subtitle =
|
| 24 |
|
| 25 |
with open(transcribe, "w", encoding="utf-8") as file:
|
| 26 |
file.writelines(transcribe_txt_list)
|
|
@@ -29,11 +29,11 @@ def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list:
|
|
| 29 |
|
| 30 |
|
| 31 |
def read_transcribe_subtitle_file(adjustment: bool):
|
| 32 |
-
transcribe =
|
| 33 |
-
subtitle =
|
| 34 |
if adjustment:
|
| 35 |
-
transcribe =
|
| 36 |
-
subtitle =
|
| 37 |
|
| 38 |
transcribe_txt_list = []
|
| 39 |
subtitle_txt_list = []
|
|
|
|
| 1 |
import json
|
| 2 |
+
from file_name import *
|
| 3 |
import os
|
| 4 |
|
| 5 |
|
| 6 |
def load_groups_json():
|
| 7 |
sample_groups_list = []
|
| 8 |
speaker_groups_dict = []
|
| 9 |
+
if os.path.exists(sample_groups_json):
|
| 10 |
+
with open(sample_groups_json, "r", encoding="utf-8") as json_file_sample:
|
| 11 |
sample_groups_list: list = json.load(json_file_sample)
|
| 12 |
+
if os.path.exists(speaker_groups_json):
|
| 13 |
+
with open(speaker_groups_json, "r", encoding="utf-8") as json_file_speaker:
|
| 14 |
speaker_groups_dict: dict = json.load(json_file_speaker)
|
| 15 |
return sample_groups_list, speaker_groups_dict
|
| 16 |
|
| 17 |
|
| 18 |
def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list: list, adjustment: bool):
|
| 19 |
+
transcribe = get_transcribe_file()
|
| 20 |
+
subtitle = get_subtitle_file()
|
| 21 |
if adjustment:
|
| 22 |
+
transcribe = get_transcribe_adjusted_file()
|
| 23 |
+
subtitle = get_subtitle_adjusted_file()
|
| 24 |
|
| 25 |
with open(transcribe, "w", encoding="utf-8") as file:
|
| 26 |
file.writelines(transcribe_txt_list)
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def read_transcribe_subtitle_file(adjustment: bool):
|
| 32 |
+
transcribe = get_transcribe_file()
|
| 33 |
+
subtitle = get_subtitle_file()
|
| 34 |
if adjustment:
|
| 35 |
+
transcribe = get_transcribe_adjusted_file()
|
| 36 |
+
subtitle = get_subtitle_adjusted_file()
|
| 37 |
|
| 38 |
transcribe_txt_list = []
|
| 39 |
subtitle_txt_list = []
|
video_tool.py
CHANGED
|
@@ -4,17 +4,19 @@ import ffmpeg
|
|
| 4 |
def convert_video_to_audio(input_file, output_file, start_time, end_time):
|
| 5 |
print(input_file)
|
| 6 |
print(output_file)
|
|
|
|
| 7 |
(
|
| 8 |
ffmpeg
|
| 9 |
-
.input(input_file
|
| 10 |
-
.output(output_file, format="wav", acodec='pcm_s16le')
|
| 11 |
.run(overwrite_output=True)
|
| 12 |
)
|
| 13 |
|
|
|
|
| 14 |
def add_subtitle_to_video(input_file, subtitle_file, output_file, start_time, end_time):
|
| 15 |
(
|
| 16 |
ffmpeg
|
| 17 |
-
.input(input_file
|
| 18 |
-
.output(output_file, vf='subtitles=' + subtitle_file, preset='ultrafast', acodec='copy')
|
| 19 |
.run(overwrite_output=True)
|
| 20 |
)
|
|
|
|
| 4 |
def convert_video_to_audio(input_file, output_file, start_time, end_time):
|
| 5 |
print(input_file)
|
| 6 |
print(output_file)
|
| 7 |
+
|
| 8 |
(
|
| 9 |
ffmpeg
|
| 10 |
+
.input(input_file)
|
| 11 |
+
.output(output_file, ss=start_time, to=end_time, format="wav", acodec='pcm_s16le')
|
| 12 |
.run(overwrite_output=True)
|
| 13 |
)
|
| 14 |
|
| 15 |
+
|
| 16 |
def add_subtitle_to_video(input_file, subtitle_file, output_file, start_time, end_time):
|
| 17 |
(
|
| 18 |
ffmpeg
|
| 19 |
+
.input(input_file)
|
| 20 |
+
.output(output_file, ss=start_time, to=end_time, vf='subtitles=' + subtitle_file, preset='ultrafast', acodec='copy')
|
| 21 |
.run(overwrite_output=True)
|
| 22 |
)
|