Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
|
|
7 |
from collections import defaultdict
|
8 |
from uuid import uuid4
|
9 |
|
|
|
10 |
DB_CONN = pymongo.MongoClient(os.environ.get("DB_URL"))
|
11 |
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}
|
12 |
|
@@ -37,13 +38,10 @@ def render_line_details(line_id):
|
|
37 |
translation = line_detail["translator_translated_text"]
|
38 |
response = requests.post(os.environ["CF_URL"], params={"url": line_detail["source_audio_url"]})
|
39 |
signed_uri = response.text
|
40 |
-
audio_response = requests.get(signed_uri)
|
41 |
-
|
42 |
-
# with open(path, "wb") as f:
|
43 |
-
# f.write(audio_response.content)
|
44 |
-
return audio_response.content, source_transcript, translation
|
45 |
|
46 |
-
def 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):
|
47 |
line_detail = line_details[line_id]
|
48 |
video_id = line_detail["video_id"]
|
49 |
line_data = {
|
@@ -55,6 +53,7 @@ def dump_data_db(line_id, video_type, video_subject, video_topics, video_tone, g
|
|
55 |
"accent": accent,
|
56 |
"speaking_rate": round(len(translation.split()) / line_detail["line_duration"], 3),
|
57 |
"src_time": line_detail["line_duration"],
|
|
|
58 |
"version": "v1",
|
59 |
"done": True
|
60 |
}
|
@@ -105,8 +104,8 @@ with gr.Blocks() as demo:
|
|
105 |
video_html = gr.HTML(label="Video")
|
106 |
video_playable = gr.Video(label="Video")
|
107 |
with gr.Row():
|
108 |
-
video_type_dropdown = gr.Dropdown(["learning", "audiobook", "podcast", "vlog", "news", "cooking", "review"], label="Video Type", value="learning")
|
109 |
-
video_subject_dropdown = gr.Dropdown(["tech", "science", "lifestyle", "cooking", "travel", "finance", "politics"], label="Video Subject", value="tech")
|
110 |
video_topics_text = gr.Textbox(label="Video Topics")
|
111 |
with gr.Row():
|
112 |
video_tone_dropdown = gr.Dropdown(["casual", "semi-formal", "formal"], label="Video Tone", value="semi-formal")
|
@@ -123,6 +122,7 @@ with gr.Blocks() as demo:
|
|
123 |
with gr.Row():
|
124 |
audio_item = gr.Audio(label="Source Audio", type="filepath")
|
125 |
accent_text = gr.Textbox(label="Accent", value="indian")
|
|
|
126 |
with gr.Row():
|
127 |
source_transcript_text = gr.Textbox(label="Source Transcript")
|
128 |
translation_text = gr.Textbox(label="Translation", interactive=False)
|
@@ -131,8 +131,8 @@ with gr.Blocks() as demo:
|
|
131 |
# Actions
|
132 |
video_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])
|
133 |
line_id_dropdown.change(render_line_details, line_id_dropdown, [audio_item, source_transcript_text, translation_text])
|
134 |
-
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])
|
135 |
|
136 |
|
137 |
if __name__=="__main__":
|
138 |
-
demo.queue().launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
|
|
|
7 |
from collections import defaultdict
|
8 |
from uuid import uuid4
|
9 |
|
10 |
+
|
11 |
DB_CONN = pymongo.MongoClient(os.environ.get("DB_URL"))
|
12 |
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}
|
13 |
|
|
|
38 |
translation = line_detail["translator_translated_text"]
|
39 |
response = requests.post(os.environ["CF_URL"], params={"url": line_detail["source_audio_url"]})
|
40 |
signed_uri = response.text
|
41 |
+
audio_response = requests.get(signed_uri).content
|
42 |
+
return audio_response, source_transcript, translation
|
|
|
|
|
|
|
43 |
|
44 |
+
def 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):
|
45 |
line_detail = line_details[line_id]
|
46 |
video_id = line_detail["video_id"]
|
47 |
line_data = {
|
|
|
53 |
"accent": accent,
|
54 |
"speaking_rate": round(len(translation.split()) / line_detail["line_duration"], 3),
|
55 |
"src_time": line_detail["line_duration"],
|
56 |
+
"gender": speaker_gender,
|
57 |
"version": "v1",
|
58 |
"done": True
|
59 |
}
|
|
|
104 |
video_html = gr.HTML(label="Video")
|
105 |
video_playable = gr.Video(label="Video")
|
106 |
with gr.Row():
|
107 |
+
video_type_dropdown = gr.Dropdown(["learning", "audiobook", "podcast", "vlog", "news", "cooking", "review"], label="Video Type", value="learning", allow_custom_value=True)
|
108 |
+
video_subject_dropdown = gr.Dropdown(["tech", "science", "lifestyle", "cooking", "travel", "finance", "politics"], label="Video Subject", value="tech", allow_custom_value=True)
|
109 |
video_topics_text = gr.Textbox(label="Video Topics")
|
110 |
with gr.Row():
|
111 |
video_tone_dropdown = gr.Dropdown(["casual", "semi-formal", "formal"], label="Video Tone", value="semi-formal")
|
|
|
122 |
with gr.Row():
|
123 |
audio_item = gr.Audio(label="Source Audio", type="filepath")
|
124 |
accent_text = gr.Textbox(label="Accent", value="indian")
|
125 |
+
speaker_gender_dropdown = gr.Dropdown(["female", "male"], label="Speaker Gender", value="female")
|
126 |
with gr.Row():
|
127 |
source_transcript_text = gr.Textbox(label="Source Transcript")
|
128 |
translation_text = gr.Textbox(label="Translation", interactive=False)
|
|
|
131 |
# Actions
|
132 |
video_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])
|
133 |
line_id_dropdown.change(render_line_details, line_id_dropdown, [audio_item, source_transcript_text, translation_text])
|
134 |
+
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])
|
135 |
|
136 |
|
137 |
if __name__=="__main__":
|
138 |
+
demo.queue().launch(share=True, auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
|