Sephfox commited on
Commit
a69e1fa
1 Parent(s): db61d73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -413,10 +413,10 @@ class NeuralNetworkSimulator:
413
  mp_pose = mp.solutions.pose
414
  pose = mp_pose.Pose(static_image_mode=True, min_detection_confidence=0.5)
415
 
416
- def detect_humanoid(image):
 
417
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
418
  results = pose.process(image_rgb)
419
-
420
  if results.pose_landmarks:
421
  landmarks = results.pose_landmarks.landmark
422
  image_height, image_width, _ = image.shape
@@ -428,7 +428,8 @@ def detect_humanoid(image):
428
  return keypoints
429
  return []
430
 
431
- def apply_touch_points(image, keypoints):
 
432
  draw = ImageDraw.Draw(image)
433
  for point in keypoints:
434
  draw.ellipse([point[0]-5, point[1]-5, point[0]+5, point[1]+5], fill='red')
@@ -653,18 +654,18 @@ def create_avatar():
653
  draw.line([start, end], fill=(0, 255, 255, 50), width=1)
654
 
655
  return img
656
- def create_avatar_with_heatmap(show_heatmap=True):
657
- # Load avatar image
658
- avatar_img = Image.open("avatar.png").resize((AVATAR_WIDTH, 600, AVATAR_HEIGHT,800))
659
 
660
  if not show_heatmap:
661
- return avatar_img # Return the avatar image without heatmap
662
 
663
  # Create a heatmap
664
- heatmap_img = create_heatmap(sensation_map, sensation_type)
665
 
666
  # Resize heatmap to match avatar size
667
- heatmap_img = heatmap_img.resize((AVATAR_WIDTH, AVATAR_HEIGHT))
668
 
669
  # Adjust alpha channel of heatmap
670
  data = np.array(heatmap_img)
@@ -682,7 +683,23 @@ st.subheader("Avatar with Optional Sensation Heatmap")
682
  avatar_with_heatmap = create_avatar_with_heatmap(show_heatmap)
683
  st.image(avatar_with_heatmap, use_column_width=True)
684
 
 
 
 
 
 
 
 
 
 
 
 
685
 
 
 
 
 
 
686
 
687
  # Create three columns
688
  col1, col2, col3 = st.columns(3)
@@ -843,11 +860,6 @@ st.write(response)
843
 
844
 
845
 
846
- import streamlit as st
847
- import matplotlib.pyplot as plt
848
- import numpy as np
849
- from PIL import Image
850
- import io
851
 
852
  # Constants
853
  AVATAR_WIDTH = 50 # Reduced size
 
413
  mp_pose = mp.solutions.pose
414
  pose = mp_pose.Pose(static_image_mode=True, min_detection_confidence=0.5)
415
 
416
+ def detect_humanoid(image_path):
417
+ image = imread(image_path)
418
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
419
  results = pose.process(image_rgb)
 
420
  if results.pose_landmarks:
421
  landmarks = results.pose_landmarks.landmark
422
  image_height, image_width, _ = image.shape
 
428
  return keypoints
429
  return []
430
 
431
+ def apply_touch_points(image_path, keypoints):
432
+ image = imread(image_path)
433
  draw = ImageDraw.Draw(image)
434
  for point in keypoints:
435
  draw.ellipse([point[0]-5, point[1]-5, point[0]+5, point[1]+5], fill='red')
 
654
  draw.line([start, end], fill=(0, 255, 255, 50), width=1)
655
 
656
  return img
657
+ def create_avatar_with_heatmap(image_path, show_heatmap=True):
658
+ # Load the image
659
+ avatar_img = Image.open(image_path)
660
 
661
  if not show_heatmap:
662
+ return avatar_img
663
 
664
  # Create a heatmap
665
+ heatmap_img = create_heatmap(sensation_map)
666
 
667
  # Resize heatmap to match avatar size
668
+ heatmap_img = heatmap_img.resize((image.width, image.height))
669
 
670
  # Adjust alpha channel of heatmap
671
  data = np.array(heatmap_img)
 
683
  avatar_with_heatmap = create_avatar_with_heatmap(show_heatmap)
684
  st.image(avatar_with_heatmap, use_column_width=True)
685
 
686
+ # Load the chosen humanoid image
687
+ image_path = 'chosen_avatar.jpg'
688
+ keypoints = detect_humanoid(image_path)
689
+ image_with_touch_points = apply_touch_points(image_path, keypoints)
690
+ heatmap_avatar = create_avatar_with_heatmap(image_path)
691
+
692
+ # Display the images
693
+ plt.figure(figsize=(15, 5))
694
+ plt.subplot(1, 3, 1)
695
+ plt.imshow(image_with_touch_points)
696
+ plt.title('Image with Touch Points')
697
 
698
+ plt.subplot(1, 3, 2)
699
+ plt.imshow(heatmap_avatar)
700
+ plt.title('Avatar with Heatmap')
701
+
702
+ plt.show()
703
 
704
  # Create three columns
705
  col1, col2, col3 = st.columns(3)
 
860
 
861
 
862
 
 
 
 
 
 
863
 
864
  # Constants
865
  AVATAR_WIDTH = 50 # Reduced size