Waqasuet commited on
Commit
6c59865
·
verified ·
1 Parent(s): e1943b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from math import pi
4
+
5
+ # Beam Deflection Calculator (Euler-Bernoulli)
6
+ def beam_deflection(load, length, elasticity, inertia, support_type):
7
+ """
8
+ Calculate deflection for common beam supports.
9
+ Units: Load (N), Length (m), Elasticity (Pa), Inertia (m^4)
10
+ """
11
+ if support_type == "Simply Supported (Center Load)":
12
+ deflection = (load * length**3) / (48 * elasticity * inertia)
13
+ elif support_type == "Cantilever (End Load)":
14
+ deflection = (load * length**3) / (3 * elasticity * inertia)
15
+ elif support_type == "Simply Supported (Uniform Load)":
16
+ deflection = (5 * load * length**4) / (384 * elasticity * inertia)
17
+ else:
18
+ return "Invalid support type"
19
+ return f"Max Deflection: {deflection * 1000:.2f} mm"
20
+
21
+ # Section Properties Calculator
22
+ def section_properties(width, height, shape):
23
+ """Calculate area and moment of inertia for rectangular or circular sections."""
24
+ if shape == "Rectangle":
25
+ area = width * height
26
+ inertia = (width * height**3) / 12
27
+ elif shape == "Circle":
28
+ diameter = width
29
+ area = pi * (diameter / 2)**2
30
+ inertia = pi * (diameter**4) / 64
31
+ else:
32
+ return "Invalid shape"
33
+ return f"Area: {area:.2f} m² | Moment of Inertia: {inertia:.4f} m⁴"
34
+
35
+ # Load Capacity Estimator (Simplified)
36
+ def load_capacity(material, cross_section_area, safety_factor):
37
+ """Estimate allowable load based on material strength."""
38
+ material_strength = {
39
+ "Concrete (20MPa)": 20e6,
40
+ "Steel (A36)": 250e6,
41
+ "Wood (Pine)": 10e6
42
+ }
43
+ allowable_stress = material_strength[material] / safety_factor
44
+ capacity = allowable_stress * cross_section_area
45
+ return f"Allowable Load: {capacity / 1000:.2f} kN"
46
+
47
+ # Gradio UI
48
+ with gr.Blocks(title="Structural Engineering Toolkit") as app:
49
+ gr.Markdown("# 🏗️ Structural Engineering Toolkit")
50
+
51
+ with gr.Tab("Beam Deflection"):
52
+ gr.Markdown("### Calculate beam deflection under load")
53
+ with gr.Row():
54
+ load = gr.Number(label="Load (N)")
55
+ length = gr.Number(label="Length (m)")
56
+ elasticity = gr.Number(label="Elasticity Modulus (Pa)", value=2.1e11) # Steel default
57
+ inertia = gr.Number(label="Moment of Inertia (m⁴)", value=1e-6)
58
+ support_type = gr.Dropdown(
59
+ ["Simply Supported (Center Load)", "Cantilever (End Load)", "Simply Supported (Uniform Load)"],
60
+ label="Support Type"
61
+ )
62
+ deflection_output = gr.Textbox(label="Result")
63
+ gr.Button("Calculate").click(
64
+ beam_deflection,
65
+ inputs=[load, length, elasticity, inertia, support_type],
66
+ outputs=deflection_output
67
+ )
68
+
69
+ with gr.Tab("Section Properties"):
70
+ gr.Markdown("### Calculate geometric properties of sections")
71
+ shape = gr.Dropdown(["Rectangle", "Circle"], label="Shape")
72
+ width = gr.Number(label="Width/Diameter (m)")
73
+ height = gr.Number(label="Height (m)", visible=True)
74
+ shape.change(
75
+ lambda x: gr.Number(visible=(x == "Rectangle")),
76
+ inputs=shape,
77
+ outputs=height
78
+ )
79
+ section_output = gr.Textbox(label="Result")
80
+ gr.Button("Calculate").click(
81
+ section_properties,
82
+ inputs=[width, height, shape],
83
+ outputs=section_output
84
+ )
85
+
86
+ with gr.Tab("Load Capacity"):
87
+ gr.Markdown("### Estimate allowable load for materials")
88
+ material = gr.Dropdown(
89
+ ["Concrete (20MPa)", "Steel (A36)", "Wood (Pine)"],
90
+ label="Material"
91
+ )
92
+ cross_section_area = gr.Number(label="Cross-Section Area (m²)", value=0.01)
93
+ safety_factor = gr.Slider(1.5, 5, value=2.5, label="Safety Factor")
94
+ capacity_output = gr.Textbox(label="Result")
95
+ gr.Button("Calculate").click(
96
+ load_capacity,
97
+ inputs=[material, cross_section_area, safety_factor],
98
+ outputs=capacity_output
99
+ )
100
+
101
+ gr.Markdown("---\n**Note:** This is a simplified tool for educational purposes.")
102
+
103
+ app.launch()