Tank-thickness / app.py
Hidayatmahar's picture
Create app.py
8ad56c9 verified
import gradio as gr
# Function to calculate tank thickness
def calculate_tank_thickness(height, diameter, material_density, tensile_strength):
"""
Calculate tank thickness based on:
- height of tank (m),
- diameter of tank (m),
- material density to be poured (kg/m³),
- tensile strength of tank material (MPa).
Formula: t = (ρ * g * h * D) / (2 * S)
where:
- t = thickness (m)
- ρ = material density (kg/m³)
- g = gravity (9.81 m/s²)
- h = height (m)
- D = diameter (m)
- S = tensile strength (Pa)
"""
gravity = 9.81 # m/s²
tensile_strength_pa = tensile_strength * 1e6 # Convert MPa to Pa
thickness = (material_density * gravity * height * diameter) / (2 * tensile_strength_pa)
return round(thickness * 1000, 2) # Return thickness in mm
# Gradio interface
def tank_thickness_interface(height, diameter, material_density, tensile_strength):
thickness = calculate_tank_thickness(height, diameter, material_density, tensile_strength)
return f"The calculated tank thickness is: {thickness} mm."
# Create Gradio interface
with gr.Blocks() as app:
gr.Markdown("# Tank Thickness Calculator")
gr.Markdown(
"Calculate the required thickness of a tank based on its height, diameter, material density, and tensile strength."
)
with gr.Row():
height_input = gr.Number(label="Tank Height (m)", value=5.0)
diameter_input = gr.Number(label="Tank Diameter (m)", value=2.0)
with gr.Row():
density_input = gr.Number(label="Material Density (kg/m³)", value=1000)
tensile_input = gr.Number(label="Material Tensile Strength (MPa)", value=200)
output = gr.Textbox(label="Result", interactive=False)
calculate_button = gr.Button("Calculate Thickness")
calculate_button.click(
tank_thickness_interface,
inputs=[height_input, diameter_input, density_input, tensile_input],
outputs=output,
)
# Launch the app
if __name__ == "__main__":
app.launch()