Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import networkx as nx
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# ---- Define 20 Steps ----
|
| 7 |
+
pipeline_steps = [
|
| 8 |
+
"ML Model File Loaded",
|
| 9 |
+
"ELT Data Set Loaded",
|
| 10 |
+
"Code Pushed to Repo",
|
| 11 |
+
"Pull Request Created",
|
| 12 |
+
"Unit Tests Executed",
|
| 13 |
+
"Integration Tests Executed",
|
| 14 |
+
"Data Validation",
|
| 15 |
+
"Security Scan",
|
| 16 |
+
"Environment Build",
|
| 17 |
+
"Artifact Stored",
|
| 18 |
+
"Model Training Pipeline Run",
|
| 19 |
+
"Model Validation (Accuracy, Recall)",
|
| 20 |
+
"Performance Test (Latency)",
|
| 21 |
+
"Bias & Ethics Check",
|
| 22 |
+
"Test Report Generated",
|
| 23 |
+
"Deploy to Staging",
|
| 24 |
+
"Shadow Deployment",
|
| 25 |
+
"Deploy to Production",
|
| 26 |
+
"Monitoring & Drift Detection",
|
| 27 |
+
"Feedback Loop & Retraining Trigger"
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# ---- Status for Demo ----
|
| 31 |
+
demo_status = [
|
| 32 |
+
"β
ML Model File (demo.py) loaded",
|
| 33 |
+
"β
ELT Data Set (sample.csv) loaded",
|
| 34 |
+
"β
Code pushed to GitHub",
|
| 35 |
+
"β
Pull request created & approved",
|
| 36 |
+
"β
Unit tests passed (12/12)",
|
| 37 |
+
"β
Integration tests passed",
|
| 38 |
+
"β
Data validation successful",
|
| 39 |
+
"β
Security scan passed",
|
| 40 |
+
"β
Environment build successful",
|
| 41 |
+
"β
Artifact stored in registry",
|
| 42 |
+
"β
Model trained (epoch=5)",
|
| 43 |
+
"β
Validation passed (Accuracy=92%)",
|
| 44 |
+
"β
Latency test passed (50ms avg)",
|
| 45 |
+
"β οΈ Bias check warning (dataset imbalance found)",
|
| 46 |
+
"β
Test report generated",
|
| 47 |
+
"β
Staging deployment successful",
|
| 48 |
+
"β
Shadow deployment running",
|
| 49 |
+
"β
Production deployment successful",
|
| 50 |
+
"β
Monitoring enabled (no drift detected)",
|
| 51 |
+
"π Feedback loop active β system ready"
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
# ---- Function to Simulate ----
|
| 55 |
+
def run_pipeline(code_input, dataset_input):
|
| 56 |
+
logs = []
|
| 57 |
+
|
| 58 |
+
# If no input, run demo
|
| 59 |
+
if not code_input:
|
| 60 |
+
code_input = "ML Model File: demo.py"
|
| 61 |
+
if not dataset_input:
|
| 62 |
+
dataset_input = "ELT Data Set: sample.csv"
|
| 63 |
+
|
| 64 |
+
logs.append(f"Pipeline started with {code_input} and {dataset_input}.\n")
|
| 65 |
+
|
| 66 |
+
# Simulate pipeline execution
|
| 67 |
+
for i, step in enumerate(pipeline_steps):
|
| 68 |
+
logs.append(f"Step {i+1}: {demo_status[i]}")
|
| 69 |
+
time.sleep(0.3) # simulate delay
|
| 70 |
+
|
| 71 |
+
# ---- Create Graph ----
|
| 72 |
+
G = nx.DiGraph()
|
| 73 |
+
for i, step in enumerate(pipeline_steps):
|
| 74 |
+
G.add_node(f"{i+1}")
|
| 75 |
+
if i > 0:
|
| 76 |
+
G.add_edge(f"{i}", f"{i+1}")
|
| 77 |
+
|
| 78 |
+
plt.figure(figsize=(12, 6))
|
| 79 |
+
pos = nx.spring_layout(G, seed=42)
|
| 80 |
+
nx.draw(G, pos, with_labels=True, node_size=1200, node_color="lightgreen", font_size=8, font_weight="bold")
|
| 81 |
+
nx.draw_networkx_labels(G, pos, labels={str(i+1): f"{i+1}" for i in range(len(pipeline_steps))})
|
| 82 |
+
|
| 83 |
+
plt.title("CI/CD/CT 20-Step Pipeline (Simulator)")
|
| 84 |
+
plt.tight_layout()
|
| 85 |
+
plt.savefig("pipeline.png")
|
| 86 |
+
plt.close()
|
| 87 |
+
|
| 88 |
+
return "pipeline.png", "\n".join(logs)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# ---- Gradio UI ----
|
| 92 |
+
with gr.Blocks() as demo:
|
| 93 |
+
gr.Markdown("# π CI/CD/CT Pipeline Simulator (Demo Version)")
|
| 94 |
+
gr.Markdown("This app simulates a **20-step CI/CD/CT pipeline**. Upload your own files or leave blank to run the prebuilt demo.")
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
code_input = gr.Textbox(label="Upload/Enter ML Model File", placeholder="Leave empty to use demo.py")
|
| 98 |
+
dataset_input = gr.Textbox(label="Upload/Enter ELT Data Set", placeholder="Leave empty to use sample.csv")
|
| 99 |
+
|
| 100 |
+
run_button = gr.Button("βΆοΈ Run 20-Step Pipeline")
|
| 101 |
+
|
| 102 |
+
with gr.Row():
|
| 103 |
+
graph_output = gr.Image(label="Pipeline Graph")
|
| 104 |
+
log_output = gr.Textbox(label="Pipeline Logs", lines=25)
|
| 105 |
+
|
| 106 |
+
run_button.click(run_pipeline, [code_input, dataset_input], [graph_output, log_output])
|
| 107 |
+
|
| 108 |
+
# Launch
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
demo.launch()
|