Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,7 @@ from sklearn.ensemble import RandomForestClassifier
|
|
| 6 |
import torch
|
| 7 |
from diffusers import StableDiffusionPipeline
|
| 8 |
|
| 9 |
-
|
| 10 |
-
print("Model ve Veriler Hazırlanıyor...")
|
| 11 |
np.random.seed(42)
|
| 12 |
ozellikler = np.random.rand(200, 14) * 100
|
| 13 |
etiketler = np.random.choice([0, 1], 200)
|
|
@@ -21,41 +20,37 @@ y = hf_dataset.to_pandas().iloc[:, -1]
|
|
| 21 |
clf = RandomForestClassifier(n_estimators=50, random_state=42)
|
| 22 |
clf.fit(X, y)
|
| 23 |
|
| 24 |
-
# Budanmış (Pruned) modeli yüklüyoruz
|
| 25 |
pipe = StableDiffusionPipeline.from_pretrained("nota-ai/bk-sdm-tiny", torch_dtype=torch.float32)
|
| 26 |
if torch.cuda.is_available():
|
| 27 |
pipe = pipe.to("cuda")
|
| 28 |
|
| 29 |
-
# --- 2. ÜRETİM FONKSİYONU (Butona basıldığında çalışır) ---
|
| 30 |
def generate_neuro_image():
|
| 31 |
-
# 14 kanallı yeni bir beyin sinyali simülasyonu
|
| 32 |
yeni_sinyal = np.random.rand(1, 14) * 100
|
| 33 |
tahmin = clf.predict(yeni_sinyal)[0]
|
| 34 |
|
| 35 |
if tahmin == 0:
|
| 36 |
-
durum_adi = "
|
| 37 |
prompt = "A highly focused futuristic brain, glowing neon blue nodes, cyberpunk city background, ultra detailed, 8k"
|
| 38 |
else:
|
| 39 |
-
durum_adi = "
|
| 40 |
prompt = "A peaceful zen garden, glowing soft green tree, calm relaxing atmosphere, digital art, highly detailed"
|
| 41 |
|
| 42 |
image = pipe(prompt, num_inference_steps=20).images[0]
|
| 43 |
return durum_adi, prompt, image
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
with gr.Blocks(theme=gr.themes.
|
| 47 |
-
gr.Markdown("#
|
| 48 |
-
gr.Markdown("
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
with gr.Column():
|
| 52 |
-
btn = gr.Button("
|
| 53 |
-
state_out = gr.Textbox(label="
|
| 54 |
-
prompt_out = gr.Textbox(label="
|
| 55 |
with gr.Column():
|
| 56 |
-
image_out = gr.Image(label="Neuro-AI
|
| 57 |
|
| 58 |
btn.click(fn=generate_neuro_image, inputs=[], outputs=[state_out, prompt_out, image_out])
|
| 59 |
|
| 60 |
-
# Uygulamayı başlat
|
| 61 |
demo.launch()
|
|
|
|
| 6 |
import torch
|
| 7 |
from diffusers import StableDiffusionPipeline
|
| 8 |
|
| 9 |
+
print("System Initialization...")
|
|
|
|
| 10 |
np.random.seed(42)
|
| 11 |
ozellikler = np.random.rand(200, 14) * 100
|
| 12 |
etiketler = np.random.choice([0, 1], 200)
|
|
|
|
| 20 |
clf = RandomForestClassifier(n_estimators=50, random_state=42)
|
| 21 |
clf.fit(X, y)
|
| 22 |
|
|
|
|
| 23 |
pipe = StableDiffusionPipeline.from_pretrained("nota-ai/bk-sdm-tiny", torch_dtype=torch.float32)
|
| 24 |
if torch.cuda.is_available():
|
| 25 |
pipe = pipe.to("cuda")
|
| 26 |
|
|
|
|
| 27 |
def generate_neuro_image():
|
|
|
|
| 28 |
yeni_sinyal = np.random.rand(1, 14) * 100
|
| 29 |
tahmin = clf.predict(yeni_sinyal)[0]
|
| 30 |
|
| 31 |
if tahmin == 0:
|
| 32 |
+
durum_adi = "Awake & Focused (Eyes Open)"
|
| 33 |
prompt = "A highly focused futuristic brain, glowing neon blue nodes, cyberpunk city background, ultra detailed, 8k"
|
| 34 |
else:
|
| 35 |
+
durum_adi = "Calm & Resting (Eyes Closed)"
|
| 36 |
prompt = "A peaceful zen garden, glowing soft green tree, calm relaxing atmosphere, digital art, highly detailed"
|
| 37 |
|
| 38 |
image = pipe(prompt, num_inference_steps=20).images[0]
|
| 39 |
return durum_adi, prompt, image
|
| 40 |
|
| 41 |
+
# Minimalist ve Profesyonel UI (Monochrome Theme)
|
| 42 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 43 |
+
gr.Markdown("# CognitiveDiffusion: Edge-Optimized Neuro-AI Pipeline")
|
| 44 |
+
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.")
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
with gr.Column():
|
| 48 |
+
btn = gr.Button("Simulate EEG Signal & Generate Output", variant="primary")
|
| 49 |
+
state_out = gr.Textbox(label="Detected Cognitive State", lines=1)
|
| 50 |
+
prompt_out = gr.Textbox(label="Generated Gen-AI Prompt", lines=2)
|
| 51 |
with gr.Column():
|
| 52 |
+
image_out = gr.Image(label="Neuro-AI Output")
|
| 53 |
|
| 54 |
btn.click(fn=generate_neuro_image, inputs=[], outputs=[state_out, prompt_out, image_out])
|
| 55 |
|
|
|
|
| 56 |
demo.launch()
|