Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,8 @@ import matplotlib.pyplot as plt
|
|
6 |
from PIL import Image, ImageDraw, ImageFont
|
7 |
import time
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
9 |
-
import
|
|
|
10 |
import base64
|
11 |
from streamlit_drawable_canvas import st_canvas
|
12 |
|
@@ -494,9 +495,26 @@ def create_avatar():
|
|
494 |
|
495 |
return img
|
496 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
498 |
|
499 |
-
|
|
|
|
|
|
|
|
|
|
|
500 |
|
501 |
|
502 |
|
@@ -514,18 +532,17 @@ col1, col2 = st.columns([2, 1])
|
|
514 |
with col1:
|
515 |
st.subheader("Humanoid Avatar Interface")
|
516 |
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
|
530 |
|
531 |
# Touch controls and output
|
@@ -544,13 +561,13 @@ with col2:
|
|
544 |
# Toggle synesthesia
|
545 |
use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
|
546 |
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
(
|
555 |
pain, pleasure, pressure_sens, temp_sens, texture_sens,
|
556 |
em_sens, tickle_sens, itch_sens, quantum_sens, neural_sens,
|
|
|
6 |
from PIL import Image, ImageDraw, ImageFont
|
7 |
import time
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
9 |
+
import seaborn as sns
|
10 |
+
from io import BytesIO
|
11 |
import base64
|
12 |
from streamlit_drawable_canvas import st_canvas
|
13 |
|
|
|
495 |
|
496 |
return img
|
497 |
|
498 |
+
# New function to create heatmap
|
499 |
+
def create_heatmap(sensation_map):
|
500 |
+
overall_sensitivity = np.mean(sensation_map, axis=2)
|
501 |
+
fig, ax = plt.subplots(figsize=(10, 15))
|
502 |
+
sns.heatmap(overall_sensitivity, cmap='YlOrRd', alpha=0.7, cbar=False, ax=ax)
|
503 |
+
ax.set_axis_off()
|
504 |
+
buf = BytesIO()
|
505 |
+
plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0)
|
506 |
+
buf.seek(0)
|
507 |
+
heatmap_img = Image.open(buf)
|
508 |
+
plt.close(fig)
|
509 |
+
return heatmap_img
|
510 |
|
511 |
|
512 |
+
def create_avatar_with_heatmap():
|
513 |
+
avatar_img = create_avatar()
|
514 |
+
heatmap_img = create_heatmap(avatar_sensation_map)
|
515 |
+
heatmap_img = heatmap_img.resize((AVATAR_WIDTH, AVATAR_HEIGHT))
|
516 |
+
combined_img = Image.alpha_composite(avatar_img.convert('RGBA'), heatmap_img.convert('RGBA'))
|
517 |
+
return combined_img
|
518 |
|
519 |
|
520 |
|
|
|
532 |
with col1:
|
533 |
st.subheader("Humanoid Avatar Interface")
|
534 |
|
535 |
+
# Use st_canvas for touch input
|
536 |
+
canvas_result = st_canvas(
|
537 |
+
fill_color="rgba(0, 255, 255, 0.3)",
|
538 |
+
stroke_width=2,
|
539 |
+
stroke_color="#00FFFF",
|
540 |
+
background_image=avatar_with_heatmap,
|
541 |
+
height=AVATAR_HEIGHT,
|
542 |
+
width=AVATAR_WIDTH,
|
543 |
+
drawing_mode="point",
|
544 |
+
key="canvas",
|
545 |
+
)
|
|
|
546 |
|
547 |
|
548 |
# Touch controls and output
|
|
|
561 |
# Toggle synesthesia
|
562 |
use_synesthesia = st.checkbox("Enable Synesthesia", value=False)
|
563 |
|
564 |
+
if canvas_result.json_data is not None:
|
565 |
+
objects = canvas_result.json_data["objects"]
|
566 |
+
if len(objects) > 0:
|
567 |
+
last_touch = objects[-1]
|
568 |
+
touch_x, touch_y = last_touch["left"], last_touch["top"]
|
569 |
+
|
570 |
+
sensation = avatar_sensation_map[int(touch_y), int(touch_x)]
|
571 |
(
|
572 |
pain, pleasure, pressure_sens, temp_sens, texture_sens,
|
573 |
em_sens, tickle_sens, itch_sens, quantum_sens, neural_sens,
|