Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import plotly.express as px | |
import random | |
import time | |
st.set_page_config(layout="wide") | |
# Specify the radius within which the dots should appear | |
radius = 5 | |
# 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") | |
# In the left column, allow the user to input the number of dots, agent names, tasks, and backstories | |
num_dots = left_column.number_input('Number of dots', min_value=1, max_value=10, value=5) | |
# Initialize lists to hold agent names, tasks, and backstories | |
agent_names = [] | |
tasks = [] | |
backstories = [] | |
# For each dot, get the agent name, task, and backstory | |
for i in range(num_dots): | |
agent_names.append(left_column.text_input(f"Agent {i+1} Name", key=f"name_{i}")) | |
tasks.append(left_column.text_input(f"Agent {i+1} Task", key=f"task_{i}")) | |
backstories.append(left_column.text_area(f"Agent {i+1} Backstory", key=f"backstory_{i}")) | |
# Placeholder for the Plotly chart in the right column | |
chart_placeholder = right_column.empty() | |
while True: # This loop will simulate real-time data updates | |
# Create a list to hold the new data points | |
new_data_points = [] | |
# Generate random x and y positions within the specified radius for the specified number of dots | |
for _ in range(num_dots): | |
new_x = random.uniform(-radius, radius) | |
new_y = random.uniform(-radius, radius) | |
# Append the new data point as a dictionary to the list | |
new_data_points.append({'x': new_x, 'y': new_y}) | |
# 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 | |
fig = px.scatter(new_data, x='x', y='y', 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=[-radius, radius]), | |
yaxis=dict(range=[-radius, radius])) | |
# Update traces to adjust the appearance of the dots | |
fig.update_traces(marker=dict(size=12)) # Adjust the size as needed | |
# Display the figure in the right column | |
chart_placeholder.plotly_chart(fig, use_container_width=True) | |
# Pause for a moment before updating the chart with new dots | |
time.sleep(1) | |