Spaces:
Runtime error
Runtime error
Update app.py
Browse files6 unmodified lines78910111224 unmodified lines373839404142434445464748495 unmodified lines55565758596044 unmodified lines10510610710810911011111210 unmodified lines1231241251261271282 unmodified lines1311321331341351361371386 unmodified linesfrom collections import defaultdictfrom uuid import uuid4DB_CONN = pymongo.MongoClient(os.environ.get("DB_URL"))line_details = {l["source_id"]:l for l in list(DB_CONN['vo_data_dump']['qa_video_dump'].find()) if l.get("done") is not True}24 unmodified linestranslation = line_detail["translator_translated_text"]response = requests.post(os.environ["CF_URL"], params={"url": line_detail["source_audio_url"]})signed_uri = response.textaudio_response = requests.get(signed_uri)# path = os.path.join("temp_audios", f"{uuid4()}.mp3")# with open(path, "wb") as f:# f.write(audio_response.content)return audio_response.content, source_transcript, translationdef dump_data_db(line_id, video_type, video_subject, video_topics, video_tone, gender, demography, total_time, source_language, target_language, comments, accent, source_transcript, translation):line_detail = line_details[line_id]video_id = line_detail["video_id"]line_data = {5 unmodified lines"accent": accent,"speaking_rate": round(len(translation.split()) / line_detail["line_duration"], 3),"src_time": line_detail["line_duration"],"version": "v1","done": True}44 unmodified linesvideo_html = gr.HTML(label="Video")video_playable = gr.Video(label="Video")with gr.Row():video_type_dropdown = gr.Dropdown(["learning", "audiobook", "podcast", "vlog", "news", "cooking", "review"], label="Video Type", value="learning")video_subject_dropdown = gr.Dropdown(["tech", "science", "lifestyle", "cooking", "travel", "finance", "politics"], label="Video Subject", value="tech")video_topics_text = gr.Textbox(label="Video Topics")with gr.Row():video_tone_dropdown = gr.Dropdown(["casual", "semi-formal", "formal"], label="Video Tone", value="semi-formal")10 unmodified lineswith gr.Row():audio_item = gr.Audio(label="Source Audio", type="filepath")accent_text = gr.Textbox(label="Accent", value="indian")with gr.Row():source_transcript_text = gr.Textbox(label="Source Transcript")translation_text = gr.Textbox(label="Translation", interactive=False)2 unmodified lines# Actionsvideo_id_dropdown.change(render_video_details, video_id_dropdown, [video_title_text, source_language_text, target_language_text, total_time_text, line_id_dropdown, video_html, video_playable])line_id_dropdown.change(render_line_details, line_id_dropdown, [audio_item, source_transcript_text, translation_text])update_button.click(dump_data_db, [line_id_dropdown, video_type_dropdown, video_subject_dropdown, video_topics_text, video_tone_dropdown, gender_dropdown, demography_text, total_time_text, source_language_text, target_language_text, comments_text, accent_text, source_transcript_text, translation_text], [line_id_dropdown, video_id_dropdown])if __name__=="__main__":demo.queue().launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))6 unmodified lines7891011121324 unmodified lines383940414243444546475 unmodified lines5354555657585944 unmodified lines10410510610710810911011110 unmodified lines1221231241251261271282 unmodified lines1311321331341351361371386 unmodified linesfrom collections import defaultdictfrom uuid import uuid4DB_CONN = pymongo.MongoClient(os.environ.get("DB_URL"))line_details = {l["source_id"]:l for l in list(DB_CONN['vo_data_dump']['qa_video_dump'].find()) if l.get("done") is not True}24 unmodified linestranslation = line_detail["translator_translated_text"]response = requests.post(os.environ["CF_URL"], params={"url": line_detail["source_audio_url"]})signed_uri = response.textaudio_response = requests.get(signed_uri).contentreturn audio_response, source_transcript, translationdef dump_data_db(line_id, video_type, video_subject, video_topics, video_tone, gender, demography, total_time, source_language, target_language, comments, accent, source_transcript, translation, speaker_gender):line_detail = line_details[line_id]video_id = line_detail["video_id"]line_data = {5 unmodified lines"accent": accent,"speaking_rate": round(len(translation.split()) / line_detail["line_duration"], 3),"src_time": line_detail["line_duration"],"gender": speaker_gender,"version": "v1","done": True}44 unmodified linesvideo_html = gr.HTML(label="Video")video_playable = gr.Video(label="Video")with gr.Row():video_type_dropdown = gr.Dropdown(["learning", "audiobook", "podcast", "vlog", "news", "cooking", "review"], label="Video Type", value="learning", allow_custom_value=True)video_subject_dropdown = gr.Dropdown(["tech", "science", "lifestyle", "cooking", "travel", "finance", "politics"], label="Video Subject", value="tech", allow_custom_value=True)video_topics_text = gr.Textbox(label="Video Topics")with gr.Row():video_tone_dropdown = gr.Dropdown(["casual", "semi-formal", "formal"], label="Video Tone", value="semi-formal")10 unmodified lineswith gr.Row():audio_item = gr.Audio(label="Source Audio", type="filepath")accent_text = gr.Textbox(label="Accent", value="indian")speaker_gender_dropdown = gr.Dropdown(["female", "male"], label="Speaker Gender", value="female")with gr.Row():source_transcript_text = gr.Textbox(label="Source Transcript")translation_text = gr.Textbox(label="Translation", interactive=False)2 unmodified lines# Actionsvideo_id_dropdown.change(render_video_details, video_id_dropdown, [video_title_text, source_language_text, target_language_text, total_time_text, line_id_dropdown, video_html, video_playable])line_id_dropdown.change(render_line_details, line_id_dropdown, [audio_item, source_transcript_text, translation_text])update_button.click(dump_data_db, [line_id_dropdown, video_type_dropdown, video_subject_dropdown, video_topics_text, video_tone_dropdown, gender_dropdown, demography_text, total_time_text, source_language_text, target_language_text, comments_text, accent_text, source_transcript_text, translation_text, speaker_gender_dropdown], [line_id_dropdown, video_id_dropdown])if __name__=="__main__":demo.queue().launch(share=True, auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
app.py+10-10