File size: 2,474 Bytes
5cfb870
8fc1a61
 
24455ca
5c46e89
31bcc97
b1ec1ee
 
24455ca
a398248
24455ca
 
 
8b4d250
baa423c
 
75cadaa
8c4fb17
3da8b1b
8c4fb17
24455ca
 
 
 
baa423c
 
 
75cadaa
24455ca
 
dd5aded
5c46e89
24455ca
 
5c46e89
24455ca
 
ddaf69f
 
 
5c46e89
24455ca
 
5c46e89
 
 
 
 
24455ca
 
5c46e89
dd5aded
 
5cfb870
baa423c
5c46e89
5cfb870
24455ca
 
 
5c46e89
75cadaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
import pandas as pd
import plotly.express as px
import json
import time

st.set_page_config(layout="wide")

# Load the positions data
positions_df = pd.read_csv('data/positions.csv')

# Preprocess the 'Positions' column to convert from string to dictionary
positions_df['Positions'] = positions_df['Positions'].apply(json.loads)

# Create two columns in the Streamlit app
left_column, right_column = st.columns(2)

# In the left column, allow the user to input a common goal for all agents
common_goal = left_column.text_area("Common Goal for the Agents", "Enter a goal")

# Initialize lists to hold agent names, tasks, and backstories from the dataframe
agent_names = list(positions_df['Agent'].unique())
tasks = list(positions_df['Task'].unique())
backstories = list(positions_df['Backstory'].unique())

# Placeholder for the Plotly chart in the right column
chart_placeholder = right_column.empty()

# Index for accessing rows in positions_df, starting with the first row after the header
current_index = 0

while True:  # This loop will simulate real-time data updates
    # Fetch the current row's position data
    current_positions = positions_df.iloc[current_index % len(positions_df)]['Positions']
    
    # Convert current_positions into a list of dicts suitable for DataFrame creation
    new_data_points = [{'Agent': agent, 'x': pos[0], 'y': pos[1]} for agent, pos in current_positions.items()]
    
    # Create a new DataFrame from the list of new data points
    new_data = pd.DataFrame(new_data_points)
    
    # Create a new Plotly figure for the scatter plot, using Agent names for colors
    fig = px.scatter(new_data, x='x', y='y', color='Agent', title="Random Dots with Assigned Agents")
    
    # Update the figure layout to better visualize the dots
    fig.update_layout(xaxis_title='X Axis',
                      yaxis_title='Y Axis',
                      autosize=True,
                      xaxis=dict(range=[-5, 5]),
                      yaxis=dict(range=[-5, 5]))
    
    # Update traces to adjust the appearance of the dots, setting radius to 10
    fig.update_traces(marker=dict(size=20))  # Size adjusted for radius of 10

    # Display the figure in the right column
    chart_placeholder.plotly_chart(fig, use_container_width=True)

    # Increment the index to move to the next row for the next update
    current_index += 1

    # Pause for a moment before updating the chart with new dots
    time.sleep(1)