Spaces:
Sleeping
Sleeping
Add language detection
Browse files- app.py +3 -2
- functions.py +12 -4
app.py
CHANGED
@@ -27,6 +27,7 @@ with (gr.Blocks() as app):
|
|
27 |
radio = gr.Radio(
|
28 |
choices=['small', 'big'], value='small', label='GPU', info='Select the size of GPU'
|
29 |
)
|
|
|
30 |
|
31 |
with gr.Column():
|
32 |
with gr.Row():
|
@@ -64,13 +65,13 @@ with (gr.Blocks() as app):
|
|
64 |
|
65 |
button_text.click(
|
66 |
get_answer_text,
|
67 |
-
[text, chat, user_id, checkbox, radio],
|
68 |
[video, output_audio, chat, text]
|
69 |
)
|
70 |
|
71 |
button_audio.click(
|
72 |
get_answer_audio,
|
73 |
-
[audio, chat, user_id, checkbox, radio],
|
74 |
[video, output_audio, chat, audio]
|
75 |
)
|
76 |
|
|
|
27 |
radio = gr.Radio(
|
28 |
choices=['small', 'big'], value='small', label='GPU', info='Select the size of GPU'
|
29 |
)
|
30 |
+
language = gr.Checkbox(label='Predict language')
|
31 |
|
32 |
with gr.Column():
|
33 |
with gr.Row():
|
|
|
65 |
|
66 |
button_text.click(
|
67 |
get_answer_text,
|
68 |
+
[text, chat, user_id, checkbox, radio, language],
|
69 |
[video, output_audio, chat, text]
|
70 |
)
|
71 |
|
72 |
button_audio.click(
|
73 |
get_answer_audio,
|
74 |
+
[audio, chat, user_id, checkbox, radio, language],
|
75 |
[video, output_audio, chat, audio]
|
76 |
)
|
77 |
|
functions.py
CHANGED
@@ -69,6 +69,7 @@ def init_chatbot(chatbot: list[tuple[str, str]]):
|
|
69 |
# Call API with the following json
|
70 |
inputs = {"inputs": {
|
71 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
72 |
'get_video': True
|
73 |
}}
|
74 |
output = _query(inputs, 'small')
|
@@ -80,21 +81,25 @@ def init_chatbot(chatbot: list[tuple[str, str]]):
|
|
80 |
|
81 |
|
82 |
def get_answer_text(
|
83 |
-
question: str, chatbot: list[tuple[str, str]], user_id: str, checkbox: bool, size_gpu: str
|
|
|
84 |
):
|
85 |
"""
|
86 |
Gets the answer of the chatbot
|
87 |
"""
|
|
|
|
|
88 |
# Create json and send it to the API
|
89 |
inputs = {'inputs': {
|
90 |
-
'text': question, 'user_id': user_id, 'get_video': checkbox
|
91 |
}}
|
92 |
output = _query(inputs, size_gpu)
|
93 |
return _update_elements(question, chatbot, output, checkbox, '')
|
94 |
|
95 |
|
96 |
def get_answer_audio(
|
97 |
-
audio_path, chatbot: list[tuple[str, str]], user_id: str, checkbox: bool, size_gpu: str
|
|
|
98 |
):
|
99 |
"""
|
100 |
Gets the answer of the chatbot
|
@@ -104,9 +109,12 @@ def get_answer_audio(
|
|
104 |
audio_data = audio_file.read()
|
105 |
encoded_audio = base64.b64encode(audio_data).decode('utf-8')
|
106 |
|
|
|
|
|
107 |
# Create json and send it to the API
|
108 |
inputs = {'inputs': {
|
109 |
-
'is_audio': True, 'audio': encoded_audio, 'user_id': user_id, 'get_video': checkbox
|
|
|
110 |
}}
|
111 |
output = _query(inputs, size_gpu)
|
112 |
|
|
|
69 |
# Call API with the following json
|
70 |
inputs = {"inputs": {
|
71 |
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
72 |
+
'language': 'es',
|
73 |
'get_video': True
|
74 |
}}
|
75 |
output = _query(inputs, 'small')
|
|
|
81 |
|
82 |
|
83 |
def get_answer_text(
|
84 |
+
question: str, chatbot: list[tuple[str, str]], user_id: str, checkbox: bool, size_gpu: str,
|
85 |
+
detect_language: bool
|
86 |
):
|
87 |
"""
|
88 |
Gets the answer of the chatbot
|
89 |
"""
|
90 |
+
get_language = None if detect_language is False else True
|
91 |
+
|
92 |
# Create json and send it to the API
|
93 |
inputs = {'inputs': {
|
94 |
+
'text': question, 'user_id': user_id, 'get_video': checkbox, 'get_language': get_language
|
95 |
}}
|
96 |
output = _query(inputs, size_gpu)
|
97 |
return _update_elements(question, chatbot, output, checkbox, '')
|
98 |
|
99 |
|
100 |
def get_answer_audio(
|
101 |
+
audio_path, chatbot: list[tuple[str, str]], user_id: str, checkbox: bool, size_gpu: str,
|
102 |
+
detect_language: bool
|
103 |
):
|
104 |
"""
|
105 |
Gets the answer of the chatbot
|
|
|
109 |
audio_data = audio_file.read()
|
110 |
encoded_audio = base64.b64encode(audio_data).decode('utf-8')
|
111 |
|
112 |
+
get_language = None if detect_language is False else True
|
113 |
+
|
114 |
# Create json and send it to the API
|
115 |
inputs = {'inputs': {
|
116 |
+
'is_audio': True, 'audio': encoded_audio, 'user_id': user_id, 'get_video': checkbox,
|
117 |
+
'get_language': get_language
|
118 |
}}
|
119 |
output = _query(inputs, size_gpu)
|
120 |
|