khababakhtar commited on
Commit
445bb5d
·
verified ·
1 Parent(s): 2c3ce4c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import math
3
+ import matplotlib.pyplot as plt
4
+ import numpy as np
5
+
6
+ # Set the page configuration with an icon and title
7
+ st.set_page_config(page_title="Pipe Sizing Helper", page_icon="💧")
8
+
9
+ # Title and description
10
+ st.title("💧 Pipe Sizing Helper")
11
+ st.write("Calculate the recommended pipe diameter for a given flow rate and permissible velocity.")
12
+
13
+ # Input fields
14
+ st.sidebar.header("Input Parameters")
15
+ flow_rate = st.sidebar.number_input("Enter the Flow Rate (m³/s):", min_value=0.0, format="%.6f")
16
+ velocity = st.sidebar.number_input("Enter the Permissible Velocity (m/s):", min_value=0.1, format="%.3f")
17
+
18
+ # Add a button to generate the result
19
+ if st.sidebar.button("Generate Diameter"):
20
+ if flow_rate > 0 and velocity > 0:
21
+ diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
22
+ st.success(f"Recommended Pipe Diameter: **{diameter:.3f} meters**")
23
+
24
+ # Visualization of Pipe Diameter vs Flow Rate and Velocity
25
+ fig, ax = plt.subplots(1, 2, figsize=(14, 6))
26
+
27
+ # Pipe Diameter vs Flow Rate
28
+ flow_rate_values = np.linspace(0.1, 10, 100) # Generate a range of flow rates
29
+ diameters_flow_rate = np.sqrt((4 * flow_rate_values) / (math.pi * velocity)) # Calculate diameters for each flow rate
30
+
31
+ ax[0].plot(flow_rate_values, diameters_flow_rate, color='b', label="Diameter vs Flow Rate")
32
+ ax[0].set_title("Pipe Diameter vs Flow Rate")
33
+ ax[0].set_xlabel("Flow Rate (m³/s)")
34
+ ax[0].set_ylabel("Pipe Diameter (meters)")
35
+ ax[0].grid(True)
36
+ ax[0].legend()
37
+
38
+ # Pipe Diameter vs Velocity
39
+ velocity_values = np.linspace(0.1, 10, 100) # Generate a range of velocities
40
+ diameters_velocity = np.sqrt((4 * flow_rate) / (math.pi * velocity_values)) # Calculate diameters for each velocity
41
+
42
+ ax[1].plot(velocity_values, diameters_velocity, color='r', label="Diameter vs Velocity")
43
+ ax[1].set_title("Pipe Diameter vs Velocity")
44
+ ax[1].set_xlabel("Velocity (m/s)")
45
+ ax[1].set_ylabel("Pipe Diameter (meters)")
46
+ ax[1].grid(True)
47
+ ax[1].legend()
48
+
49
+ # Show the plot
50
+ st.pyplot(fig)
51
+
52
+ else:
53
+ st.error("Please enter positive values for flow rate and velocity.")
54
+ else:
55
+ st.info("Click the 'Generate Diameter' button to calculate.")