Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from typing import List, Tuple
|
3 |
-
from
|
4 |
-
from bokeh.models import ColumnDataSource
|
5 |
-
from bokeh.events import Tap
|
6 |
|
7 |
# Constants
|
8 |
WIDTH, HEIGHT = 600, 600
|
@@ -16,17 +14,14 @@ original_points = touch_points.copy()
|
|
16 |
velocities: List[Tuple[float, float]] = [(0.0, 0.0)] * len(touch_points)
|
17 |
is_affected: List[bool] = [False] * len(touch_points)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
# Set up the Bokeh plot
|
22 |
-
p = figure(width=WIDTH, height=HEIGHT, tools="", toolbar_location=None)
|
23 |
-
p.circle('x', 'y', size=5, color="navy", alpha=0.5, source=source)
|
24 |
|
25 |
# Streamlit app
|
26 |
st.title("Artificial Touch Simulation")
|
27 |
|
28 |
-
# Create a Streamlit container for the
|
29 |
-
|
30 |
|
31 |
def update_points():
|
32 |
global touch_points, velocities, is_affected
|
@@ -48,14 +43,10 @@ def update_points():
|
|
48 |
|
49 |
# Reset affected flags
|
50 |
is_affected = [False] * len(touch_points)
|
51 |
-
|
52 |
-
# Update Bokeh data source
|
53 |
-
source.data = dict(x=[x for x, y in touch_points], y=[y for x, y in touch_points])
|
54 |
|
55 |
-
def on_tap(
|
56 |
global touch_points, velocities, is_affected
|
57 |
|
58 |
-
x, y = event.x, event.y
|
59 |
for i, (tx, ty) in enumerate(touch_points):
|
60 |
distance = ((tx - x)**2 + (ty - y)**2)**0.5
|
61 |
if distance < 30:
|
@@ -64,12 +55,28 @@ def on_tap(event):
|
|
64 |
velocities[i] = (velocities[i][0] - force_x * 10, velocities[i][1] - force_y * 10)
|
65 |
is_affected[i] = True
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
update_points()
|
69 |
|
70 |
-
p.on_event(Tap, on_tap)
|
71 |
-
|
72 |
while True:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
update_points()
|
74 |
-
chart.bokeh_chart(p)
|
75 |
st.experimental_rerun()
|
|
|
1 |
import streamlit as st
|
2 |
from typing import List, Tuple
|
3 |
+
from transformers import pipeline
|
|
|
|
|
4 |
|
5 |
# Constants
|
6 |
WIDTH, HEIGHT = 600, 600
|
|
|
14 |
velocities: List[Tuple[float, float]] = [(0.0, 0.0)] * len(touch_points)
|
15 |
is_affected: List[bool] = [False] * len(touch_points)
|
16 |
|
17 |
+
# Set up the Hugging Face pipeline
|
18 |
+
text_generator = pipeline('text-generation', model='gpt2')
|
|
|
|
|
|
|
19 |
|
20 |
# Streamlit app
|
21 |
st.title("Artificial Touch Simulation")
|
22 |
|
23 |
+
# Create a Streamlit container for the touch simulation
|
24 |
+
touch_container = st.container()
|
25 |
|
26 |
def update_points():
|
27 |
global touch_points, velocities, is_affected
|
|
|
43 |
|
44 |
# Reset affected flags
|
45 |
is_affected = [False] * len(touch_points)
|
|
|
|
|
|
|
46 |
|
47 |
+
def on_tap(x, y):
|
48 |
global touch_points, velocities, is_affected
|
49 |
|
|
|
50 |
for i, (tx, ty) in enumerate(touch_points):
|
51 |
distance = ((tx - x)**2 + (ty - y)**2)**0.5
|
52 |
if distance < 30:
|
|
|
55 |
velocities[i] = (velocities[i][0] - force_x * 10, velocities[i][1] - force_y * 10)
|
56 |
is_affected[i] = True
|
57 |
|
58 |
+
# Generate a description of the touch
|
59 |
+
with touch_container:
|
60 |
+
st.write(f"Touch at ({x:.2f}, {y:.2f})")
|
61 |
+
text = text_generator(f"The user touched the screen at ({x:.2f}, {y:.2f}).", max_length=100, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=1)[0]['generated_text']
|
62 |
+
st.write(text)
|
63 |
+
|
64 |
update_points()
|
65 |
|
|
|
|
|
66 |
while True:
|
67 |
+
with touch_container:
|
68 |
+
for i, (x, y) in enumerate(touch_points):
|
69 |
+
if is_affected[i]:
|
70 |
+
st.circle((x, y), 5, color="red", fill_opacity=0.5)
|
71 |
+
else:
|
72 |
+
st.circle((x, y), 5, color="navy", fill_opacity=0.5)
|
73 |
+
|
74 |
+
if st.button("Tap the screen"):
|
75 |
+
on_tap(st.session_state.get('x', 0), st.session_state.get('y', 0))
|
76 |
+
|
77 |
+
st.experimental_set_query_params(x=touch_points[0][0], y=touch_points[0][1])
|
78 |
+
st.session_state['x'] = st.experimental_get_query_params().get('x', [0])[0]
|
79 |
+
st.session_state['y'] = st.experimental_get_query_params().get('y', [0])[0]
|
80 |
+
|
81 |
update_points()
|
|
|
82 |
st.experimental_rerun()
|