Sephfox commited on
Commit
d4637e4
·
verified ·
1 Parent(s): f0ba455

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -21
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 io
 
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
- avatar_image = create_avatar()
 
 
 
 
 
500
 
501
 
502
 
@@ -514,18 +532,17 @@ col1, col2 = st.columns([2, 1])
514
  with col1:
515
  st.subheader("Humanoid Avatar Interface")
516
 
517
- # Use st_canvas for touch input
518
- canvas_result = st_canvas(
519
- fill_color="rgba(0, 255, 255, 0.3)",
520
- stroke_width=2,
521
- stroke_color="#00FFFF",
522
- background_image=avatar_image,
523
- height=AVATAR_HEIGHT,
524
- width=AVATAR_WIDTH,
525
- drawing_mode="point",
526
- key="canvas",
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
- if canvas_result.json_data is not None:
548
- objects = canvas_result.json_data["objects"]
549
- if len(objects) > 0:
550
- last_touch = objects[-1]
551
- touch_x, touch_y = last_touch["left"], last_touch["top"]
552
-
553
- sensation = avatar_sensation_map[int(touch_y), int(touch_x)]
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,