Update app.py
Browse files
app.py
CHANGED
@@ -110,21 +110,17 @@ def process_audio(audio, state):
|
|
110 |
|
111 |
return gr.update(), state
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
audio_processor.stop()
|
117 |
-
state['is_running'] = False
|
118 |
-
return state
|
119 |
|
120 |
with gr.Blocks() as demo:
|
121 |
gr.Markdown("# Real-time Audio Emotion Detection")
|
122 |
gr.Markdown("Speak into your microphone. Emotions are detected in 3-second chunks.")
|
123 |
|
124 |
-
state = gr.State(
|
125 |
output = gr.Textbox(label="Detected Emotions (Last 5 chunks)", lines=2)
|
126 |
|
127 |
-
# Updated Audio component syntax for Gradio 4.39.0
|
128 |
audio_input = gr.Audio(
|
129 |
sources=["microphone"],
|
130 |
type="numpy",
|
@@ -139,9 +135,10 @@ with gr.Blocks() as demo:
|
|
139 |
outputs=[output, state],
|
140 |
show_progress=False
|
141 |
)
|
142 |
-
|
143 |
-
demo.load(lambda: None, None, state)
|
144 |
-
demo.close(cleanup, state, state)
|
145 |
|
146 |
-
# Launch with
|
147 |
-
demo.queue(max_size=10).launch(share=True)
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
return gr.update(), state
|
112 |
|
113 |
+
# Define event handler for cleanup
|
114 |
+
def on_close():
|
115 |
+
audio_processor.stop()
|
|
|
|
|
|
|
116 |
|
117 |
with gr.Blocks() as demo:
|
118 |
gr.Markdown("# Real-time Audio Emotion Detection")
|
119 |
gr.Markdown("Speak into your microphone. Emotions are detected in 3-second chunks.")
|
120 |
|
121 |
+
state = gr.State({'is_running': False})
|
122 |
output = gr.Textbox(label="Detected Emotions (Last 5 chunks)", lines=2)
|
123 |
|
|
|
124 |
audio_input = gr.Audio(
|
125 |
sources=["microphone"],
|
126 |
type="numpy",
|
|
|
135 |
outputs=[output, state],
|
136 |
show_progress=False
|
137 |
)
|
|
|
|
|
|
|
138 |
|
139 |
+
# Launch with cleanup handling
|
140 |
+
demo.queue(max_size=10).launch(share=True, prevent_thread_lock=True)
|
141 |
+
|
142 |
+
# Register cleanup
|
143 |
+
import atexit
|
144 |
+
atexit.register(on_close)
|