Spaces:
Sleeping
Sleeping
AyeshaAslam
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import math
|
|
|
|
|
3 |
|
4 |
# Function to calculate pipe diameter
|
5 |
def calculate_diameter(flow_rate, velocity):
|
@@ -9,6 +11,29 @@ def calculate_diameter(flow_rate, velocity):
|
|
9 |
diameter = math.sqrt(4 * flow_rate / (math.pi * velocity))
|
10 |
return diameter
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Streamlit App
|
13 |
def main():
|
14 |
# Set the page configuration with a title, icon, and layout style
|
@@ -34,6 +59,10 @@ def main():
|
|
34 |
st.write(f"The recommended pipe diameter is: **{diameter:.2f} meters**")
|
35 |
else:
|
36 |
st.error("Please enter valid values for flow rate and velocity.")
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Add some helpful info or tips
|
39 |
st.markdown("""
|
|
|
1 |
import streamlit as st
|
2 |
import math
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
|
6 |
# Function to calculate pipe diameter
|
7 |
def calculate_diameter(flow_rate, velocity):
|
|
|
11 |
diameter = math.sqrt(4 * flow_rate / (math.pi * velocity))
|
12 |
return diameter
|
13 |
|
14 |
+
# Function to plot the graph
|
15 |
+
def plot_diameter_graph():
|
16 |
+
# Define a range of flow rates (Q) and velocities (v)
|
17 |
+
flow_rate_values = np.linspace(0.01, 1.0, 100) # Range of flow rates (0.01 to 1.0 m³/s)
|
18 |
+
velocity_values = np.linspace(0.1, 5.0, 50) # Range of velocities (0.1 to 5.0 m/s)
|
19 |
+
|
20 |
+
# Create a meshgrid for the flow rates and velocities
|
21 |
+
flow_rate_grid, velocity_grid = np.meshgrid(flow_rate_values, velocity_values)
|
22 |
+
|
23 |
+
# Calculate the pipe diameter for each combination of flow rate and velocity
|
24 |
+
diameter_values = np.sqrt(4 * flow_rate_grid / (np.pi * velocity_grid))
|
25 |
+
|
26 |
+
# Plotting the graph
|
27 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
28 |
+
cp = ax.contourf(flow_rate_grid, velocity_grid, diameter_values, cmap='viridis')
|
29 |
+
fig.colorbar(cp, ax=ax, label='Pipe Diameter (m)')
|
30 |
+
ax.set_xlabel('Flow Rate (m³/s)')
|
31 |
+
ax.set_ylabel('Velocity (m/s)')
|
32 |
+
ax.set_title('Pipe Diameter vs. Flow Rate and Velocity')
|
33 |
+
|
34 |
+
# Display the plot in Streamlit
|
35 |
+
st.pyplot(fig)
|
36 |
+
|
37 |
# Streamlit App
|
38 |
def main():
|
39 |
# Set the page configuration with a title, icon, and layout style
|
|
|
59 |
st.write(f"The recommended pipe diameter is: **{diameter:.2f} meters**")
|
60 |
else:
|
61 |
st.error("Please enter valid values for flow rate and velocity.")
|
62 |
+
|
63 |
+
# Show the graphical visualization of pipe diameter vs flow rate and velocity
|
64 |
+
st.subheader("Graphical Visualization")
|
65 |
+
plot_diameter_graph()
|
66 |
|
67 |
# Add some helpful info or tips
|
68 |
st.markdown("""
|