awacke1 commited on
Commit
5ebec48
โ€ข
1 Parent(s): e45c3f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -53
app.py CHANGED
@@ -2,8 +2,9 @@ import streamlit as st
2
  import asyncio
3
  import threading
4
  import random
5
- import matplotlib.pyplot as plt
6
- import numpy as np
 
7
 
8
  # Yoruba gods and their roles
9
  gods = {
@@ -19,23 +20,7 @@ gods = {
19
 
20
  # Story of Olorun and Yoruba gods
21
  story = """
22
- In the beginning, there was only Olorun, the supreme creator god, dwelling in the heavens above. ๐ŸŒค๏ธ Olorun, the almighty, decided to create the world and all that exists within it. He summoned Obatala, the god of creation, and tasked him with crafting the earth and all its inhabitants. ๐ŸŒ
23
-
24
- Obatala descended from the heavens, carrying a snail shell filled with sacred sand, a chameleon, and a pigeon. ๐Ÿš๐ŸฆŽ๐Ÿ•Š๏ธ As he reached the watery void below, Obatala released the sand, and the chameleon stepped upon it, spreading the grains far and wide. Thus, the earth was formed, and the pigeon flew across its expanse, bringing life and vitality to the land. ๐ŸŒฟ
25
-
26
- With the earth now created, Olorun sent down the other gods to populate and govern various aspects of the world. Among them was Eshu, the trickster god of crossroads and fate. ๐Ÿƒ Eshu, ever mischievous, would often play pranks on both mortals and gods alike, teaching valuable lessons through his cunning ways.
27
-
28
- Orunmila, the god of wisdom and divination, also descended to guide humanity with his prophetic insights. ๐Ÿ”ฎ He introduced the sacred divination system called Ifa, which allowed mortals to communicate with the gods and seek guidance in their lives.
29
-
30
- As the world flourished, Olorun watched from above, pleased with his creation. However, darkness crept in as Ikรบ, the god of death, began to claim the lives of mortals. ๐Ÿ’€ Olorun, in his infinite wisdom, knew that life and death were part of the natural cycle, and he allowed Ikรบ to maintain the balance.
31
-
32
- Shango, the god of thunder and lightning, ruled the skies with his mighty axe. โšก His tempestuous nature mirrored the powerful storms that swept across the land, and mortals both feared and revered him.
33
-
34
- Oshun, the goddess of love, beauty, and fertility, graced the earth with her presence. ๐Ÿ’› She brought joy, passion, and abundance to the lives of mortals, and her followers celebrated her with vibrant festivities and offerings.
35
-
36
- Throughout the ages, the Yoruba gods continued to shape the world and guide humanity. They taught valuable lessons, bestowed blessings, and occasionally unleashed their wrath upon those who transgressed against them. ๐ŸŒˆ
37
-
38
- The Yoruba mythology is a tapestry woven with tales of creation, destiny, and the eternal dance between the gods and mortals. These stories, passed down through generations, continue to inspire and teach the Yoruba people, reminding them of their rich heritage and the interconnectedness of all things in the cosmos. โœจ
39
  """
40
 
41
  # Streamlit app
@@ -43,51 +28,69 @@ def main():
43
  st.title("Yoruba Gods and Mythology")
44
  st.write(story)
45
 
46
- st.sidebar.title("Agents")
47
- agent_count = st.sidebar.slider("Number of Agents", min_value=1, max_value=8, value=8)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- if st.sidebar.button("Start Agents"):
50
- with st.spinner("Spawning agents..."):
51
- agents = []
52
- for i in range(agent_count):
53
- agent = threading.Thread(target=agent_function, args=(i,))
54
- agents.append(agent)
55
- agent.start()
56
 
57
- for agent in agents:
58
- agent.join()
59
 
60
- st.success("All agents have completed their tasks.")
 
61
 
62
- st.sidebar.title("Heartbeat Graph")
63
- if st.sidebar.button("Update Graph"):
64
- update_heartbeat_graph()
65
 
66
  def agent_function(agent_id):
 
67
  god_name = list(gods.keys())[agent_id]
68
  role = gods[god_name]
69
- st.write(f"Agent {agent_id+1}: {god_name} - {role}")
70
  asyncio.run(simulate_task(agent_id))
71
 
72
  async def simulate_task(agent_id):
73
- progress_bar = st.progress(0)
74
- for i in range(100):
75
- progress_bar.progress(i + 1)
76
- await asyncio.sleep(random.uniform(0.01, 0.1))
77
-
78
- def update_heartbeat_graph():
79
- active_threads = threading.active_count() - 1 # Subtract 1 for the main thread
80
- ip_addresses = [f"192.168.0.{i+1}" for i in range(active_threads)]
81
-
82
- fig, ax = plt.subplots()
83
- ax.bar(range(active_threads), [1] * active_threads, color='blue')
84
- ax.set_xlabel("User")
85
- ax.set_ylabel("Heartbeat")
86
- ax.set_title("Active Users")
87
- ax.set_xticks(range(active_threads))
88
- ax.set_xticklabels(ip_addresses)
89
-
90
- st.pyplot(fig)
 
 
 
 
91
 
92
  if __name__ == "__main__":
93
  main()
 
2
  import asyncio
3
  import threading
4
  import random
5
+ import time
6
+ import psutil
7
+ import plotly.graph_objects as go
8
 
9
  # Yoruba gods and their roles
10
  gods = {
 
20
 
21
  # Story of Olorun and Yoruba gods
22
  story = """
23
+ ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  """
25
 
26
  # Streamlit app
 
28
  st.title("Yoruba Gods and Mythology")
29
  st.write(story)
30
 
31
+ st.sidebar.title("Simulation")
32
+ timer_duration = st.sidebar.slider("Timer Duration (seconds)", min_value=1, max_value=60, value=60)
33
+ if st.sidebar.button("Start Simulation"):
34
+ simulate(timer_duration)
35
+
36
+ def simulate(duration):
37
+ start_time = time.time()
38
+ end_time = start_time + duration
39
+
40
+ agents = []
41
+ for i in range(8):
42
+ agent = threading.Thread(target=agent_function, args=(i,))
43
+ agents.append(agent)
44
+ agent.start()
45
+
46
+ while time.time() < end_time:
47
+ remaining_time = int(end_time - time.time())
48
+ st.write(f"โฐ Time Remaining: {remaining_time} seconds")
49
 
50
+ for i, agent in enumerate(agents):
51
+ if agent.is_alive():
52
+ st.write(f"Agent {i+1}: {agent.message}")
53
+ else:
54
+ st.write(f"Agent {i+1}: Idle")
 
 
55
 
56
+ update_process_metrics()
57
+ time.sleep(1)
58
 
59
+ for agent in agents:
60
+ agent.join()
61
 
62
+ st.success("Simulation completed.")
 
 
63
 
64
  def agent_function(agent_id):
65
+ thread = threading.current_thread()
66
  god_name = list(gods.keys())[agent_id]
67
  role = gods[god_name]
68
+ thread.message = f"{god_name} - {role}"
69
  asyncio.run(simulate_task(agent_id))
70
 
71
  async def simulate_task(agent_id):
72
+ await asyncio.sleep(random.uniform(1, 5))
73
+
74
+ def update_process_metrics():
75
+ thread_count = threading.active_count()
76
+ cpu_percent = psutil.cpu_percent()
77
+ mem_percent = psutil.virtual_memory().percent
78
+
79
+ fig = go.Figure(
80
+ data=[
81
+ go.Bar(name="Thread Count", x=["Metrics"], y=[thread_count]),
82
+ go.Bar(name="CPU Usage (%)", x=["Metrics"], y=[cpu_percent]),
83
+ go.Bar(name="Memory Usage (%)", x=["Metrics"], y=[mem_percent])
84
+ ],
85
+ layout=go.Layout(
86
+ title="Process Metrics",
87
+ xaxis=dict(title="Metrics"),
88
+ yaxis=dict(title="Value"),
89
+ barmode="group"
90
+ )
91
+ )
92
+
93
+ st.plotly_chart(fig)
94
 
95
  if __name__ == "__main__":
96
  main()