Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
-
import
|
| 5 |
import time
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Create two columns in the Streamlit app
|
| 13 |
left_column, right_column = st.columns(2)
|
|
@@ -15,49 +18,36 @@ left_column, right_column = st.columns(2)
|
|
| 15 |
# In the left column, allow the user to input a common goal for all agents
|
| 16 |
common_goal = left_column.text_area("Common Goal for the Agents", "Enter a goal")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
agent_names = []
|
| 23 |
-
tasks = []
|
| 24 |
-
backstories = []
|
| 25 |
-
|
| 26 |
-
# Loop fixed to 4 for the four agents
|
| 27 |
-
for i in range(4):
|
| 28 |
-
agent_names.append(left_column.text_input(f"Agent {i+1} Name", key=f"name_{i}"))
|
| 29 |
-
tasks.append(left_column.text_input(f"Agent {i+1} Task", key=f"task_{i}"))
|
| 30 |
-
backstories.append(left_column.text_area(f"Agent {i+1} Backstory", key=f"backstory_{i}"))
|
| 31 |
|
| 32 |
# Placeholder for the Plotly chart in the right column
|
| 33 |
chart_placeholder = right_column.empty()
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
|
| 38 |
while True: # This loop will simulate real-time data updates
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
for
|
| 44 |
-
new_x = random.uniform(-radius, radius)
|
| 45 |
-
new_y = random.uniform(-radius, radius)
|
| 46 |
-
# Append the new data point as a dictionary to the list
|
| 47 |
-
new_data_points.append({'x': new_x, 'y': new_y, 'color': colors[i]})
|
| 48 |
|
| 49 |
# Create a new DataFrame from the list of new data points
|
| 50 |
new_data = pd.DataFrame(new_data_points)
|
| 51 |
|
| 52 |
-
# Create a new Plotly figure for the scatter plot
|
| 53 |
-
fig = px.scatter(new_data, x='x', y='y', color='
|
| 54 |
|
| 55 |
# Update the figure layout to better visualize the dots
|
| 56 |
fig.update_layout(xaxis_title='X Axis',
|
| 57 |
yaxis_title='Y Axis',
|
| 58 |
autosize=True,
|
| 59 |
-
xaxis=dict(range=[-
|
| 60 |
-
yaxis=dict(range=[-
|
| 61 |
|
| 62 |
# Update traces to adjust the appearance of the dots, setting radius to 10
|
| 63 |
fig.update_traces(marker=dict(size=20)) # Size adjusted for radius of 10
|
|
@@ -65,5 +55,8 @@ while True: # This loop will simulate real-time data updates
|
|
| 65 |
# Display the figure in the right column
|
| 66 |
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
# Pause for a moment before updating the chart with new dots
|
| 69 |
time.sleep(1)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
+
import json
|
| 5 |
import time
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
|
| 9 |
+
# Load the positions data
|
| 10 |
+
positions_df = pd.read_csv('./data/positions.csv')
|
| 11 |
+
|
| 12 |
+
# Preprocess the 'Positions' column to convert from string to dictionary
|
| 13 |
+
positions_df['Positions'] = positions_df['Positions'].apply(json.loads)
|
| 14 |
|
| 15 |
# Create two columns in the Streamlit app
|
| 16 |
left_column, right_column = st.columns(2)
|
|
|
|
| 18 |
# In the left column, allow the user to input a common goal for all agents
|
| 19 |
common_goal = left_column.text_area("Common Goal for the Agents", "Enter a goal")
|
| 20 |
|
| 21 |
+
# Initialize lists to hold agent names, tasks, and backstories from the dataframe
|
| 22 |
+
agent_names = list(positions_df['Agent'].unique())
|
| 23 |
+
tasks = list(positions_df['Task'].unique())
|
| 24 |
+
backstories = list(positions_df['Backstory'].unique())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Placeholder for the Plotly chart in the right column
|
| 27 |
chart_placeholder = right_column.empty()
|
| 28 |
|
| 29 |
+
# Index for accessing rows in positions_df, starting with the first row after the header
|
| 30 |
+
current_index = 0
|
| 31 |
|
| 32 |
while True: # This loop will simulate real-time data updates
|
| 33 |
+
# Fetch the current row's position data
|
| 34 |
+
current_positions = positions_df.iloc[current_index % len(positions_df)]['Positions']
|
| 35 |
|
| 36 |
+
# Convert current_positions into a list of dicts suitable for DataFrame creation
|
| 37 |
+
new_data_points = [{'Agent': agent, 'x': pos[0], 'y': pos[1]} for agent, pos in current_positions.items()]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Create a new DataFrame from the list of new data points
|
| 40 |
new_data = pd.DataFrame(new_data_points)
|
| 41 |
|
| 42 |
+
# Create a new Plotly figure for the scatter plot, using Agent names for colors
|
| 43 |
+
fig = px.scatter(new_data, x='x', y='y', color='Agent', title="Random Dots with Assigned Agents")
|
| 44 |
|
| 45 |
# Update the figure layout to better visualize the dots
|
| 46 |
fig.update_layout(xaxis_title='X Axis',
|
| 47 |
yaxis_title='Y Axis',
|
| 48 |
autosize=True,
|
| 49 |
+
xaxis=dict(range=[-5, 5]),
|
| 50 |
+
yaxis=dict(range=[-5, 5]))
|
| 51 |
|
| 52 |
# Update traces to adjust the appearance of the dots, setting radius to 10
|
| 53 |
fig.update_traces(marker=dict(size=20)) # Size adjusted for radius of 10
|
|
|
|
| 55 |
# Display the figure in the right column
|
| 56 |
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
| 57 |
|
| 58 |
+
# Increment the index to move to the next row for the next update
|
| 59 |
+
current_index += 1
|
| 60 |
+
|
| 61 |
# Pause for a moment before updating the chart with new dots
|
| 62 |
time.sleep(1)
|