Upload app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,7 @@ def generate_colorbar(colormap, normalize):
|
|
| 52 |
buf.seek(0)
|
| 53 |
base64_colorbar = base64.b64encode(buf.read()).decode("utf-8")
|
| 54 |
plt.close(fig) # Close the figure to free up memory
|
| 55 |
-
return f"<img src='data:image/png;base64,{base64_colorbar}' style='height:250px;'>"
|
| 56 |
|
| 57 |
|
| 58 |
# Helper function to generate HTML for state diagram with directed edges
|
|
@@ -166,6 +166,7 @@ def generate_state_diagram_html(P):
|
|
| 166 |
|
| 167 |
# Create the state diagram (2x2 grid)
|
| 168 |
html_content = f"""
|
|
|
|
| 169 |
<svg width="250" height="250">
|
| 170 |
{arrowhead_marker}
|
| 171 |
{edges}
|
|
@@ -189,7 +190,8 @@ def generate_state_diagram_html(P):
|
|
| 189 |
def generate_transition_matrix_html(P, prob_threshold=0.5, normalize=None, colormap=None, ticks=None):
|
| 190 |
header_size = "30px" # Set a fixed size for headers
|
| 191 |
cell_size = "60px" # Set a fixed size for cells
|
| 192 |
-
html_content = f"<
|
|
|
|
| 193 |
|
| 194 |
# Add xticks (column labels)
|
| 195 |
if ticks:
|
|
@@ -244,8 +246,10 @@ def initial_html(P):
|
|
| 244 |
combined_html = f"""
|
| 245 |
<div style="display: flex; align-items: center; justify-content: center; gap: 50px;">
|
| 246 |
<div>{state_diagram_html}</div>
|
| 247 |
-
<div>
|
| 248 |
-
|
|
|
|
|
|
|
| 249 |
</div>
|
| 250 |
"""
|
| 251 |
return combined_html
|
|
@@ -291,8 +295,10 @@ def process_sequence(current_P, P_true_str, sequence_length, lambda_, tau, state
|
|
| 291 |
combined_html = f"""
|
| 292 |
<div style="display: flex; align-items: center; justify-content: center; gap: 50px;">
|
| 293 |
<div>{state_diagram_html}</div>
|
| 294 |
-
<div>
|
| 295 |
-
|
|
|
|
|
|
|
| 296 |
</div>
|
| 297 |
"""
|
| 298 |
|
|
@@ -333,7 +339,7 @@ with gr.Blocks() as demo:
|
|
| 333 |
with gr.Column():
|
| 334 |
target_p = gr.Textbox(
|
| 335 |
value=matrix_to_string(modes[0]),
|
| 336 |
-
label="Enter
|
| 337 |
lines=4,
|
| 338 |
placeholder="Enter the 4x4 matrix here...",
|
| 339 |
)
|
|
|
|
| 52 |
buf.seek(0)
|
| 53 |
base64_colorbar = base64.b64encode(buf.read()).decode("utf-8")
|
| 54 |
plt.close(fig) # Close the figure to free up memory
|
| 55 |
+
return f"<img src='data:image/png;base64,{base64_colorbar}' style='height:250px; margin-top:30px'>"
|
| 56 |
|
| 57 |
|
| 58 |
# Helper function to generate HTML for state diagram with directed edges
|
|
|
|
| 166 |
|
| 167 |
# Create the state diagram (2x2 grid)
|
| 168 |
html_content = f"""
|
| 169 |
+
<div style="text-align:center;">State Diagram</div>
|
| 170 |
<svg width="250" height="250">
|
| 171 |
{arrowhead_marker}
|
| 172 |
{edges}
|
|
|
|
| 190 |
def generate_transition_matrix_html(P, prob_threshold=0.5, normalize=None, colormap=None, ticks=None):
|
| 191 |
header_size = "30px" # Set a fixed size for headers
|
| 192 |
cell_size = "60px" # Set a fixed size for cells
|
| 193 |
+
html_content = f"<div style='text-align: center; margin-left: {header_size}; margin-bottom: 10px;'>Transition Matrix</div>"
|
| 194 |
+
html_content += f"<table style='border: none; margin-bottom: {header_size} !important;'>"
|
| 195 |
|
| 196 |
# Add xticks (column labels)
|
| 197 |
if ticks:
|
|
|
|
| 246 |
combined_html = f"""
|
| 247 |
<div style="display: flex; align-items: center; justify-content: center; gap: 50px;">
|
| 248 |
<div>{state_diagram_html}</div>
|
| 249 |
+
<div style="display: flex; justify-content: center; align-items: center; gap: 10px;">
|
| 250 |
+
<div>{transition_matrix_html}</div>
|
| 251 |
+
<div>{colorbar_html}</div>
|
| 252 |
+
</div>
|
| 253 |
</div>
|
| 254 |
"""
|
| 255 |
return combined_html
|
|
|
|
| 295 |
combined_html = f"""
|
| 296 |
<div style="display: flex; align-items: center; justify-content: center; gap: 50px;">
|
| 297 |
<div>{state_diagram_html}</div>
|
| 298 |
+
<div style="display: flex; justify-content: center; align-items: center; gap: 10px;">
|
| 299 |
+
<div>{transition_matrix_html}</div>
|
| 300 |
+
<div>{colorbar_html}</div>
|
| 301 |
+
</div>
|
| 302 |
</div>
|
| 303 |
"""
|
| 304 |
|
|
|
|
| 339 |
with gr.Column():
|
| 340 |
target_p = gr.Textbox(
|
| 341 |
value=matrix_to_string(modes[0]),
|
| 342 |
+
label="Enter transition matrix or select a mode.",
|
| 343 |
lines=4,
|
| 344 |
placeholder="Enter the 4x4 matrix here...",
|
| 345 |
)
|