Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import graphviz
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
# Function to create a process flow diagram
|
| 6 |
+
def create_flow_diagram(process_name):
|
| 7 |
+
diagram = graphviz.Digraph(format="png")
|
| 8 |
+
diagram.attr(rankdir="LR")
|
| 9 |
+
|
| 10 |
+
# Example of a simple flow
|
| 11 |
+
diagram.node("Start", "Start")
|
| 12 |
+
diagram.node("Process", process_name)
|
| 13 |
+
diagram.node("End", "End")
|
| 14 |
+
|
| 15 |
+
# Add edges
|
| 16 |
+
diagram.edge("Start", "Process")
|
| 17 |
+
diagram.edge("Process", "End")
|
| 18 |
+
|
| 19 |
+
return diagram
|
| 20 |
+
|
| 21 |
+
# Function to generate explanation
|
| 22 |
+
def generate_explanation(process_name):
|
| 23 |
+
explanation = (
|
| 24 |
+
f"The process named '{process_name}' begins with the initiation phase (Start), "
|
| 25 |
+
f"then transitions through the core processing stage (Process), "
|
| 26 |
+
f"and finally concludes in the termination phase (End). This flow ensures clarity and simplicity in execution."
|
| 27 |
+
)
|
| 28 |
+
return explanation
|
| 29 |
+
|
| 30 |
+
# Streamlit App
|
| 31 |
+
def main():
|
| 32 |
+
st.title("Process Flow Diagram & Explanation Generator")
|
| 33 |
+
|
| 34 |
+
# Input for the process name
|
| 35 |
+
process_name = st.text_input("Enter the name of the process:", "Example Process")
|
| 36 |
+
|
| 37 |
+
if process_name:
|
| 38 |
+
# Display process flow diagram
|
| 39 |
+
st.subheader("Process Flow Diagram")
|
| 40 |
+
diagram = create_flow_diagram(process_name)
|
| 41 |
+
diagram_data = diagram.pipe()
|
| 42 |
+
|
| 43 |
+
# Display Diagram
|
| 44 |
+
st.image(BytesIO(diagram_data), format="PNG")
|
| 45 |
+
|
| 46 |
+
# Display explanation
|
| 47 |
+
st.subheader("Process Explanation")
|
| 48 |
+
explanation = generate_explanation(process_name)
|
| 49 |
+
st.write(explanation)
|
| 50 |
+
|
| 51 |
+
# Provide download options
|
| 52 |
+
st.download_button(
|
| 53 |
+
label="Download Diagram as PNG",
|
| 54 |
+
data=diagram_data,
|
| 55 |
+
file_name=f"{process_name}_flow_diagram.png",
|
| 56 |
+
mime="image/png"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|
| 61 |
+
|