razaali10 commited on
Commit
9df58fc
·
verified ·
1 Parent(s): e98eff6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -4,6 +4,7 @@ import json
4
  import traceback
5
  from hardy_cross_solver import hardy_cross_solver
6
  from hardy_cross_plot import plot_hardy_cross_network
 
7
 
8
  def run_hardy_cross(file, loops_json, max_iterations, tolerance):
9
  try:
@@ -16,16 +17,26 @@ def run_hardy_cross(file, loops_json, max_iterations, tolerance):
16
  max_iterations=int(max_iterations),
17
  tolerance=float(tolerance)
18
  )
19
- plot_path = "hardy_cross_network_result.png"
20
- plot_hardy_cross_network(final_flows, save_path=plot_path)
 
 
 
 
 
 
 
 
21
  return (
22
  final_flows.to_markdown(),
23
  pd.DataFrame(results).to_markdown(),
24
  plot_path
25
  )
26
  except Exception as e:
27
- # Capture full stack trace for clear debugging
28
- error_message = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
 
 
29
  return error_message, "", ""
30
 
31
  demo = gr.Interface(
@@ -46,4 +57,4 @@ demo = gr.Interface(
46
  )
47
 
48
  if __name__ == "__main__":
49
- demo.launch()
 
4
  import traceback
5
  from hardy_cross_solver import hardy_cross_solver
6
  from hardy_cross_plot import plot_hardy_cross_network
7
+ import os
8
 
9
  def run_hardy_cross(file, loops_json, max_iterations, tolerance):
10
  try:
 
17
  max_iterations=int(max_iterations),
18
  tolerance=float(tolerance)
19
  )
20
+
21
+ # Generate and confirm plot path
22
+ plot_filename = "hardy_cross_network_result.png"
23
+ plot_path = plot_hardy_cross_network(final_flows, save_path=plot_filename)
24
+
25
+ # Double-check that the plot_path is a valid PNG file
26
+ if not (os.path.isfile(plot_path) and plot_path.endswith(".png")):
27
+ raise ValueError(f"Generated plot_path is invalid or not a PNG file: {plot_path}")
28
+
29
+ # Return structured outputs
30
  return (
31
  final_flows.to_markdown(),
32
  pd.DataFrame(results).to_markdown(),
33
  plot_path
34
  )
35
  except Exception as e:
36
+ # Full traceback for clear debugging in output
37
+ error_message = f"❌ **Error:** {str(e)}\n\n```
38
+ {traceback.format_exc()}
39
+ ```"
40
  return error_message, "", ""
41
 
42
  demo = gr.Interface(
 
57
  )
58
 
59
  if __name__ == "__main__":
60
+ demo.launch()