Sephfox commited on
Commit
fec1916
·
verified ·
1 Parent(s): 06cdccc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -68
app.py CHANGED
@@ -482,6 +482,9 @@ def generate_ai_response(keypoints, sensation_map):
482
 
483
  ### Streamlit UI Logic ###
484
 
 
 
 
485
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
486
 
487
  if uploaded_file is not None:
@@ -508,17 +511,20 @@ if uploaded_file is not None:
508
  clicked_points = []
509
 
510
  def onclick(event):
 
511
  if event.xdata and event.ydata:
512
- clicked_points.append((int(event.xdata), int(event.ydata)))
513
- st.write(f"Clicked point: ({int(event.xdata)}, {int(event.ydata)})")
 
514
 
515
  # Display sensation values at the clicked point
516
- sensation = sensation_map[int(event.ydata), int(event.xdata)]
517
  st.write("### Sensory Data Analysis")
518
  st.write(f"Pain: {sensation[0]:.2f} | Pleasure: {sensation[1]:.2f} | Pressure: {sensation[2]:.2f}")
 
 
519
  st.write(f"Neural: {sensation[9]:.2f} | Proprioception: {sensation[10]:.2f} | Synesthesia: {sensation[11]:.2f}")
520
 
521
- # Connect the click event to the matplotlib figure
522
  fig.canvas.mpl_connect('button_press_event', onclick)
523
 
524
  # Display the plot in Streamlit
@@ -537,74 +543,21 @@ if uploaded_file is not None:
537
  response = generate_ai_response(keypoints, sensation_map)
538
  st.write("AI Response:", response)
539
 
540
- # Additional Neural Interface Controls for Interaction
541
- st.subheader("Neural Interface Controls")
542
-
543
- touch_duration = st.slider("Interaction Duration (s)", 0.1, 5.0, 1.0, 0.1)
544
- touch_pressure = st.slider("Interaction Intensity", 0.1, 2.0, 1.0, 0.1)
545
- use_quantum = st.checkbox("Enable Quantum Sensing", value=True)
546
- use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
547
- show_heatmap = st.checkbox("Show Sensation Heatmap", value=True)
548
-
549
- if st.button("Simulate Interaction"):
550
- if clicked_points:
551
- # Get the last clicked point
552
- touch_x, touch_y = clicked_points[-1]
553
-
554
- # Retrieve the sensation values at the clicked location
555
- sensation = sensation_map[touch_y, touch_x]
556
- (
557
- pain, pleasure, pressure_sens, temp_sens, texture_sens,
558
- em_sens, tickle_sens, itch_sens, quantum_sens, neural_sens,
559
- proprioception_sens, synesthesia_sens
560
- ) = sensation
561
-
562
- # Adjust the sensations based on user interaction settings
563
- measured_pressure = pressure_sens * touch_pressure
564
- measured_temp = temp_sens # Assuming temperature doesn't change during touch
565
- measured_texture = texture_sens # Assuming texture is constant
566
- measured_em = em_sens # Assuming electromagnetic field remains constant
567
-
568
- # Quantum sensation handling based on user selection
569
- if use_quantum:
570
- quantum_state = quantum_sens
571
- else:
572
- quantum_state = "N/A"
573
-
574
- # Calculate overall sensations with interaction modifiers
575
- pain_level = pain * measured_pressure * touch_pressure
576
- pleasure_level = pleasure * (measured_temp - 37) / 10 # Adjusted for average body temp
577
- tickle_level = tickle_sens * (1 - np.exp(-touch_duration / 0.5)) # Exponential decay
578
- itch_level = itch_sens * (1 - np.exp(-touch_duration / 1.5)) # Exponential decay
579
-
580
- # Proprioception (sense of body position) based on distance from the center
581
- proprioception = proprioception_sens * np.linalg.norm([touch_x - image_width / 2, touch_y - image_height / 2]) / (image_width / 2)
582
-
583
- # Synesthesia (mixing of senses) handling based on user selection
584
- if use_synesthesia:
585
- synesthesia = synesthesia_sens * (measured_pressure + measured_temp + measured_em) / 3
586
- else:
587
- synesthesia = "N/A"
588
-
589
- # Display simulated interaction results
590
- st.write("### Simulated Interaction Results")
591
- st.write(f"Interaction Point: ({touch_x:.1f}, {touch_y:.1f})")
592
- st.write(f"Duration: {touch_duration:.1f} s | Intensity: {touch_pressure:.2f}")
593
- st.write(f"Pain: {pain_level:.2f} | Pleasure: {pleasure_level:.2f} | Pressure: {measured_pressure:.2f}")
594
- st.write(f"Temperature: {measured_temp:.2f} | Texture: {measured_texture:.2f} | EM Field: {measured_em:.2f}")
595
- st.write(f"Tickle: {tickle_level:.2f} | Itch: {itch_level:.2f} | Quantum: {quantum_state}")
596
- st.write(f"Neural: {neural_sens:.2f} | Proprioception: {proprioception:.2f} | Synesthesia: {synesthesia}")
597
-
598
- # Optionally display heatmap of the sensations
599
- if show_heatmap:
600
- heatmap = create_heatmap(sensation_map, sensation_types.index("Pain")) # Example for "Pain"
601
- st.image(heatmap, use_column_width=True)
602
 
603
- # Optionally, calculate and display the average pressure value in the image
604
  average_pressure = np.mean(sensation_map[:, :, 2]) # Pressure channel
605
  st.write(f"Average Pressure across the image: {average_pressure:.2f}")
606
 
607
  # Create a futuristic data display
 
 
 
 
 
608
  data_display = (
609
  "```\n"
610
  "+---------------------------------------------+\n"
@@ -614,7 +567,7 @@ if uploaded_file is not None:
614
  f"| EM Field : {np.mean(sensation_map[:, :, 5]):.2f} μT".ljust(45) + "|\n"
615
  f"| Quantum State: {np.mean(sensation_map[:, :, 8]):.2f}".ljust(45) + "|\n"
616
  "+---------------------------------------------+\n"
617
- f"| Location: ({touch_x:.1f}, {touch_y:.1f})".ljust(45) + "|\n"
618
  f"| Pain Level : {np.mean(sensation_map[:, :, 0]):.2f}".ljust(45) + "|\n"
619
  f"| Pleasure : {np.mean(sensation_map[:, :, 1]):.2f}".ljust(45) + "|\n"
620
  f"| Tickle : {np.mean(sensation_map[:, :, 6]):.2f}".ljust(45) + "|\n"
@@ -629,6 +582,7 @@ if uploaded_file is not None:
629
  # Display the futuristic data display using Streamlit's code block feature
630
  st.code(data_display, language="")
631
 
 
632
  # Generate description
633
  prompt = (
634
  "Human: Analyze the sensory input for a hyper-advanced AI humanoid:\n"
 
482
 
483
  ### Streamlit UI Logic ###
484
 
485
+ # Initialize touch_x and touch_y with None or placeholder values
486
+ touch_x, touch_y = None, None
487
+
488
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
489
 
490
  if uploaded_file is not None:
 
511
  clicked_points = []
512
 
513
  def onclick(event):
514
+ nonlocal touch_x, touch_y # Ensure we update the outer variables
515
  if event.xdata and event.ydata:
516
+ touch_x, touch_y = int(event.xdata), int(event.ydata)
517
+ clicked_points.append((touch_x, touch_y))
518
+ st.write(f"Clicked point: ({touch_x}, {touch_y})")
519
 
520
  # Display sensation values at the clicked point
521
+ sensation = sensation_map[touch_y, touch_x]
522
  st.write("### Sensory Data Analysis")
523
  st.write(f"Pain: {sensation[0]:.2f} | Pleasure: {sensation[1]:.2f} | Pressure: {sensation[2]:.2f}")
524
+ st.write(f"Temperature: {sensation[3]:.2f} | Texture: {sensation[4]:.2f} | EM Field: {sensation[5]:.2f}")
525
+ st.write(f"Tickle: {sensation[6]:.2f} | Itch: {sensation[7]:.2f} | Quantum: {sensation[8]:.2f}")
526
  st.write(f"Neural: {sensation[9]:.2f} | Proprioception: {sensation[10]:.2f} | Synesthesia: {sensation[11]:.2f}")
527
 
 
528
  fig.canvas.mpl_connect('button_press_event', onclick)
529
 
530
  # Display the plot in Streamlit
 
543
  response = generate_ai_response(keypoints, sensation_map)
544
  st.write("AI Response:", response)
545
 
546
+ # Simulate interaction
547
+ if st.button("Simulate Interaction") and clicked_points:
548
+ touch_x, touch_y = clicked_points[-1]
549
+ # Interaction logic here...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
 
551
+ # Calculate average pressure across the image
552
  average_pressure = np.mean(sensation_map[:, :, 2]) # Pressure channel
553
  st.write(f"Average Pressure across the image: {average_pressure:.2f}")
554
 
555
  # Create a futuristic data display
556
+ if touch_x is not None and touch_y is not None:
557
+ location_str = f"({touch_x:.1f}, {touch_y:.1f})"
558
+ else:
559
+ location_str = "(no interaction yet)"
560
+
561
  data_display = (
562
  "```\n"
563
  "+---------------------------------------------+\n"
 
567
  f"| EM Field : {np.mean(sensation_map[:, :, 5]):.2f} μT".ljust(45) + "|\n"
568
  f"| Quantum State: {np.mean(sensation_map[:, :, 8]):.2f}".ljust(45) + "|\n"
569
  "+---------------------------------------------+\n"
570
+ f"| Location: {location_str}".ljust(45) + "|\n"
571
  f"| Pain Level : {np.mean(sensation_map[:, :, 0]):.2f}".ljust(45) + "|\n"
572
  f"| Pleasure : {np.mean(sensation_map[:, :, 1]):.2f}".ljust(45) + "|\n"
573
  f"| Tickle : {np.mean(sensation_map[:, :, 6]):.2f}".ljust(45) + "|\n"
 
582
  # Display the futuristic data display using Streamlit's code block feature
583
  st.code(data_display, language="")
584
 
585
+
586
  # Generate description
587
  prompt = (
588
  "Human: Analyze the sensory input for a hyper-advanced AI humanoid:\n"