Spaces:
Sleeping
Sleeping
Add new API and more videos
Browse files- .gitattributes +1 -0
- .gitignore +1 -2
- app.py +19 -10
- functions.py +24 -3
- infinite_loop.mp4 +0 -0
- videos/searching_en.mp4 +3 -0
- videos/searching_es.mp4 +3 -0
- videos/searching_pt.mp4 +3 -0
- videos/waiting.mp4 +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
@@ -3,5 +3,4 @@ __pycache__/
|
|
3 |
|
4 |
data.json
|
5 |
audio.wav
|
6 |
-
video.mp4
|
7 |
-
infinite_loop.mp4
|
|
|
3 |
|
4 |
data.json
|
5 |
audio.wav
|
6 |
+
video.mp4
|
|
app.py
CHANGED
@@ -9,15 +9,16 @@ with (gr.Blocks() as app):
|
|
9 |
with gr.Tab('Test Chats'):
|
10 |
with gr.Row() as select_author:
|
11 |
author = gr.Dropdown(authors, value=authors[0], label='Author', interactive=True)
|
|
|
|
|
|
|
12 |
chat_btn = gr.Button(value='Start chat')
|
13 |
|
14 |
# ------------------------------------- Chat -------------------------------------------
|
15 |
with gr.Row(visible=False) as chatbot:
|
16 |
with gr.Column():
|
17 |
with gr.Row():
|
18 |
-
video = gr.Video(
|
19 |
-
interactive=False, label='Video', autoplay=True, value='infinite_loop.mp4'
|
20 |
-
)
|
21 |
with gr.Row():
|
22 |
output_audio = gr.Audio(interactive=False, label='Audio', autoplay=True)
|
23 |
with gr.Row():
|
@@ -25,9 +26,11 @@ with (gr.Blocks() as app):
|
|
25 |
label='Get video', info='Remember that this has a cost'
|
26 |
)
|
27 |
radio = gr.Radio(
|
28 |
-
choices=['small', 'big'], value='small',
|
|
|
|
|
29 |
)
|
30 |
-
|
31 |
|
32 |
with gr.Column():
|
33 |
with gr.Row():
|
@@ -60,18 +63,24 @@ with (gr.Blocks() as app):
|
|
60 |
).then(
|
61 |
make_visible, None, [chatbot, scores_row]
|
62 |
).then(
|
63 |
-
init_chatbot, [chat], [video, chat, user_id]
|
64 |
)
|
65 |
-
|
66 |
button_text.click(
|
|
|
|
|
|
|
|
|
67 |
get_answer_text,
|
68 |
-
[text, chat, user_id, checkbox, radio,
|
69 |
[video, output_audio, chat, text]
|
70 |
)
|
71 |
|
72 |
button_audio.click(
|
|
|
|
|
73 |
get_answer_audio,
|
74 |
-
[audio, chat, user_id, checkbox, radio,
|
75 |
[video, output_audio, chat, audio]
|
76 |
)
|
77 |
|
@@ -82,7 +91,7 @@ with (gr.Blocks() as app):
|
|
82 |
)
|
83 |
|
84 |
video.end(
|
85 |
-
lambda: '
|
86 |
)
|
87 |
|
88 |
output_audio.stop(
|
|
|
9 |
with gr.Tab('Test Chats'):
|
10 |
with gr.Row() as select_author:
|
11 |
author = gr.Dropdown(authors, value=authors[0], label='Author', interactive=True)
|
12 |
+
language = gr.Dropdown(
|
13 |
+
value='Español', choices=['Español', 'English', 'Português'], label='Language'
|
14 |
+
)
|
15 |
chat_btn = gr.Button(value='Start chat')
|
16 |
|
17 |
# ------------------------------------- Chat -------------------------------------------
|
18 |
with gr.Row(visible=False) as chatbot:
|
19 |
with gr.Column():
|
20 |
with gr.Row():
|
21 |
+
video = gr.Video(interactive=False, label='Video', autoplay=True)
|
|
|
|
|
22 |
with gr.Row():
|
23 |
output_audio = gr.Audio(interactive=False, label='Audio', autoplay=True)
|
24 |
with gr.Row():
|
|
|
26 |
label='Get video', info='Remember that this has a cost'
|
27 |
)
|
28 |
radio = gr.Radio(
|
29 |
+
choices=['small', 'big'], value='small',
|
30 |
+
label='GPU', info='Select the size of GPU (at the moment they are the same)',
|
31 |
+
visible=False
|
32 |
)
|
33 |
+
predict_language = gr.Checkbox(label='Predict language')
|
34 |
|
35 |
with gr.Column():
|
36 |
with gr.Row():
|
|
|
63 |
).then(
|
64 |
make_visible, None, [chatbot, scores_row]
|
65 |
).then(
|
66 |
+
init_chatbot, [chat, language], [video, chat, user_id]
|
67 |
)
|
68 |
+
import time
|
69 |
button_text.click(
|
70 |
+
play_searching, language, video
|
71 |
+
).then(
|
72 |
+
lambda : time.sleep(5), None, None
|
73 |
+
).then(
|
74 |
get_answer_text,
|
75 |
+
[text, chat, user_id, checkbox, radio, predict_language],
|
76 |
[video, output_audio, chat, text]
|
77 |
)
|
78 |
|
79 |
button_audio.click(
|
80 |
+
play_searching, language, video
|
81 |
+
).then(
|
82 |
get_answer_audio,
|
83 |
+
[audio, chat, user_id, checkbox, radio, predict_language],
|
84 |
[video, output_audio, chat, audio]
|
85 |
)
|
86 |
|
|
|
91 |
)
|
92 |
|
93 |
video.end(
|
94 |
+
lambda: 'videos/waiting.mp4', None, video
|
95 |
)
|
96 |
|
97 |
output_audio.stop(
|
functions.py
CHANGED
@@ -35,6 +35,19 @@ def make_visible():
|
|
35 |
return gr.Row.update(visible=True), gr.Row.update(visible=True)
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def _query(payload, size_gpu: str):
|
39 |
"""
|
40 |
Returns the json from a post request. It is done to the BellaAPI
|
@@ -61,15 +74,23 @@ def _download_media(url: str, type_media: str) -> None:
|
|
61 |
shutil.copyfileobj(r.raw, f)
|
62 |
|
63 |
|
64 |
-
def init_chatbot(chatbot: list[tuple[str, str]]):
|
65 |
"""
|
66 |
Returns a greeting video, with its transcription and the user_id that
|
67 |
will be used later in the other requests
|
68 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
# Call API with the following json
|
70 |
inputs = {"inputs": {
|
71 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
72 |
-
'language':
|
73 |
'get_video': True
|
74 |
}}
|
75 |
output = _query(inputs, 'small')
|
@@ -135,7 +156,7 @@ def _update_elements(question, chatbot, output, checkbox, clean):
|
|
135 |
|
136 |
else:
|
137 |
_download_media(link_media, 'audio')
|
138 |
-
return '
|
139 |
|
140 |
|
141 |
def save_scores(author: gr.Dropdown, history: gr.Chatbot, opinion: gr.Textbox, *score_values):
|
|
|
35 |
return gr.Row.update(visible=True), gr.Row.update(visible=True)
|
36 |
|
37 |
|
38 |
+
def play_searching(language: str):
|
39 |
+
"""
|
40 |
+
"""
|
41 |
+
if language == 'Español':
|
42 |
+
l = 'es'
|
43 |
+
elif language == 'English':
|
44 |
+
l = 'en'
|
45 |
+
else:
|
46 |
+
l = 'pt'
|
47 |
+
|
48 |
+
return f'videos/searching_{l}.mp4'
|
49 |
+
|
50 |
+
|
51 |
def _query(payload, size_gpu: str):
|
52 |
"""
|
53 |
Returns the json from a post request. It is done to the BellaAPI
|
|
|
74 |
shutil.copyfileobj(r.raw, f)
|
75 |
|
76 |
|
77 |
+
def init_chatbot(chatbot: list[tuple[str, str]], language: str):
|
78 |
"""
|
79 |
Returns a greeting video, with its transcription and the user_id that
|
80 |
will be used later in the other requests
|
81 |
"""
|
82 |
+
# Select language
|
83 |
+
if language == 'Español':
|
84 |
+
l = 'es'
|
85 |
+
elif language == 'English':
|
86 |
+
l = 'en'
|
87 |
+
else:
|
88 |
+
l = 'pt'
|
89 |
+
|
90 |
# Call API with the following json
|
91 |
inputs = {"inputs": {
|
92 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
93 |
+
'language': l,
|
94 |
'get_video': True
|
95 |
}}
|
96 |
output = _query(inputs, 'small')
|
|
|
156 |
|
157 |
else:
|
158 |
_download_media(link_media, 'audio')
|
159 |
+
return 'videos/waiting.mp4', 'audio.wav', chatbot, clean
|
160 |
|
161 |
|
162 |
def save_scores(author: gr.Dropdown, history: gr.Chatbot, opinion: gr.Textbox, *score_values):
|
infinite_loop.mp4
DELETED
Binary file (642 kB)
|
|
videos/searching_en.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4e19acf4521b44bb6b2f6024a3b01c331a75aadc65b9b7b8663013211b2ec850
|
3 |
+
size 657344
|
videos/searching_es.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9b7c0f9f5f2e55e4c707bf89f4a7786c0171305bda2f168bb8e51b7562feae6
|
3 |
+
size 759678
|
videos/searching_pt.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7760a516d7da9e1e31f2502613c636a0ed33ff2567d19f5f40168a582b6ffc6
|
3 |
+
size 1077705
|
videos/waiting.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7fb959d7ae5fb25116b403293a2314c9ac96d4ec10f6996ce0f40ebfaef8b22
|
3 |
+
size 495429
|