Spaces:
Sleeping
Sleeping
Updated app.py with new features/plots
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import sympy as sp
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
def solve_beam(l1_val, l2_val, q1_val, q2_val):
|
7 |
# Define the variables
|
@@ -67,22 +68,46 @@ def solve_beam(l1_val, l2_val, q1_val, q2_val):
|
|
67 |
|
68 |
return beam
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
def main(l1, l2, q1, q2):
|
71 |
beam_df = solve_beam(l1, l2, q1, q2)
|
72 |
csv_file = 'beam_analysis.csv'
|
73 |
beam_df.to_csv(csv_file, index=False)
|
74 |
-
|
|
|
75 |
|
76 |
inputs = [
|
77 |
-
gr.components.Number(label="Length of span 1 (l1
|
78 |
-
gr.components.Number(label="Length of span 2 (l2
|
79 |
-
gr.components.Number(label="Load on span 1 (q1
|
80 |
-
gr.components.Number(label="Load on span 2 (q2
|
81 |
]
|
82 |
|
83 |
outputs = [
|
84 |
gr.components.Dataframe(label="Beam Analysis Data"),
|
85 |
-
gr.components.File(label="Download CSV")
|
|
|
86 |
]
|
87 |
|
88 |
-
gr.Interface(fn=main, inputs=inputs, outputs=outputs, title="Beam Analysis Tool").launch()
|
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import gradio as gr
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
|
7 |
def solve_beam(l1_val, l2_val, q1_val, q2_val):
|
8 |
# Define the variables
|
|
|
68 |
|
69 |
return beam
|
70 |
|
71 |
+
def plot_beam(beam_df):
|
72 |
+
fig, axs = plt.subplots(2, 1, figsize=(8, 8))
|
73 |
+
|
74 |
+
# Plot bending moment
|
75 |
+
axs[0].plot(beam_df['x'], beam_df['M'], label='Bending Moment (M)')
|
76 |
+
axs[0].invert_yaxis()
|
77 |
+
axs[0].set_title('Bending Moment Diagram')
|
78 |
+
axs[0].set_xlabel('Position along the beam (x)')
|
79 |
+
axs[0].set_ylabel('Bending Moment (M)')
|
80 |
+
axs[0].legend()
|
81 |
+
|
82 |
+
# Plot shear force
|
83 |
+
axs[1].plot(beam_df['x'], beam_df['V'], label='Shear Force (V)')
|
84 |
+
axs[1].invert_yaxis()
|
85 |
+
axs[1].set_title('Shear Force Diagram')
|
86 |
+
axs[1].set_xlabel('Position along the beam (x)')
|
87 |
+
axs[1].set_ylabel('Shear Force (V)')
|
88 |
+
axs[1].legend()
|
89 |
+
|
90 |
+
plt.tight_layout()
|
91 |
+
return fig
|
92 |
+
|
93 |
def main(l1, l2, q1, q2):
|
94 |
beam_df = solve_beam(l1, l2, q1, q2)
|
95 |
csv_file = 'beam_analysis.csv'
|
96 |
beam_df.to_csv(csv_file, index=False)
|
97 |
+
fig = plot_beam(beam_df)
|
98 |
+
return beam_df, csv_file, fig
|
99 |
|
100 |
inputs = [
|
101 |
+
gr.components.Number(label="Length of span 1 (l1)"),
|
102 |
+
gr.components.Number(label="Length of span 2 (l2)"),
|
103 |
+
gr.components.Number(label="Load on span 1 (q1)"),
|
104 |
+
gr.components.Number(label="Load on span 2 (q2)")
|
105 |
]
|
106 |
|
107 |
outputs = [
|
108 |
gr.components.Dataframe(label="Beam Analysis Data"),
|
109 |
+
gr.components.File(label="Download CSV"),
|
110 |
+
gr.components.Plot(label="Bending Moment and Shear Force Diagrams")
|
111 |
]
|
112 |
|
113 |
+
gr.Interface(fn=main, inputs=inputs, outputs=outputs, title="Beam Analysis Tool").launch()
|