Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from typing import List, Tuple
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
# Constants
|
6 |
WIDTH, HEIGHT = 600, 600
|
@@ -15,7 +16,11 @@ 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 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Streamlit app
|
21 |
st.title("Artificial Touch Simulation")
|
@@ -56,27 +61,33 @@ def on_tap(x, y):
|
|
56 |
is_affected[i] = True
|
57 |
|
58 |
# Generate a description of the touch
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
st.write(text)
|
63 |
|
64 |
update_points()
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from typing import List, Tuple
|
3 |
from transformers import pipeline
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
|
6 |
# Constants
|
7 |
WIDTH, HEIGHT = 600, 600
|
|
|
16 |
is_affected: List[bool] = [False] * len(touch_points)
|
17 |
|
18 |
# Set up the Hugging Face pipeline
|
19 |
+
@st.cache_resource
|
20 |
+
def load_model():
|
21 |
+
return pipeline('text-generation', model='gpt2')
|
22 |
+
|
23 |
+
text_generator = load_model()
|
24 |
|
25 |
# Streamlit app
|
26 |
st.title("Artificial Touch Simulation")
|
|
|
61 |
is_affected[i] = True
|
62 |
|
63 |
# Generate a description of the touch
|
64 |
+
st.write(f"Touch at ({x:.2f}, {y:.2f})")
|
65 |
+
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']
|
66 |
+
st.write(text)
|
|
|
67 |
|
68 |
update_points()
|
69 |
|
70 |
+
# Initialize session state
|
71 |
+
if 'x' not in st.session_state:
|
72 |
+
st.session_state.x = 0
|
73 |
+
if 'y' not in st.session_state:
|
74 |
+
st.session_state.y = 0
|
75 |
+
|
76 |
+
# Main app logic
|
77 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
78 |
+
ax.set_xlim(0, WIDTH)
|
79 |
+
ax.set_ylim(0, HEIGHT)
|
80 |
+
|
81 |
+
for i, (x, y) in enumerate(touch_points):
|
82 |
+
color = "red" if is_affected[i] else "navy"
|
83 |
+
ax.add_artist(plt.Circle((x, y), 5, color=color, alpha=0.5))
|
84 |
+
|
85 |
+
touch_container.pyplot(fig)
|
86 |
+
|
87 |
+
if touch_container.button("Tap the screen"):
|
88 |
+
on_tap(st.session_state.x, st.session_state.y)
|
89 |
+
|
90 |
+
st.session_state.x = st.slider("X coordinate", 0, WIDTH, st.session_state.x)
|
91 |
+
st.session_state.y = st.slider("Y coordinate", 0, HEIGHT, st.session_state.y)
|
92 |
+
|
93 |
+
update_points()
|