begumbb commited on
Commit
55e3a29
·
verified ·
1 Parent(s): ccf27e3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +61 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from datasets import Dataset
5
+ from sklearn.ensemble import RandomForestClassifier
6
+ import torch
7
+ from diffusers import StableDiffusionPipeline
8
+
9
+ # --- 1. SİSTEM BAŞLATMA (Arka planda bir kere çalışır) ---
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)
14
+ df = pd.DataFrame(ozellikler)
15
+ df['durum'] = etiketler
16
+
17
+ hf_dataset = Dataset.from_pandas(df)
18
+ X = hf_dataset.to_pandas().iloc[:, :-1]
19
+ y = hf_dataset.to_pandas().iloc[:, -1]
20
+
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 = "Uyanık ve Odaklanmış (Gözler Açık)"
37
+ prompt = "A highly focused futuristic brain, glowing neon blue nodes, cyberpunk city background, ultra detailed, 8k"
38
+ else:
39
+ durum_adi = "Sakin ve Dinleniyor (Gözler Kapalı)"
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
+ # --- 3. GRADIO WEB ARAYÜZÜ (UI) ---
46
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
47
+ gr.Markdown("# 🧠 CognitiveDiffusion: Edge-Optimized Neuro-AI Pipeline")
48
+ gr.Markdown("Bu PoC, EEG beyin dalgalarını simüle ederek anlık bilişsel durumu sınıflandırır ve optimize edilmiş (pruned) bir difüzyon modeli ile bu durumu anında görselleştirir. **HubX AI Lab**'in edge optimizasyon vizyonundan ilham alınarak tasarlanmıştır.")
49
+
50
+ with gr.Row():
51
+ with gr.Column():
52
+ btn = gr.Button("🚀 Yeni EEG Sinyali Simüle Et ve Üret", variant="primary")
53
+ state_out = gr.Textbox(label="Algılanan Bilişsel Durum", lines=1)
54
+ prompt_out = gr.Textbox(label="Üretilen Yapay Zeka Promptu", lines=2)
55
+ with gr.Column():
56
+ image_out = gr.Image(label="Neuro-AI Çıktısı")
57
+
58
+ btn.click(fn=generate_neuro_image, inputs=[], outputs=[state_out, prompt_out, image_out])
59
+
60
+ # Uygulamayı başlat
61
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ datasets
4
+ scikit-learn
5
+ torch
6
+ diffusers
7
+ transformers
8
+ gradio
9
+ accelerate