Spaces:
Sleeping
Sleeping
Update app.py
Browse files1212345678910114 unmodified lines16171818192021229 unmodified lines3233343435363718 unmodified lines565758595960616162636364656667686968697071717273746 unmodified lines8182838484858687888989909192939494959697989899100101102102103104104105106107107108109# app.py - NeuroSense: MINIMAL & 100% WORKING β PLAY WORKS β FULL DURATION# Upload CSV β LOAD β PLAY β Emotion changes every second β Slider full length# 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 time
model = load_model("cnnGru_fydp.keras", compile=False)print("Model loaded!")4 unmodified lines "Normal": "#888888", "Sad": "#3366ff"}
# Global# Global stateemotions_list = []duration = 0
9 unmodified lines timestamps_sec = [t / 1000.0 for t in timestamps_ms] duration = int(timestamps_sec[-1]) + 1
# 1 emotion per second emotions_list = [] for sec in range(duration): idxs = [i for i, t in enumerate(timestamps_sec) if sec <= t < sec + 1]18 unmodified lines 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 {i}</small></div>", i ) gr.sleep(1) time.sleep(1) # REAL sleep, not gr.sleep
def update_from_slider(sec):def update_slider(sec): sec = int(sec) if not emotions_list or sec >= len(emotions_list): 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 ===with gr.Blocks(theme=gr.themes.Soft(), title="NeuroSense β FINAL") as demo:# === 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 β Emotion changes every 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 lines play_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) current_idx = gr.State(0)
load_btn.click( load_csv, inputs=csv_in, outputs=[emotion_box, status, slider, idx_state] outputs=[emotion_box, status, slider, current_idx] )
play_btn.click( play, outputs=[emotion_box, idx_state] outputs=[emotion_box, current_idx] )
slider.change( update_from_slider, update_slider, inputs=slider, outputs=emotion_box ).then( lambda x: x, lambda x: int(x), inputs=slider, outputs=idx_state outputs=current_idx )
print("LAUNCHING FINAL WORKING VERSION β PLAY WORKS β FULL DURATION")print("LAUNCHING FINAL 100% WORKING VERSION β PLAY WORKS β NO gr.sleep")demo.queue()demo.launch()app.py+17-17