eaglelandsonce commited on
Commit
24455ca
·
verified ·
1 Parent(s): dd5aded

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -30
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 random
5
  import time
6
 
7
  st.set_page_config(layout="wide")
8
 
9
- # Specify the radius within which the dots should appear
10
- radius = 5
 
 
 
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
- # Number of dots is set to 4
19
- num_dots = 4
20
-
21
- # Initialize lists to hold agent names, tasks, and backstories. Limited to 4 agents.
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
- # Define colors for the dots
36
- colors = ['red', 'green', 'blue', 'purple']
37
 
38
  while True: # This loop will simulate real-time data updates
39
- # Create a list to hold the new data points
40
- new_data_points = []
41
 
42
- # Generate random x and y positions within the specified radius for 4 dots
43
- for i in range(num_dots):
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='color', title="Random Dots with Assigned Agents", color_discrete_sequence=colors)
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=[-radius, radius]),
60
- yaxis=dict(range=[-radius, radius]))
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)