Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,14 @@ import gradio as gr
|
|
2 |
import networkx as nx
|
3 |
import pydot
|
4 |
import pandas as pd
|
5 |
-
from io import BytesIO
|
6 |
|
7 |
-
def calculate_parameters(
|
8 |
-
#
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
G = nx.nx_pydot.from_pydot(graphs[0])
|
11 |
|
12 |
# Initialize the list of lengths and the node-to-index map
|
@@ -38,15 +41,17 @@ def calculate_parameters(file):
|
|
38 |
# Calculate average width (Wavg)
|
39 |
Wavg = Wabs / len(set(all_lengths))
|
40 |
|
41 |
-
# Create a DataFrame for
|
42 |
df = pd.DataFrame.from_dict(node_depth, orient='index', columns=['Depth'])
|
43 |
-
|
44 |
-
|
45 |
-
result = f"Node Depths:\n{node_depth_str}\n\nFinal Calculations:\n"
|
46 |
-
result += f"Dabs = {Dabs}, Dmax = {Dmax}, Davg = {Davg:.3f}\n"
|
47 |
-
result += f"Wabs = {Wabs}, Wmax = {Wmax}, Wavg = {Wavg:.3f}"
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
iface = gr.Interface(fn=calculate_parameters,
|
|
|
|
|
52 |
iface.launch()
|
|
|
2 |
import networkx as nx
|
3 |
import pydot
|
4 |
import pandas as pd
|
|
|
5 |
|
6 |
+
def calculate_parameters(dot_file):
|
7 |
+
# Read the dot file with specified encoding
|
8 |
+
with open(dot_file.name, 'r', encoding='utf-8') as f:
|
9 |
+
dot_data = f.read()
|
10 |
+
|
11 |
+
# Parse dot data using pydot
|
12 |
+
graphs = pydot.graph_from_dot_data(dot_data)
|
13 |
G = nx.nx_pydot.from_pydot(graphs[0])
|
14 |
|
15 |
# Initialize the list of lengths and the node-to-index map
|
|
|
41 |
# Calculate average width (Wavg)
|
42 |
Wavg = Wabs / len(set(all_lengths))
|
43 |
|
44 |
+
# Create a DataFrame for better visualization
|
45 |
df = pd.DataFrame.from_dict(node_depth, orient='index', columns=['Depth'])
|
46 |
+
df_str = df.to_string()
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
result_str = (f"Node Depths:\n{df_str}\n\nFinal Calculations:\n"
|
49 |
+
f"Dabs = {Dabs}, Dmax = {Dmax}, Davg = {Davg:.3f}\n"
|
50 |
+
f"Wabs = {Wabs}, Wmax = {Wmax}, Wavg = {Wavg:.3f}")
|
51 |
+
|
52 |
+
return result_str
|
53 |
|
54 |
+
iface = gr.Interface(fn=calculate_parameters,
|
55 |
+
inputs=gr.inputs.File(label="Upload .dot file"),
|
56 |
+
outputs="text")
|
57 |
iface.launch()
|