Spaces:
Sleeping
Sleeping
File size: 2,322 Bytes
55e3a29 af23aac 55e3a29 af23aac 55e3a29 af23aac 55e3a29 af23aac 55e3a29 af23aac 55e3a29 af23aac 55e3a29 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import gradio as gr
import pandas as pd
import numpy as np
from datasets import Dataset
from sklearn.ensemble import RandomForestClassifier
import torch
from diffusers import StableDiffusionPipeline
print("System Initialization...")
np.random.seed(42)
ozellikler = np.random.rand(200, 14) * 100
etiketler = np.random.choice([0, 1], 200)
df = pd.DataFrame(ozellikler)
df['durum'] = etiketler
hf_dataset = Dataset.from_pandas(df)
X = hf_dataset.to_pandas().iloc[:, :-1]
y = hf_dataset.to_pandas().iloc[:, -1]
clf = RandomForestClassifier(n_estimators=50, random_state=42)
clf.fit(X, y)
pipe = StableDiffusionPipeline.from_pretrained("nota-ai/bk-sdm-tiny", torch_dtype=torch.float32)
if torch.cuda.is_available():
pipe = pipe.to("cuda")
def generate_neuro_image():
yeni_sinyal = np.random.rand(1, 14) * 100
tahmin = clf.predict(yeni_sinyal)[0]
if tahmin == 0:
durum_adi = "Awake & Focused (Eyes Open)"
prompt = "A highly focused futuristic brain, glowing neon blue nodes, cyberpunk city background, ultra detailed, 8k"
else:
durum_adi = "Calm & Resting (Eyes Closed)"
prompt = "A peaceful zen garden, glowing soft green tree, calm relaxing atmosphere, digital art, highly detailed"
image = pipe(prompt, num_inference_steps=20).images[0]
return durum_adi, prompt, image
# Minimalist ve Profesyonel UI (Monochrome Theme)
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
gr.Markdown("# CognitiveDiffusion: Edge-Optimized Neuro-AI Pipeline")
gr.Markdown("This Proof of Concept simulates an active 14-channel EEG data stream, categorizes the real-time cognitive state using a lightweight classifier, and visually renders the state utilizing a pruned diffusion model (bk-sdm-tiny). Designed for resource-constrained edge environments.")
with gr.Row():
with gr.Column():
btn = gr.Button("Simulate EEG Signal & Generate Output", variant="primary")
state_out = gr.Textbox(label="Detected Cognitive State", lines=1)
prompt_out = gr.Textbox(label="Generated Gen-AI Prompt", lines=2)
with gr.Column():
image_out = gr.Image(label="Neuro-AI Output")
btn.click(fn=generate_neuro_image, inputs=[], outputs=[state_out, prompt_out, image_out])
demo.launch() |