Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,11 @@ import numpy as np
|
|
| 3 |
from typing import List, Tuple
|
| 4 |
from transformers import pipeline
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
-
from matplotlib.backends.backend_agg import
|
| 7 |
from streamlit_drawable_canvas import st_canvas
|
| 8 |
import time
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Constants
|
| 11 |
WIDTH, HEIGHT = 600, 600
|
|
@@ -63,13 +65,21 @@ fig, ax = plt.subplots(figsize=(6, 6))
|
|
| 63 |
ax.imshow(sensation_map, cmap='coolwarm', extent=[0, WIDTH, HEIGHT, 0])
|
| 64 |
ax.axis('off')
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# Use streamlit-drawable-canvas for interaction
|
| 67 |
canvas_result = st_canvas(
|
| 68 |
fill_color="rgba(255, 165, 0, 0.3)",
|
| 69 |
stroke_width=3,
|
| 70 |
stroke_color="#e00",
|
| 71 |
background_color="#eee",
|
| 72 |
-
background_image=
|
| 73 |
update_streamlit=True,
|
| 74 |
height=HEIGHT,
|
| 75 |
width=WIDTH,
|
|
|
|
| 3 |
from typing import List, Tuple
|
| 4 |
from transformers import pipeline
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
+
from matplotlib.backends.backend_agg import FigureCanvasAgg
|
| 7 |
from streamlit_drawable_canvas import st_canvas
|
| 8 |
import time
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import io
|
| 11 |
|
| 12 |
# Constants
|
| 13 |
WIDTH, HEIGHT = 600, 600
|
|
|
|
| 65 |
ax.imshow(sensation_map, cmap='coolwarm', extent=[0, WIDTH, HEIGHT, 0])
|
| 66 |
ax.axis('off')
|
| 67 |
|
| 68 |
+
# Convert matplotlib figure to Image
|
| 69 |
+
canvas = FigureCanvasAgg(fig)
|
| 70 |
+
canvas.draw()
|
| 71 |
+
buf = io.BytesIO()
|
| 72 |
+
plt.savefig(buf, format='png')
|
| 73 |
+
buf.seek(0)
|
| 74 |
+
img = Image.open(buf)
|
| 75 |
+
|
| 76 |
# Use streamlit-drawable-canvas for interaction
|
| 77 |
canvas_result = st_canvas(
|
| 78 |
fill_color="rgba(255, 165, 0, 0.3)",
|
| 79 |
stroke_width=3,
|
| 80 |
stroke_color="#e00",
|
| 81 |
background_color="#eee",
|
| 82 |
+
background_image=img,
|
| 83 |
update_streamlit=True,
|
| 84 |
height=HEIGHT,
|
| 85 |
width=WIDTH,
|