Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import time
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
|
5 |
+
# Set the page layout to wide mode
|
6 |
+
st.set_page_config(layout="wide")
|
7 |
+
|
8 |
+
# List of process stages and outcomes
|
9 |
+
stages = [
|
10 |
+
("Initiating Process (0-5 seconds)", "info"),
|
11 |
+
("Process Ongoing (5-10 seconds)", "success"),
|
12 |
+
("Midway Check (10-15 seconds)", "info"),
|
13 |
+
("Process Nearing Completion (15-20 seconds)", "warning"),
|
14 |
+
("Process Completed (20-25 seconds)", "success")
|
15 |
+
]
|
16 |
+
|
17 |
+
# Create interactive graph with progressive stages
|
18 |
+
def create_interactive_graph(show_until_stage):
|
19 |
+
fig = go.Figure()
|
20 |
+
|
21 |
+
# Data for the plot
|
22 |
+
process_steps = [1, 2, 3, 4, 5]
|
23 |
+
intensity = [1, 2, 3, 4, 5]
|
24 |
+
steps_text = [
|
25 |
+
"Initiating",
|
26 |
+
"Ongoing",
|
27 |
+
"Midway Check",
|
28 |
+
"Nearing Completion",
|
29 |
+
"Completed"
|
30 |
+
]
|
31 |
+
|
32 |
+
# Add bars for each stage up to show_until_stage
|
33 |
+
for i in range(show_until_stage):
|
34 |
+
fig.add_trace(go.Bar(
|
35 |
+
x=[process_steps[i]],
|
36 |
+
y=[intensity[i]],
|
37 |
+
name=f"Stage {i+1}: {steps_text[i]}",
|
38 |
+
marker_color=['blue', 'green', 'orange', 'yellow', 'red'][i]
|
39 |
+
))
|
40 |
+
|
41 |
+
# Update layout
|
42 |
+
fig.update_layout(
|
43 |
+
title="Process Stages vs Intensity",
|
44 |
+
xaxis_title="Process Steps",
|
45 |
+
yaxis_title="Intensity",
|
46 |
+
barmode='stack'
|
47 |
+
)
|
48 |
+
return fig
|
49 |
+
|
50 |
+
# Streamlit app
|
51 |
+
st.title("Process Stages Animation")
|
52 |
+
|
53 |
+
# Add a start animation button
|
54 |
+
start_button = st.button("Start Animation")
|
55 |
+
|
56 |
+
if start_button:
|
57 |
+
# Iterate through stages and corresponding outcomes
|
58 |
+
for i in range(len(stages)):
|
59 |
+
with st.container():
|
60 |
+
# Create two columns within each container
|
61 |
+
col1, col2 = st.columns([1, 2]) # Adjust column width ratio
|
62 |
+
|
63 |
+
with col1:
|
64 |
+
# Display stages with delays
|
65 |
+
stage, stage_type = stages[i]
|
66 |
+
if stage_type == "success":
|
67 |
+
st.success(f"Stage {i+1}: {stage}")
|
68 |
+
elif stage_type == "info":
|
69 |
+
st.info(f"Stage {i+1}: {stage}")
|
70 |
+
elif stage_type == "warning":
|
71 |
+
st.warning(f"Stage {i+1}: {stage}")
|
72 |
+
elif stage_type == "error":
|
73 |
+
st.error(f"Stage {i+1}: {stage}")
|
74 |
+
|
75 |
+
with col2:
|
76 |
+
# Update the graph in the second column
|
77 |
+
fig = create_interactive_graph(i + 1)
|
78 |
+
st.plotly_chart(fig, use_container_width=True)
|
79 |
+
|
80 |
+
# Add a delay between stages
|
81 |
+
time.sleep(5)
|
82 |
+
|
83 |
+
# Display final complete graph
|
84 |
+
with st.container():
|
85 |
+
st.write("**Complete Interactive Graph:**")
|
86 |
+
fig = create_interactive_graph(len(stages))
|
87 |
+
st.plotly_chart(fig, use_container_width=True)
|