Spaces:
Running
Running
Write audios to tmp folder; changed the title bar
Browse files
app.py
CHANGED
@@ -84,8 +84,9 @@ def chat_and_speak(user_input, language_choice):
|
|
84 |
if hasattr(tts_response, "audio_data") and isinstance(tts_response.audio_data, str) and tts_response.audio_data:
|
85 |
try:
|
86 |
audio_bytes = base64.b64decode(tts_response.audio_data)
|
87 |
-
|
88 |
-
|
|
|
89 |
with open(audio_output_path, "wb") as f:
|
90 |
f.write(audio_bytes)
|
91 |
except Exception as audio_err:
|
@@ -110,12 +111,12 @@ with open("custom.css") as f:
|
|
110 |
|
111 |
with gr.Blocks(css=custom_css) as demo:
|
112 |
gr.HTML(
|
113 |
-
'<div class="custom-bar"><span class="custom-bar-title">
|
114 |
)
|
115 |
with gr.Column(elem_classes="main-card"):
|
116 |
with gr.Row():
|
117 |
with gr.Column():
|
118 |
-
user_input = gr.Textbox(label="Type in whatever language you
|
119 |
language_choice = gr.Dropdown(
|
120 |
choices=["Portuguese", "French", "Spanish"],
|
121 |
value="Portuguese",
|
|
|
84 |
if hasattr(tts_response, "audio_data") and isinstance(tts_response.audio_data, str) and tts_response.audio_data:
|
85 |
try:
|
86 |
audio_bytes = base64.b64decode(tts_response.audio_data)
|
87 |
+
output_dir = "/tmp" if RUNNING_IN_SPACES else "speech_files"
|
88 |
+
os.makedirs(output_dir, exist_ok=True)
|
89 |
+
audio_output_path = os.path.join(output_dir, f"speech_{uuid.uuid4().hex}.mp3")
|
90 |
with open(audio_output_path, "wb") as f:
|
91 |
f.write(audio_bytes)
|
92 |
except Exception as audio_err:
|
|
|
111 |
|
112 |
with gr.Blocks(css=custom_css) as demo:
|
113 |
gr.HTML(
|
114 |
+
'<div class="custom-bar"><span class="custom-bar-title">Language Tutor</span></div>'
|
115 |
)
|
116 |
with gr.Column(elem_classes="main-card"):
|
117 |
with gr.Row():
|
118 |
with gr.Column():
|
119 |
+
user_input = gr.Textbox(label="Type in whatever language you prefer", placeholder="Type here...", lines=4)
|
120 |
language_choice = gr.Dropdown(
|
121 |
choices=["Portuguese", "French", "Spanish"],
|
122 |
value="Portuguese",
|