rmayormartins commited on
Commit
e28fa28
·
1 Parent(s): d77b896

Atualizacao app com split

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -5,19 +5,19 @@ import zipfile
5
  import os
6
 
7
  def process_onnx(uploaded_file):
8
-
9
  if zipfile.is_zipfile(uploaded_file.name):
10
  with zipfile.ZipFile(uploaded_file.name, 'r') as zip_ref:
11
  zip_ref.extractall("/tmp")
12
- onnx_file = zip_ref.namelist()[0]
13
  file_path = os.path.join("/tmp", onnx_file)
14
  else:
15
  file_path = uploaded_file.name
16
 
17
-
18
  model = onnx.load(file_path)
19
 
20
-
21
  info = {
22
  "Model Name": model.graph.name,
23
  "Number of Nodes": len(model.graph.node),
@@ -25,7 +25,7 @@ def process_onnx(uploaded_file):
25
  "Nodes": []
26
  }
27
 
28
-
29
  for node in model.graph.node:
30
  node_info = {
31
  "Name": node.name,
@@ -36,23 +36,23 @@ def process_onnx(uploaded_file):
36
  info["Nodes"].append(node_info)
37
  info["Architecture Summary"][node.op_type] += 1
38
 
39
-
40
- output = []
41
- for key, value in info.items():
42
- if key != "Nodes":
43
- output.append(f"{key}: {value}")
44
- output.append("\nComplete Nodes:")
45
- for node in info["Nodes"]:
46
- output.append(str(node))
47
 
48
- return '\n'.join(output)
 
 
 
49
 
50
  iface = gr.Interface(
51
  fn=process_onnx,
52
- inputs=gr.File(label="Upload .ONNX or .ZIP (with .onnx) File"),
53
- outputs="text",
 
 
 
54
  title="ONNX Model Scope",
55
- description="Upload an ONNX file or a ZIP (containing an .onnx file) to extract and display its detailed information. This process can take some time depending on the size of the ONNX model."
56
  )
57
 
58
  iface.launch(debug=True)
 
5
  import os
6
 
7
  def process_onnx(uploaded_file):
8
+ # Check if the uploaded file is a zip file
9
  if zipfile.is_zipfile(uploaded_file.name):
10
  with zipfile.ZipFile(uploaded_file.name, 'r') as zip_ref:
11
  zip_ref.extractall("/tmp")
12
+ onnx_file = zip_ref.namelist()[0] # Assuming there is only one ONNX file in the zip
13
  file_path = os.path.join("/tmp", onnx_file)
14
  else:
15
  file_path = uploaded_file.name
16
 
17
+ # Load the ONNX model
18
  model = onnx.load(file_path)
19
 
20
+ # Collect basic information about the model
21
  info = {
22
  "Model Name": model.graph.name,
23
  "Number of Nodes": len(model.graph.node),
 
25
  "Nodes": []
26
  }
27
 
28
+ # Iterate over each node (layer) to collect detailed information
29
  for node in model.graph.node:
30
  node_info = {
31
  "Name": node.name,
 
36
  info["Nodes"].append(node_info)
37
  info["Architecture Summary"][node.op_type] += 1
38
 
39
+ # Format the summary output
40
+ summary_output = '\n'.join([f"{key}: {value}" for key, value in info.items() if key != "Nodes"])
 
 
 
 
 
 
41
 
42
+ # Format the complete nodes output
43
+ nodes_output = "Complete Nodes:\n" + '\n'.join([str(node) for node in info["Nodes"]])
44
+
45
+ return summary_output, nodes_output
46
 
47
  iface = gr.Interface(
48
  fn=process_onnx,
49
+ inputs=gr.File(label="Upload .ONNX or .ZIP File"),
50
+ outputs=[
51
+ gr.components.Textbox(label="Summary"),
52
+ gr.components.Textbox(label="Complete Nodes")
53
+ ],
54
  title="ONNX Model Scope",
55
+ description="Upload an ONNX file or a ZIP file containing an .onnx file to extract and display its detailed information. This process can take some time depending on the size of the ONNX model."
56
  )
57
 
58
  iface.launch(debug=True)