Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,27 @@ ELASTICITY = 0.3
|
|
15 |
DAMPING = 0.7
|
16 |
|
17 |
# Create sensation map
|
18 |
-
|
19 |
-
for
|
20 |
-
for
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Set up the Hugging Face pipeline
|
25 |
@st.cache_resource
|
@@ -36,21 +52,32 @@ touch_container = st.container()
|
|
36 |
|
37 |
def calculate_sensation(x, y, pressure, duration):
|
38 |
# Get sensation from the map
|
39 |
-
|
40 |
|
41 |
# Modify sensation based on pressure and duration
|
42 |
-
modified_sensation =
|
43 |
|
44 |
return modified_sensation
|
45 |
|
46 |
def on_touch(x, y, pressure, duration):
|
47 |
sensation = calculate_sensation(x, y, pressure, duration)
|
|
|
|
|
|
|
48 |
|
49 |
# Generate a description of the touch
|
50 |
st.write(f"Touch at ({x:.2f}, {y:.2f}) with pressure {pressure:.2f} for {duration:.2f} seconds")
|
51 |
-
st.write(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
prompt = f"The user touched the screen at ({x:.2f}, {y:.2f}) with a pressure of {pressure:.2f} for {duration:.2f} seconds, resulting in a sensation
|
54 |
text = text_generator(prompt, max_length=100, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=1)[0]['generated_text']
|
55 |
st.write(text)
|
56 |
|
@@ -62,7 +89,7 @@ if 'last_touch_position' not in st.session_state:
|
|
62 |
|
63 |
# Main app logic
|
64 |
fig, ax = plt.subplots(figsize=(6, 6))
|
65 |
-
ax.imshow(sensation_map
|
66 |
ax.axis('off')
|
67 |
|
68 |
# Convert matplotlib figure to Image
|
@@ -117,4 +144,4 @@ if canvas_result.json_data is not None:
|
|
117 |
st.session_state.last_touch_position = None
|
118 |
|
119 |
st.write("Click and drag on the image to simulate touch. The color represents different sensations.")
|
120 |
-
st.write("Red areas are
|
|
|
15 |
DAMPING = 0.7
|
16 |
|
17 |
# Create sensation map
|
18 |
+
def create_sensation_map(width, height):
|
19 |
+
sensation_map = np.zeros((height, width, 3)) # RGB channels for pain, pleasure, and neutral
|
20 |
+
for y in range(height):
|
21 |
+
for x in range(width):
|
22 |
+
# Base sensation
|
23 |
+
base = np.sin(x/30) * np.cos(y/30) * 0.5 + np.random.normal(0, 0.1)
|
24 |
+
|
25 |
+
# Pain regions (red channel)
|
26 |
+
pain = np.exp(-((x-150)**2 + (y-150)**2) / 5000) + np.exp(-((x-450)**2 + (y-450)**2) / 5000)
|
27 |
+
|
28 |
+
# Pleasure regions (green channel)
|
29 |
+
pleasure = np.exp(-((x-300)**2 + (y-300)**2) / 5000) + np.exp(-((x-150)**2 + (y-450)**2) / 5000)
|
30 |
+
|
31 |
+
# Neutral sensation (blue channel)
|
32 |
+
neutral = 1 - (pain + pleasure)
|
33 |
+
|
34 |
+
sensation_map[y, x] = [pain, pleasure, neutral]
|
35 |
+
|
36 |
+
return sensation_map
|
37 |
+
|
38 |
+
sensation_map = create_sensation_map(WIDTH, HEIGHT)
|
39 |
|
40 |
# Set up the Hugging Face pipeline
|
41 |
@st.cache_resource
|
|
|
52 |
|
53 |
def calculate_sensation(x, y, pressure, duration):
|
54 |
# Get sensation from the map
|
55 |
+
sensation = sensation_map[int(y), int(x)]
|
56 |
|
57 |
# Modify sensation based on pressure and duration
|
58 |
+
modified_sensation = sensation * pressure * (1 + np.log(duration + 1))
|
59 |
|
60 |
return modified_sensation
|
61 |
|
62 |
def on_touch(x, y, pressure, duration):
|
63 |
sensation = calculate_sensation(x, y, pressure, duration)
|
64 |
+
pain = sensation[0]
|
65 |
+
pleasure = sensation[1]
|
66 |
+
neutral = sensation[2]
|
67 |
|
68 |
# Generate a description of the touch
|
69 |
st.write(f"Touch at ({x:.2f}, {y:.2f}) with pressure {pressure:.2f} for {duration:.2f} seconds")
|
70 |
+
st.write(f"Pain: {pain:.2f}, Pleasure: {pleasure:.2f}, Neutral: {neutral:.2f}")
|
71 |
+
|
72 |
+
# Determine the dominant sensation
|
73 |
+
if pain > pleasure and pain > neutral:
|
74 |
+
dominant = "pain"
|
75 |
+
elif pleasure > pain and pleasure > neutral:
|
76 |
+
dominant = "pleasure"
|
77 |
+
else:
|
78 |
+
dominant = "neutral"
|
79 |
|
80 |
+
prompt = f"The user touched the screen at ({x:.2f}, {y:.2f}) with a pressure of {pressure:.2f} for {duration:.2f} seconds, resulting in a {dominant} sensation. Pain: {pain:.2f}, Pleasure: {pleasure:.2f}, Neutral: {neutral:.2f}. Describe the experience:"
|
81 |
text = text_generator(prompt, max_length=100, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=1)[0]['generated_text']
|
82 |
st.write(text)
|
83 |
|
|
|
89 |
|
90 |
# Main app logic
|
91 |
fig, ax = plt.subplots(figsize=(6, 6))
|
92 |
+
ax.imshow(sensation_map)
|
93 |
ax.axis('off')
|
94 |
|
95 |
# Convert matplotlib figure to Image
|
|
|
144 |
st.session_state.last_touch_position = None
|
145 |
|
146 |
st.write("Click and drag on the image to simulate touch. The color represents different sensations.")
|
147 |
+
st.write("Red areas are pain regions, green areas are pleasure regions, and blue areas are neutral.")
|