forked from fit-process-mining/POWL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
212 lines (175 loc) · 7.23 KB
/
Copy pathapp.py
File metadata and controls
212 lines (175 loc) · 7.23 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import os
import shutil
import tempfile
from enum import Enum
import powl
import streamlit as st
from pm4py.objects.bpmn.exporter.variants.etree import get_xml_string
from pm4py.objects.bpmn.layout import layouter as bpmn_layouter
from pm4py.objects.petri_net.exporter.variants.pnml import export_petri_as_string
from pm4py.util import constants
from pm4py.visualization.bpmn import visualizer as bpmn_visualizer
from pm4py.visualization.petri_net import visualizer as pn_visualizer
from powl.conversion.variants.to_bpmn import apply as bpmn_converter
class ViewType(Enum):
BPMN = "BPMN"
POWL = "POWL"
PETRI = "Petri Net"
def run_app():
st.title("🔍 POWL Miner")
st.subheader("Process Mining with the Partially Ordered Workflow Language")
temp_dir = "temp"
system_dot = shutil.which("dot")
if system_dot:
print(f"Found system-wide 'dot' at: {system_dot}")
else:
base_path = "/home/adminuser/.conda"
possible_subpaths = ["bin"]
for sub in possible_subpaths:
candidate = os.path.join(base_path, sub, "dot")
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
print(f"Found 'dot' at: {candidate}")
os.environ["PATH"] += os.pathsep + os.path.dirname(candidate)
break
else:
st.error(body="Couldn't find 'dot' — is Graphviz installed?", icon="⚠️")
with st.form(key="model_gen_form"):
uploaded_log = st.file_uploader(
"For **process model discovery**, upload an event log:",
type=["csv", "xes", "gz"],
help="Supported file types: csv, xes, xes.gz",
)
threshold = st.number_input(
label="Noise Filtering Threshold (0.0 = No Filtering)",
min_value=0.0,
max_value=1.0,
value=0.0,
step=0.01,
help="Set the threshold for DFG frequency filtering",
)
submit_button = st.form_submit_button(label="Run")
if submit_button:
if uploaded_log is None:
st.error(body="No file is selected!", icon="⚠️")
return
try:
contents = uploaded_log.read()
os.makedirs(temp_dir, exist_ok=True)
with tempfile.NamedTemporaryFile(
mode="wb", delete=False, dir=temp_dir, suffix=uploaded_log.name
) as temp_file:
temp_file.write(contents)
log = powl.import_event_log(temp_file.name)
shutil.rmtree(temp_dir, ignore_errors=True)
process_model = powl.discover(
log, dfg_frequency_filtering_threshold=threshold
)
st.session_state["model_gen"] = process_model
except Exception as e:
shutil.rmtree(temp_dir, ignore_errors=True)
st.error(body=f"Error during discovery: {e}", icon="⚠️")
return
if "model_gen" in st.session_state and st.session_state["model_gen"]:
st.success("Model generated successfully!", icon="🎉")
st.write("Export Model")
powl_model = st.session_state["model_gen"]
bpmn, _, _ = bpmn_converter(powl_model)
layouted_bpmn = bpmn_layouter.apply(bpmn)
try:
pn, im, fm = powl.convert_to_petri_net(powl_model)
download_1, download_2 = st.columns(2)
with download_1:
bpmn_data = get_xml_string(
layouted_bpmn, parameters={"encoding": constants.DEFAULT_ENCODING}
)
st.download_button(
label="Download BPMN",
data=bpmn_data,
file_name="process_model.bpmn",
mime="application/xml",
)
with download_2:
pn_data = export_petri_as_string(pn, im, fm)
st.download_button(
label="Download PNML",
data=pn_data,
file_name="process_model.pnml",
mime="application/xml",
)
view_option = st.selectbox(
"Select a view:", [v_type.value for v_type in ViewType]
)
image_format = str("svg").lower()
if view_option == ViewType.POWL.value:
from powl.visualization.powl import visualizer
vis_str = visualizer.apply(powl_model)
elif view_option == ViewType.PETRI.value:
visualization = pn_visualizer.apply(
pn, im, fm, parameters={"format": image_format}
)
vis_str = visualization.pipe(format="svg").decode("utf-8")
else: # BPMN
visualization = bpmn_visualizer.apply(
layouted_bpmn, parameters={"format": image_format}
)
vis_str = visualization.pipe(format="svg").decode("utf-8")
with st.expander("View Image", expanded=True):
st.image(vis_str)
except Exception as e:
st.error(icon="⚠️", body=str(e))
def footer():
style = """
<style>
.footer-container {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
padding: 15px 0;
background-color: white;
border-top: 2px solid lightgrey;
z-index: 100;
}
.footer-text, .header-text {
margin: 0;
padding: 0;
}
.footer-links {
margin: 0;
padding: 0;
}
.footer-links a {
margin: 0 10px;
text-decoration: none;
color: blue;
}
.footer-links img {
vertical-align: middle;
}
</style>
"""
foot = f"""
<div class='footer-container'>
<div class='footer-text'>
Developed by
<a href="https://www.linkedin.com/in/humam-kourani-98b342232/" target="_blank" style="text-decoration:none;">Humam Kourani</a>
at the
<a href="https://www.fit.fraunhofer.de/" target="_blank" style="text-decoration:none;">Fraunhofer Institute for Applied Information Technology FIT</a>.
</div>
<div class='footer-links'>
<a href="https://arxiv.org/abs/2505.07052" target="_blank">
<img src="https://img.shields.io/badge/Unlocking%20Non--Block--Structured%20Decisions:%20Inductive%20Mining%20with%20Choice%20Graphs-gray?logo=googledocs&logoColor=white&labelColor=red" alt="Paper">
</a>
<a href="mailto:humam.kourani@fit.fraunhofer.de;" target="_blank">
<img src="https://img.shields.io/badge/Email-gray?logo=minutemailer&logoColor=white&labelColor=green" alt="Email Humam Kourani">
</a>
</div>
</div>
"""
st.markdown(style, unsafe_allow_html=True)
st.markdown(foot, unsafe_allow_html=True)
if __name__ == "__main__":
st.set_page_config(page_title="POWL Miner", page_icon="🔍")
footer()
run_app()