Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,10 +156,58 @@ if left_column.button('Pause' if not st.session_state['paused'] else 'Play'):
|
|
| 156 |
|
| 157 |
# Placeholder for the Plotly chart in the right column
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
|
|
|
| 161 |
chart_placeholder = right_column.empty()
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Placeholder for displaying the data below the animation
|
| 164 |
data_placeholder = right_column.empty()
|
| 165 |
|
|
@@ -198,4 +246,5 @@ while True:
|
|
| 198 |
current_frame += 1
|
| 199 |
|
| 200 |
# Pause for a moment before updating the chart with new positions
|
| 201 |
-
time.sleep(2)
|
|
|
|
|
|
| 156 |
|
| 157 |
# Placeholder for the Plotly chart in the right column
|
| 158 |
|
| 159 |
+
# Implement the pause/play functionality.
|
| 160 |
+
if left_column.button('Play' if st.session_state['paused'] else 'Pause'):
|
| 161 |
+
st.session_state['paused'] = not st.session_state['paused']
|
| 162 |
|
| 163 |
+
|
| 164 |
chart_placeholder = right_column.empty()
|
| 165 |
|
| 166 |
+
markdonw_position = right_column.markdown(f"```\n{positions_text}\n```")
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
# Placeholder for displaying additional data below the chart.
|
| 173 |
+
data_placeholder = right_column.empty()
|
| 174 |
+
|
| 175 |
+
# Function to update and display the plot based on the current frame.
|
| 176 |
+
def update_plot(frame_idx):
|
| 177 |
+
row = positions_df.iloc[frame_idx]
|
| 178 |
+
positions = row['positions']
|
| 179 |
+
data = [{'Agent': agent, 'x': pos[0], 'y': pos[1]} for agent, pos in positions.items()]
|
| 180 |
+
df = pd.DataFrame(data)
|
| 181 |
+
fig = px.scatter(df, x='x', y='y', color='Agent', title="Agent Positions", range_x=[-5,5], range_y=[-5,5])
|
| 182 |
+
fig.update_traces(marker=dict(size=20))
|
| 183 |
+
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
| 184 |
+
|
| 185 |
+
# Update data below the chart.
|
| 186 |
+
additional_data = f"**Agent Interaction:** {row['Agent']} says, \"{row['Dialog']}\""
|
| 187 |
+
st.session_state['interaction_log'] = st.session_state.get('interaction_log', '') + additional_data + "\n\n"
|
| 188 |
+
data_placeholder.markdown(st.session_state['interaction_log'])
|
| 189 |
+
|
| 190 |
+
# Initially display the plot.
|
| 191 |
+
update_plot(st.session_state['current_frame'])
|
| 192 |
+
|
| 193 |
+
# Periodic update if not paused.
|
| 194 |
+
while True:
|
| 195 |
+
if not st.session_state['paused']:
|
| 196 |
+
st.session_state['current_frame'] = (st.session_state['current_frame'] + 1) % len(positions_df)
|
| 197 |
+
update_plot(st.session_state['current_frame'])
|
| 198 |
+
time.sleep(2) # Adjust the sleep time as needed for your animation speed.
|
| 199 |
+
st.experimental_rerun()
|
| 200 |
+
|
| 201 |
+
time.sleep(0.1) # This short sleep prevents the loop from locking up the app
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
# Placeholder for displaying the data below the animation
|
| 212 |
data_placeholder = right_column.empty()
|
| 213 |
|
|
|
|
| 246 |
current_frame += 1
|
| 247 |
|
| 248 |
# Pause for a moment before updating the chart with new positions
|
| 249 |
+
time.sleep(2)
|
| 250 |
+
"""
|