Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -471,12 +471,15 @@ def create_heatmap(sensation_map, sensation_type):
|
|
471 |
plt.title(f'{["Pain", "Pleasure", "Pressure", "Temperature", "Texture", "EM Field", "Tickle", "Itch", "Quantum", "Neural", "Proprioception", "Synesthesia"][sensation_type]} Sensation Map')
|
472 |
plt.axis('off')
|
473 |
|
|
|
474 |
buf = io.BytesIO()
|
475 |
plt.savefig(buf, format='png')
|
476 |
buf.seek(0)
|
477 |
-
plt.close()
|
478 |
|
479 |
-
|
|
|
|
|
480 |
|
481 |
def generate_ai_response(keypoints, sensation_map):
|
482 |
num_keypoints = len(keypoints)
|
@@ -650,9 +653,12 @@ def create_avatar():
|
|
650 |
draw.line([start, end], fill=(0, 255, 255, 50), width=1)
|
651 |
|
652 |
return img
|
653 |
-
def create_avatar_with_heatmap(
|
654 |
-
#
|
655 |
-
avatar_img =
|
|
|
|
|
|
|
656 |
|
657 |
# Create a heatmap
|
658 |
heatmap_img = create_heatmap(sensation_map, sensation_type)
|
@@ -671,9 +677,10 @@ def create_avatar_with_heatmap(sensation_map, sensation_type):
|
|
671 |
combined_img = Image.alpha_composite(avatar_img.convert('RGBA'), heatmap_img.convert('RGBA'))
|
672 |
return combined_img
|
673 |
|
674 |
-
#
|
675 |
-
st.
|
676 |
-
|
|
|
677 |
|
678 |
|
679 |
|
@@ -718,6 +725,8 @@ with col2:
|
|
718 |
|
719 |
# Toggle synesthesia
|
720 |
use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
|
|
|
|
|
721 |
|
722 |
if canvas_result.json_data is not None:
|
723 |
objects = canvas_result.json_data["objects"]
|
|
|
471 |
plt.title(f'{["Pain", "Pleasure", "Pressure", "Temperature", "Texture", "EM Field", "Tickle", "Itch", "Quantum", "Neural", "Proprioception", "Synesthesia"][sensation_type]} Sensation Map')
|
472 |
plt.axis('off')
|
473 |
|
474 |
+
# Instead of displaying, save to a buffer
|
475 |
buf = io.BytesIO()
|
476 |
plt.savefig(buf, format='png')
|
477 |
buf.seek(0)
|
478 |
+
plt.close() # Close the figure to free up memory
|
479 |
|
480 |
+
# Create an image from the buffer
|
481 |
+
heatmap_img = Image.open(buf)
|
482 |
+
return heatmap_img
|
483 |
|
484 |
def generate_ai_response(keypoints, sensation_map):
|
485 |
num_keypoints = len(keypoints)
|
|
|
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, AVATAR_HEIGHT))
|
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)
|
|
|
677 |
combined_img = Image.alpha_composite(avatar_img.convert('RGBA'), heatmap_img.convert('RGBA'))
|
678 |
return combined_img
|
679 |
|
680 |
+
# Create and display avatar with optional heatmap
|
681 |
+
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 |
|
|
|
725 |
|
726 |
# Toggle synesthesia
|
727 |
use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
|
728 |
+
# Add this with your other UI elements
|
729 |
+
show_heatmap = st.checkbox("Show Sensation Heatmap", value=True)
|
730 |
|
731 |
if canvas_result.json_data is not None:
|
732 |
objects = canvas_result.json_data["objects"]
|