Spaces:
Sleeping
Sleeping
ASG Models
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -127,7 +127,10 @@ def generate_audio(text,name_model,speaker_id=None):
|
|
127 |
with torch.no_grad():
|
128 |
for chunk in _inference_forward_stream(model,input_ids=inputs.input_ids,attention_mask=inputs.attention_mask,speaker_embeddings= speaker_embeddings,chunk_size=64):
|
129 |
yield 16000,chunk.squeeze().cpu().numpy()#.astype(np.int16).tobytes()
|
130 |
-
|
|
|
|
|
|
|
131 |
def remove_extra_spaces(text):
|
132 |
"""
|
133 |
Removes extra spaces between words in a string.
|
@@ -191,9 +194,9 @@ with gr.Blocks() as demo: # Use gr.Blocks to wrap the entire interface
|
|
191 |
API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
|
192 |
text_answer = get_answer_ai(text)
|
193 |
text_answer = remove_extra_spaces(text_answer)
|
194 |
-
data_ai =
|
195 |
if generate_user_audio: # Generate user audio if needed
|
196 |
-
data_user =
|
197 |
return data_user, data_ai, text_answer
|
198 |
else:
|
199 |
return data_ai # Return None for user_audio
|
@@ -207,7 +210,7 @@ with gr.Blocks() as demo: # Use gr.Blocks to wrap the entire interface
|
|
207 |
# Additional button to generate only AI audio
|
208 |
|
209 |
btn_ai_only.click(
|
210 |
-
|
211 |
inputs=[text_input, model_choices],
|
212 |
outputs=[ai_audio],
|
213 |
)
|
|
|
127 |
with torch.no_grad():
|
128 |
for chunk in _inference_forward_stream(model,input_ids=inputs.input_ids,attention_mask=inputs.attention_mask,speaker_embeddings= speaker_embeddings,chunk_size=64):
|
129 |
yield 16000,chunk.squeeze().cpu().numpy()#.astype(np.int16).tobytes()
|
130 |
+
def generate_audio_ai(text,name_model):
|
131 |
+
text_answer = get_answer_ai(text)
|
132 |
+
text_answer = remove_extra_spaces(text_answer)
|
133 |
+
return yield generate_audio(text_answer,name_model)
|
134 |
def remove_extra_spaces(text):
|
135 |
"""
|
136 |
Removes extra spaces between words in a string.
|
|
|
194 |
API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
|
195 |
text_answer = get_answer_ai(text)
|
196 |
text_answer = remove_extra_spaces(text_answer)
|
197 |
+
data_ai = genrate_speech(text_answer,model_choice)#query(text_answer, API_URL)
|
198 |
if generate_user_audio: # Generate user audio if needed
|
199 |
+
data_user =genrate_speech(text,model_choice)# query(text, API_URL)
|
200 |
return data_user, data_ai, text_answer
|
201 |
else:
|
202 |
return data_ai # Return None for user_audio
|
|
|
210 |
# Additional button to generate only AI audio
|
211 |
|
212 |
btn_ai_only.click(
|
213 |
+
generate_audio_ai,
|
214 |
inputs=[text_input, model_choices],
|
215 |
outputs=[ai_audio],
|
216 |
)
|