Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
import scipy.io.wavfile as wavfile
|
| 5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 6 |
+
import warnings
|
| 7 |
+
|
| 8 |
+
warnings.filterwarnings("ignore")
|
| 9 |
+
|
| 10 |
+
MODEL_ID = "Qwen/Qwen2.5-1.5B-Instruct"
|
| 11 |
+
|
| 12 |
+
# Загружаем мозг (используем bfloat16 для экономии памяти)
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 14 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
+
MODEL_ID,
|
| 16 |
+
device_map="cpu",
|
| 17 |
+
torch_dtype=torch.bfloat16
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def generate_neural_synth(prompt):
|
| 21 |
+
if not prompt:
|
| 22 |
+
return None
|
| 23 |
+
|
| 24 |
+
neural_activations = []
|
| 25 |
+
|
| 26 |
+
# Шпионский модуль
|
| 27 |
+
def steal_thoughts_hook(module, input, output):
|
| 28 |
+
current_thought = output[0].detach().cpu().to(torch.float32).numpy()
|
| 29 |
+
compressed_thought = np.mean(current_thought, axis=1)[0]
|
| 30 |
+
neural_activations.append(compressed_thought)
|
| 31 |
+
|
| 32 |
+
# Подключаемся к 15-му слою (центр абстрактного мышления)
|
| 33 |
+
hook_handle = model.model.layers[15].register_forward_hook(steal_thoughts_hook)
|
| 34 |
+
|
| 35 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 36 |
+
|
| 37 |
+
# Заставляем ИИ думать
|
| 38 |
+
with torch.no_grad():
|
| 39 |
+
model.generate(**inputs, max_new_tokens=60, do_sample=True, temperature=0.7)
|
| 40 |
+
|
| 41 |
+
hook_handle.remove()
|
| 42 |
+
|
| 43 |
+
# Аналоговый синтез
|
| 44 |
+
duration = 15.0
|
| 45 |
+
sample_rate = 44100
|
| 46 |
+
t = np.linspace(0, duration, int(sample_rate * duration), False)
|
| 47 |
+
audio_wave = np.zeros_like(t)
|
| 48 |
+
|
| 49 |
+
for i, thought_vector in enumerate(neural_activations):
|
| 50 |
+
# Превращаем мысль в частоту (Hz)
|
| 51 |
+
freq = 60 + (np.abs(np.mean(thought_vector)) * 1000) % 600
|
| 52 |
+
|
| 53 |
+
envelope = np.exp(-t * 1.5)
|
| 54 |
+
note = np.sin(2 * np.pi * freq * t) * envelope
|
| 55 |
+
|
| 56 |
+
shift = int((i / max(1, len(neural_activations))) * len(t) * 0.8)
|
| 57 |
+
|
| 58 |
+
if shift + len(note) > len(audio_wave):
|
| 59 |
+
note = note[:len(audio_wave) - shift]
|
| 60 |
+
audio_wave[shift:shift+len(note)] += note
|
| 61 |
+
|
| 62 |
+
audio_wave = audio_wave / np.max(np.abs(audio_wave))
|
| 63 |
+
audio_data = np.int16(audio_wave * 32767)
|
| 64 |
+
|
| 65 |
+
return (sample_rate, audio_data)
|
| 66 |
+
|
| 67 |
+
PROMO_TEXT = """
|
| 68 |
+
**Powered by Livadies. Listen to the music of the future:**
|
| 69 |
+
🟢 [Spotify](https://open.spotify.com/artist/0j8EmbhNFjiVhIJcZHdfUD) | 🔴 [YouTube](https://music.youtube.com/channel/UCe6BJsKd0uj1kAQcdHqyXQw) | 🟡 [Yandex](https://music.yandex.ru/artist/21918652)
|
| 70 |
+
🔥 Project Baseline: **«RUSSIAN WINTER 26»**
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
| 74 |
+
gr.Markdown("# 🎛️ NEURAL-ANALOG ENGINE V1")
|
| 75 |
+
gr.Markdown("Type a concept. The AI will think about it. We intercept its neural activations (Layer 15) in real-time and pipe them directly into a math-based analog oscillator. **You are hearing the AI's thought process.**")
|
| 76 |
+
|
| 77 |
+
with gr.Row():
|
| 78 |
+
with gr.Column():
|
| 79 |
+
input_text = gr.Textbox(label="Conceptual Prompt", placeholder="e.g., The silence of a frozen quantum star...")
|
| 80 |
+
run_btn = gr.Button("SYNTHESIZE NEURAL WAVES", variant="primary")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
out_audio = gr.Audio(label="Raw Brainwave Oscillation")
|
| 83 |
+
|
| 84 |
+
gr.Markdown(PROMO_TEXT)
|
| 85 |
+
run_btn.click(fn=generate_neural_synth, inputs=input_text, outputs=out_audio)
|
| 86 |
+
|
| 87 |
+
app.launch()
|