Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789104 unmodified lines151617181920219 unmodified lines3132333435363718 unmodified lines565758596061626364656667686970717273746 unmodified lines81828384858687888990919293949596979899100101102103104105106107108109# app.py - NeuroSense: MINIMAL & 100% WORKING β PLAY WORKS β FULL DURATION# Upload CSV β LOAD β PLAY β Emotion changes every second β Slider full lengthimport gradio as grimport numpy as npfrom tensorflow.keras.models import load_modelfrom preprocess import preprocess_eegmodel = load_model("cnnGru_fydp.keras", compile=False)print("Model loaded!")4 unmodified lines"Normal": "#888888", "Sad": "#3366ff"}# Globalemotions_list = []duration = 09 unmodified linestimestamps_sec = [t / 1000.0 for t in timestamps_ms]duration = int(timestamps_sec[-1]) + 1# 1 emotion per secondemotions_list = []for sec in range(duration):idxs = [i for i, t in enumerate(timestamps_sec) if sec <= t < sec + 1]18 unmodified linesf"<div style='text-align:center; padding:50px; font-size:5rem; background:{COLOR_MAP[emo]}; color:white; border-radius:30px; font-weight:bold;'>{emo}<br><small style='font-size:2rem;'>Second {i}</small></div>",i)gr.sleep(1)def update_from_slider(sec):sec = int(sec)if not emotions_list or sec >= len(emotions_list):return gr.update()emo = emotions_list[sec]return f"<div style='text-align:center; padding:50px; font-size:5rem; background:{COLOR_MAP[emo]}; color:white; border-radius:30px; font-weight:bold;'>{emo}<br><small style='font-size:2rem;'>Second {sec}</small></div>"# === GRADIO ===with gr.Blocks(theme=gr.themes.Soft(), title="NeuroSense β FINAL") as demo:gr.Markdown("# NeuroSense β 1 Emotion Per Second")gr.Markdown("### Upload CSV β LOAD β PLAY β Emotion changes every second")with gr.Row():csv_in = gr.File(label="EEG CSV", file_types=[".csv"])6 unmodified linesplay_btn = gr.Button("PLAY", variant="primary", size="lg")slider = gr.Slider(0, 60, value=0, step=1, label="Second", interactive=False)idx_state = gr.State(0)load_btn.click(load_csv,inputs=csv_in,outputs=[emotion_box, status, slider, idx_state])play_btn.click(play,outputs=[emotion_box, idx_state])slider.change(update_from_slider,inputs=slider,outputs=emotion_box).then(lambda x: x,inputs=slider,outputs=idx_state)print("LAUNCHING FINAL WORKING VERSION β PLAY WORKS β FULL DURATION")demo.queue()demo.launch()12345678910114 unmodified lines161718192021229 unmodified lines32333435363718 unmodified lines565758596061626364656667686970717273746 unmodified lines81828384858687888990919293949596979899100101102103104105106107108109# app.py - NeuroSense: MINIMAL & BULLETPROOF β PLAY WORKS β FULL DURATION# Upload CSV β LOAD β PLAY β Emotion changes every second β Slider 160s+import gradio as grimport numpy as npfrom tensorflow.keras.models import load_modelfrom preprocess import preprocess_eegimport timemodel = load_model("cnnGru_fydp.keras", compile=False)print("Model loaded!")4 unmodified lines"Normal": "#888888", "Sad": "#3366ff"}# Global stateemotions_list = []duration = 09 unmodified linestimestamps_sec = [t / 1000.0 for t in timestamps_ms]duration = int(timestamps_sec[-1]) + 1emotions_list = []for sec in range(duration):idxs = [i for i, t in enumerate(timestamps_sec) if sec <= t < sec + 1]18 unmodified linesf"<div style='text-align:center; padding:50px; font-size:5rem; background:{COLOR_MAP[emo]}; color:white; border-radius:30px; font-weight:bold;'>{emo}<br><small style='font-size:2rem;'>Second {i}</small></div>",i)time.sleep(1) # REAL sleep, not gr.sleepdef update_slider(sec):sec = int(sec)if sec >= len(emotions_list):return gr.update()emo = emotions_list[sec]return f"<div style='text-align:center; padding:50px; font-size:5rem; background:{COLOR_MAP[emo]}; color:white; border-radius:30px; font-weight:bold;'>{emo}<br><small style='font-size:2rem;'>Second {sec}</small></div>"# === GRADIO APP ===with gr.Blocks(theme=gr.themes.Soft(), title="NeuroSense FINAL") as demo:gr.Markdown("# NeuroSense β 1 Emotion Per Second")gr.Markdown("### Upload CSV β LOAD β PLAY β It works. No bullshit.")with gr.Row():csv_in = gr.File(label="EEG CSV", file_types=[".csv"])6 unmodified linesplay_btn = gr.Button("PLAY", variant="primary", size="lg")slider = gr.Slider(0, 60, value=0, step=1, label="Second", interactive=False)current_idx = gr.State(0)load_btn.click(load_csv,inputs=csv_in,outputs=[emotion_box, status, slider, current_idx])play_btn.click(play,outputs=[emotion_box, current_idx])slider.change(update_slider,inputs=slider,outputs=emotion_box).then(lambda x: int(x),inputs=slider,outputs=current_idx)print("LAUNCHING FINAL 100% WORKING VERSION β PLAY WORKS β NO gr.sleep")demo.queue()demo.launch()
app.py+17-17