d_transcript / app.py
johann22's picture
Update app.py
1201332 verified
raw
history blame
2.36 kB
import os
import gradio as gr
import yt_dlp
import uuid
import whisper_diarization_main
os.system("pip install Cython")
def dl(inp,img=None):
uid=uuid.uuid4()
fps="Error"
out = None
out_file=[]
if img == None and inp !="":
try:
inp_out=inp.replace("https://","")
inp_out=inp_out.replace("/","_").replace(".","_").replace("=","_").replace("?","_")
#os.system(f'yt-dlp "{inp}" --trim-filenames 160 -o "{uid}/{inp_out}.mp4" -S res,mp4 --recode mp4')
#os.system(f'yt-dlp --skip-download --write-subs --write-auto-subs --sub-lang en --sub-format ttml --convert-subs srt "{inp}" -o "{uid}/{inp_out}"')
os.system(f'yt-dlp -x "{inp}" -o "{uid}/{inp_out}"')
#f = open(f"{uid}/{inp_out}.en.srt")
os.system(f'ffmpeg -i "{uid}/{inp_out}.opus" "output.mp3"')
##ft=f.readlines()
##line_fin=""
##line_out=""
##for line in ft:
## if "<" in line:
## line_out = line.split(">",1)[1].split("<",1)[0]
## else:
## line_out = line
## if not line.strip("\n").isnumeric():
## line_fin+=line_out
#print(ft)
#out = f"{uid}/{inp_out}.mp4"
#capture = cv2.VideoCapture(out)
#fps = capture.get(cv2.CAP_PROP_FPS)
#capture.release()
out="output.mp3"
##out=f'{line_fin}'
except Exception as e:
print(e)
out = None
elif img !=None and inp == "":
capture = cv2.VideoCapture(img)
fps = capture.get(cv2.CAP_PROP_FPS)
capture.release()
out = f"{img}"
return out
def diarize_aud(file_name):
print(file_name)
#file_name=file_name.strip(".mp3")
#print(file_name)
os.system(f"python whisper_diarization_main/diarize.py -a output.mp3")
with open(f"output.txt","r") as f:
lines=f.readlines()
line_out=""
for line in lines:
line_out+=line
return line_out
with gr.Blocks() as app:
inp_url=gr.Textbox()
btn=gr.Button()
btn2=gr.Button("diarize")
outp_aud=gr.Audio(type='filepath')
outp_diary=gr.Textbox()
btn.click(dl,inp_url,outp_aud)
btn2.click(diarize_aud,outp_aud,outp_diary)
app.launch()