Spaces:
Sleeping
Sleeping
File size: 2,607 Bytes
e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 5ebec48 e45c3f5 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
import streamlit as st
import asyncio
import threading
import random
import time
import psutil
import plotly.graph_objects as go
# Yoruba gods and their roles
gods = {
"Olorun": "Supreme Creator",
"Obatala": "God of Creation",
"Eshu": "Trickster God of Crossroads and Fate",
"Orunmila": "God of Wisdom and Divination",
"Ikú": "God of Death",
"Shango": "God of Thunder and Lightning",
"Oshun": "Goddess of Love, Beauty, and Fertility",
"Ogun": "God of Iron and War"
}
# Story of Olorun and Yoruba gods
story = """
...
"""
# Streamlit app
def main():
st.title("Yoruba Gods and Mythology")
st.write(story)
st.sidebar.title("Simulation")
timer_duration = st.sidebar.slider("Timer Duration (seconds)", min_value=1, max_value=60, value=60)
if st.sidebar.button("Start Simulation"):
simulate(timer_duration)
def simulate(duration):
start_time = time.time()
end_time = start_time + duration
agents = []
for i in range(8):
agent = threading.Thread(target=agent_function, args=(i,))
agents.append(agent)
agent.start()
while time.time() < end_time:
remaining_time = int(end_time - time.time())
st.write(f"⏰ Time Remaining: {remaining_time} seconds")
for i, agent in enumerate(agents):
if agent.is_alive():
st.write(f"Agent {i+1}: {agent.message}")
else:
st.write(f"Agent {i+1}: Idle")
update_process_metrics()
time.sleep(1)
for agent in agents:
agent.join()
st.success("Simulation completed.")
def agent_function(agent_id):
thread = threading.current_thread()
god_name = list(gods.keys())[agent_id]
role = gods[god_name]
thread.message = f"{god_name} - {role}"
asyncio.run(simulate_task(agent_id))
async def simulate_task(agent_id):
await asyncio.sleep(random.uniform(1, 5))
def update_process_metrics():
thread_count = threading.active_count()
cpu_percent = psutil.cpu_percent()
mem_percent = psutil.virtual_memory().percent
fig = go.Figure(
data=[
go.Bar(name="Thread Count", x=["Metrics"], y=[thread_count]),
go.Bar(name="CPU Usage (%)", x=["Metrics"], y=[cpu_percent]),
go.Bar(name="Memory Usage (%)", x=["Metrics"], y=[mem_percent])
],
layout=go.Layout(
title="Process Metrics",
xaxis=dict(title="Metrics"),
yaxis=dict(title="Value"),
barmode="group"
)
)
st.plotly_chart(fig)
if __name__ == "__main__":
main() |