Sephfox commited on
Commit
3eb256b
·
verified ·
1 Parent(s): 1673ea6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -340,17 +340,29 @@ AVATAR_WIDTH = 600
340
  AVATAR_HEIGHT = 800
341
 
342
 
343
- # Create heatmap function
 
 
344
  overall_sensitivity = np.mean(sensation_map, axis=2)
 
 
345
  fig, ax = plt.subplots(figsize=(10, 15))
 
 
346
  sns.heatmap(overall_sensitivity, cmap='YlOrRd', alpha=0.7, cbar=False, ax=ax)
 
 
347
  ax.set_axis_off()
 
 
348
  buf = BytesIO()
349
  plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0)
350
  buf.seek(0)
351
  heatmap_img = Image.open(buf)
 
352
  plt.close(fig)
353
-
 
354
  # Your Streamlit app code goes here
355
  st.title("NeuraSense AI - Cyberpunk Edition")
356
 
@@ -507,7 +519,14 @@ def create_avatar_with_heatmap():
507
  avatar_img = create_avatar()
508
  heatmap_img = create_heatmap(avatar_sensation_map)
509
  heatmap_img = heatmap_img.resize((AVATAR_WIDTH, AVATAR_HEIGHT))
510
- combined_img = Image.alpha_composite(avatar_img.convert('RGBA'), heatmap_img.convert('RGBA'))
 
 
 
 
 
 
 
511
  return combined_img
512
 
513
  # Create the avatar with heatmap
 
340
  AVATAR_HEIGHT = 800
341
 
342
 
343
+
344
+ def create_heatmap(sensation_map):
345
+ # Calculate the overall sensitivity by taking the mean across all sensations
346
  overall_sensitivity = np.mean(sensation_map, axis=2)
347
+
348
+ # Create a figure and axis
349
  fig, ax = plt.subplots(figsize=(10, 15))
350
+
351
+ # Generate the heatmap
352
  sns.heatmap(overall_sensitivity, cmap='YlOrRd', alpha=0.7, cbar=False, ax=ax)
353
+
354
+ # Remove axes and labels
355
  ax.set_axis_off()
356
+
357
+ # Convert the plot to an image
358
  buf = BytesIO()
359
  plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0)
360
  buf.seek(0)
361
  heatmap_img = Image.open(buf)
362
+
363
  plt.close(fig)
364
+
365
+ return heatmap_img
366
  # Your Streamlit app code goes here
367
  st.title("NeuraSense AI - Cyberpunk Edition")
368
 
 
519
  avatar_img = create_avatar()
520
  heatmap_img = create_heatmap(avatar_sensation_map)
521
  heatmap_img = heatmap_img.resize((AVATAR_WIDTH, AVATAR_HEIGHT))
522
+ heatmap_img = heatmap_img.convert('RGBA')
523
+
524
+ # Adjust alpha channel of heatmap
525
+ data = np.array(heatmap_img)
526
+ data[:, :, 3] = data[:, :, 3] * 0.5 # Reduce opacity to 50%
527
+ heatmap_img = Image.fromarray(data)
528
+
529
+ combined_img = Image.alpha_composite(avatar_img.convert('RGBA'), heatmap_img)
530
  return combined_img
531
 
532
  # Create the avatar with heatmap