File size: 14,327 Bytes
0611560
c5987cc
58b97f2
b91d93b
a750190
9aeacca
b91d93b
a8b2fd4
 
7eb3c25
7c1395e
 
 
a8b2fd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
01df617
 
 
 
 
 
 
 
 
a8b2fd4
 
0611560
6e1639c
a8b2fd4
0611560
9aeacca
 
 
d9be852
 
9aeacca
 
 
 
9782585
 
a750190
9782585
 
d9be852
9782585
a750190
9782585
 
d9be852
9782585
 
 
 
 
 
a750190
9782585
 
d9be852
9782585
a750190
9782585
50eabc7
a8b2fd4
9782585
a8b2fd4
9782585
 
 
d9be852
a750190
60e6faa
9782585
60e6faa
 
9782585
a8b2fd4
 
9782585
a8b2fd4
9782585
 
 
 
 
 
a8b2fd4
 
 
 
 
 
9782585
 
 
 
a8b2fd4
 
4f53727
60e6faa
 
9aeacca
0611560
8cb6cb7
7eb3c25
8cb6cb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7eb3c25
 
 
 
 
 
 
 
 
4f53727
7eb3c25
 
 
 
 
 
 
 
 
 
4f53727
7eb3c25
 
 
 
 
 
 
 
 
d9be852
7c1395e
 
 
 
 
 
 
 
6e1639c
a8b2fd4
9aeacca
b91d93b
 
 
7eb3c25
b91d93b
7eb3c25
b91d93b
7eb3c25
 
 
 
 
 
 
 
 
 
 
 
c190cf0
 
 
7eb3c25
 
 
 
 
 
f3de863
7eb3c25
a8b2fd4
 
 
 
 
7eb3c25
a8b2fd4
 
 
 
 
b91d93b
 
 
a8b2fd4
4f53727
b91d93b
a8b2fd4
4f53727
b91d93b
a8b2fd4
a750190
01df617
 
 
9782585
 
 
7eb3c25
f3de863
 
 
 
 
 
 
c190cf0
 
 
f3de863
 
 
 
 
 
 
a8b2fd4
f3de863
 
 
 
9782585
f3de863
 
 
 
a8b2fd4
 
 
 
 
 
9782585
 
c190cf0
9782585
 
 
 
 
 
 
 
 
 
a8b2fd4
f3de863
 
 
 
c190cf0
 
 
 
 
f3de863
c190cf0
 
 
 
 
 
 
f3de863
 
 
cf355c3
c190cf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image, ImageDraw, ImageFont
import time
from transformers import AutoModelForCausalLM, AutoTokenizer
import io
import base64
from streamlit_drawable_canvas import st_canvas
import plotly.graph_objects as go
import json
from datetime import datetime
import os

# Set page config for a futuristic look
st.set_page_config(page_title="NeuraSense AI", page_icon="🧠", layout="wide")

# Custom CSS for a futuristic look
st.markdown("""
<style>
    body {
        color: #E0E0E0;
        background-color: #0E1117;
    }
    .stApp {
        background-image: linear-gradient(135deg, #0E1117 0%, #1A1F2C 100%);
    }
    .stButton>button {
        color: #00FFFF;
        border-color: #00FFFF;
        border-radius: 20px;
    }
    .stSlider>div>div>div>div {
        background-color: #00FFFF;
    }
    .stTextArea, .stNumberInput, .stSelectbox {
        background-color: #1A1F2C;
        color: #00FFFF;
        border-color: #00FFFF;
        border-radius: 20px;
    }
    .stTextArea:focus, .stNumberInput:focus, .stSelectbox:focus {
        box-shadow: 0 0 10px #00FFFF;
    }
</style>
""", unsafe_allow_html=True)

# Constants
AVATAR_WIDTH, AVATAR_HEIGHT = 600, 800

# Set up DialoGPT model
@st.cache_resource
def load_model():
    tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
    model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
    return tokenizer, model

tokenizer, model = load_model()

# Advanced Sensor Classes
class QuantumSensor:
    @staticmethod
    def measure(x, y, sensitivity):
        return np.sin(x/20) * np.cos(y/20) * sensitivity * np.random.normal(1, 0.1)

class NanoThermalSensor:
    @staticmethod
    def measure(base_temp, pressure, duration):
        return base_temp + 10 * pressure * (1 - np.exp(-duration / 3)) + np.random.normal(0, 0.001)

class AdaptiveTextureSensor:
    textures = [
        "nano-smooth", "quantum-rough", "neuro-bumpy", "plasma-silky",
        "graviton-grainy", "zero-point-soft", "dark-matter-hard", "bose-einstein-condensate"
    ]
    
    @staticmethod
    def measure(x, y):
        return AdaptiveTextureSensor.textures[hash((x, y)) % len(AdaptiveTextureSensor.textures)]

class EMFieldSensor:
    @staticmethod
    def measure(x, y, sensitivity):
        return (np.sin(x / 30) * np.cos(y / 30) + np.random.normal(0, 0.1)) * 10 * sensitivity

class NeuralNetworkSimulator:
    @staticmethod
    def process(inputs):
        weights = np.random.rand(len(inputs))
        return np.dot(inputs, weights) / np.sum(weights)

# Create more detailed sensation map for the avatar
def create_sensation_map(width, height):
    sensation_map = np.zeros((height, width, 12))  # pain, pleasure, pressure, temp, texture, em, tickle, itch, quantum, neural, proprioception, synesthesia
    for y in range(height):
        for x in range(width):
            base_sensitivities = np.random.rand(12) * 0.5 + 0.5
            
            # Enhance certain areas
            if 250 < x < 350 and 50 < y < 150:  # Head
                base_sensitivities *= 1.5
            elif 275 < x < 325 and 80 < y < 120:  # Eyes
                base_sensitivities[0] *= 2  # More sensitive to pain
            elif 290 < x < 310 and 100 < y < 120:  # Nose
                base_sensitivities[4] *= 2  # More sensitive to texture
            elif 280 < x < 320 and 120 < y < 140:  # Mouth
                base_sensitivities[1] *= 2  # More sensitive to pleasure
            elif 250 < x < 350 and 250 < y < 550:  # Torso
                base_sensitivities[2:6] *= 1.3  # Enhance pressure, temp, texture, em
            elif (150 < x < 250 or 350 < x < 450) and 250 < y < 600:  # Arms
                base_sensitivities[0:2] *= 1.2  # Enhance pain and pleasure
            elif 200 < x < 400 and 600 < y < 800:  # Legs
                base_sensitivities[6:8] *= 1.4  # Enhance tickle and itch
            elif (140 < x < 160 or 440 < x < 460) and 390 < y < 410:  # Hands
                base_sensitivities *= 2  # Highly sensitive overall
            elif (220 < x < 240 or 360 < x < 380) and 770 < y < 790:  # Feet
                base_sensitivities[6] *= 2  # Very ticklish
            
            sensation_map[y, x] = base_sensitivities
    
    return sensation_map

avatar_sensation_map = create_sensation_map(AVATAR_WIDTH, AVATAR_HEIGHT)

# Create 3D humanoid avatar
def create_3d_avatar():
    # Head
    head_x = np.array([0, 0, 1, 1, 0, 0, 1, 1]) * 20 + 290
    head_y = np.array([0, 1, 1, 0, 0, 1, 1, 0]) * 40 + 50
    head_z = np.array([0, 0, 0, 0, 1, 1, 1, 1]) * 20 + 120
    
    # Torso
    torso_x = np.array([0, 0, 1, 1, 0, 0, 1, 1]) * 40 + 270
    torso_y = np.array([0, 1, 1, 0, 0, 1, 1, 0]) * 150 + 250
    torso_z = np.array([0, 0, 0, 0, 1, 1, 1, 1]) * 30 + 90
    
    # Arms
    arm_x = np.array([0, 0, 1, 1, 0, 0, 1, 1]) * 20 + 200
    arm_y = np.array([0, 1, 1, 0, 0, 1, 1, 0]) * 150 + 250
    arm_z = np.array([0, 0, 0, 0, 1, 1, 1, 1]) * 20 + 90
    
    # Legs
    leg_x = np.array([0, 0, 1, 1, 0, 0, 1, 1]) * 40 + 280
    leg_y = np.array([0, 1, 1, 0, 0, 1, 1, 0]) * 200 + 600
    leg_z = np.array([0, 0, 0, 0, 1, 1, 1, 1]) * 40 + 60
    
    # Combine all body parts
    x = np.concatenate([head_x, torso_x, arm_x, arm_x, leg_x, leg_x])
    y = np.concatenate([head_y, torso_y, arm_y, arm_y, leg_y, leg_y])
    z = np.concatenate([head_z, torso_z, arm_z, arm_z, leg_z, leg_z])
    
    return go.Mesh3d(x=x, y=y, z=z, color='cyan', opacity=0.5)

# Enhanced Autonomy Class
class EnhancedAutonomy:
    def __init__(self):
        self.mood = 0.5
        self.energy = 0.8
        self.curiosity = 0.7
        self.memory = []
    
    def update_state(self, sensory_input):
        self.mood = max(0, min(1, self.mood - sensory_input['pain'] * 0.1 + sensory_input['pleasure'] * 0.1))
        self.energy = max(0, min(1, self.energy - sensory_input['intensity'] * 0.05))
        if len(self.memory) == 0 or sensory_input not in self.memory:
            self.curiosity = min(1, self.curiosity + 0.1)
        else:
            self.curiosity = max(0, self.curiosity - 0.05)
        self.memory.append(sensory_input)
        if len(self.memory) > 10:
            self.memory.pop(0)
    
    def decide_action(self):
        if self.energy < 0.2:
            return "Rest to regain energy"
        elif self.curiosity > 0.8:
            return "Explore new sensations"
        elif self.mood < 0.3:
            return "Seek positive interactions"
        else:
            return "Continue current activity"

# Function to save interactions
def save_interaction(interaction_data):
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"interaction_{timestamp}.json"
    with open(filename, "w") as f:
        json.dump(interaction_data, f, indent=4)
    return filename

# Streamlit app
st.title("NeuraSense AI: Advanced Humanoid Techno-Sensory Simulation")

# Create two columns
col1, col2 = st.columns([2, 1])

# 3D Avatar display with touch interface
with col1:
    st.subheader("3D Humanoid Avatar Interface")
    
    # Create 3D avatar
    avatar_3d = create_3d_avatar()
    
    # Add 3D controls
    rotation_x = st.slider("Rotate X", -180, 180, 0)
    rotation_y = st.slider("Rotate Y", -180, 180, 0)
    rotation_z = st.slider("Rotate Z", -180, 180, 0)
    
    # Create 3D plot
    fig = go.Figure(data=[avatar_3d])
    fig.update_layout(scene=dict(xaxis_title="X", yaxis_title="Y", zaxis_title="Z"))
    fig.update_layout(scene_camera=dict(eye=dict(x=1.5, y=1.5, z=1.5)))
    fig.update_layout(scene=dict(xaxis=dict(range=[-400, 400]), 
                                 yaxis=dict(range=[-400, 400]), 
                                 zaxis=dict(range=[-200, 200])))
    
    # Apply rotations
    fig.update_layout(scene=dict(camera=dict(eye=dict(x=np.cos(np.radians(rotation_y)) * np.cos(np.radians(rotation_x)),
                                                      y=np.sin(np.radians(rotation_y)) * np.cos(np.radians(rotation_x)),
                                                      z=np.sin(np.radians(rotation_x))))))
    
    st.plotly_chart(fig, use_container_width=True)

    # Use st_canvas for touch input
    canvas_result = st_canvas(
        fill_color="rgba(0, 255, 255, 0.3)",
        stroke_width=2,
        stroke_color="#00FFFF",
        background_image=Image.new('RGBA', (AVATAR_WIDTH, AVATAR_HEIGHT), color=(0, 0, 0, 0)),
        height=AVATAR_HEIGHT,
        width=AVATAR_WIDTH,
        drawing_mode="point",
        key="canvas",
    )

# Touch controls and output
with col2:
    st.subheader("Neural Interface Controls")
    
    # Touch duration
    touch_duration = st.slider("Interaction Duration (s)", 0.1, 5.0, 1.0, 0.1)
    
    # Touch pressure
    touch_pressure = st.slider("Interaction Intensity", 0.1, 2.0, 1.0, 0.1)
    
    # Toggle quantum feature
    use_quantum = st.checkbox("Enable Quantum Sensing", value=True)
    
    # Toggle synesthesia
    use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
    
    # Initialize EnhancedAutonomy
    if 'autonomy' not in st.session_state:
        st.session_state.autonomy = EnhancedAutonomy()
    
    if canvas_result.json_data is not None:
        objects = canvas_result.json_data["objects"]
        if len(objects) > 0:
            last_touch = objects[-1]
            touch_x = last_touch["left"]
            touch_y = last_touch["top"]
            touch_z = 0  # Assuming the touch is on the surface of the avatar
            
            sensation = avatar_sensation_map[int(touch_y), int(touch_x)]
            (
                pain, pleasure, pressure_sens, temp_sens, texture_sens,
                em_sens, tickle_sens, itch_sens, quantum_sens, neural_sens,
                proprioception_sens, synesthesia_sens
            ) = sensation

            measured_pressure = QuantumSensor.measure(touch_x, touch_y, pressure_sens) * touch_pressure
            measured_temp = NanoThermalSensor.measure(37, touch_pressure, touch_duration)
            measured_texture = AdaptiveTextureSensor.measure(touch_x, touch_y)
            measured_em = EMFieldSensor.measure(touch_x, touch_y, em_sens)
            
            if use_quantum:
                quantum_state = QuantumSensor.measure(touch_x, touch_y, quantum_sens)
            else:
                quantum_state = "N/A"

            # Calculate overall sensations
            pain_level = pain * measured_pressure * touch_pressure
            pleasure_level = pleasure * (measured_temp - 37) / 10
            tickle_level = tickle_sens * (1 - np.exp(-touch_duration / 0.5))
            itch_level = itch_sens * (1 - np.exp(-touch_duration / 1.5))
            
            # Proprioception (sense of body position)
            proprioception = proprioception_sens * np.linalg.norm([touch_x - AVATAR_WIDTH/2, touch_y - AVATAR_HEIGHT/2, touch_z]) / (AVATAR_WIDTH/2)
            
            # Synesthesia (mixing of senses)
            if use_synesthesia:
                synesthesia = synesthesia_sens * (measured_pressure + measured_temp + measured_em) / 3
            else:
                synesthesia = "N/A"
            
            # Neural network simulation
            neural_inputs = [pain_level, pleasure_level, measured_pressure, measured_temp, measured_em, tickle_level, itch_level, proprioception]
            neural_response = NeuralNetworkSimulator.process(neural_inputs)

            # Create a futuristic data display
            data_display = f"""
            ```
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ Pressure     : {measured_pressure:.2f}      β”‚
            β”‚ Temperature  : {measured_temp:.2f}Β°C        β”‚
            β”‚ Texture      : {measured_texture}           β”‚
            β”‚ EM Field     : {measured_em:.2f} ΞΌT         β”‚
            β”‚ Quantum State: {quantum_state:.2f}          β”‚
            β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
            β”‚ Pain Level   : {pain_level:.2f}             β”‚
            β”‚ Pleasure     : {pleasure_level:.2f}         β”‚
            β”‚ Tickle       : {tickle_level:.2f}           β”‚
            β”‚ Itch         : {itch_level:.2f}             β”‚
            β”‚ Proprioception: {proprioception:.2f}        β”‚
            β”‚ Synesthesia  : {synesthesia}                β”‚
            β”‚ Neural Response: {neural_response:.2f}      β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            """
            st.code(data_display, language="")

            # Save interaction data
            if canvas_result.json_data is not None:
                objects = canvas_result.json_data["objects"]
                if len(objects) > 0:
                    interaction_data = {
                        "touch_x": touch_x,
                        "touch_y": touch_y,
                        "touch_z": touch_z,
                        "touch_duration": touch_duration,
                        "touch_pressure": touch_pressure,
                        "measured_pressure": measured_pressure,
                        "measured_temp": measured_temp,
                        "measured_texture": measured_texture,
                        "measured_em": measured_em,
                        "quantum_state": quantum_state,
                        "pain_level": pain_level,
                        "pleasure_level": pleasure_level,
                        "tickle_level": tickle_level,
                        "itch_level": itch_level,
                        "proprioception": proprioception,
                        "synesthesia": synesthesia,
                        "neural_response": neural_response
                    }
                    filename = save_interaction(interaction_data)
                    st.write(f"Interaction data saved to: {filename}")
                else:
                    st.write("No touch interaction detected.")
            else:
                st.write("No touch interaction detected.")