Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
3 |
import math
|
|
|
|
|
4 |
|
5 |
# Page Configuration with Icon
|
6 |
st.set_page_config(
|
@@ -58,13 +60,31 @@ st.subheader("π‘ Input Parameters")
|
|
58 |
flow_rate = st.number_input("π Enter Flow Rate (mΒ³/s):", min_value=0.0, format="%.4f")
|
59 |
velocity = st.number_input("π¨ Enter Permissible Velocity (m/s):", min_value=0.1, format="%.2f")
|
60 |
|
61 |
-
# Button for Calculation
|
62 |
st.markdown("<div class='button'>", unsafe_allow_html=True)
|
63 |
-
if st.button("π Generate Pipe Diameter"):
|
64 |
if velocity > 0 and flow_rate > 0:
|
65 |
# Formula: Diameter = sqrt((4 * Flow Rate) / (Ο * Velocity))
|
66 |
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
|
67 |
st.markdown(f"<p class='result'>β
Recommended Pipe Diameter: {diameter:.2f} meters</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
else:
|
69 |
st.warning("β οΈ Please enter valid positive values for flow rate and velocity.")
|
70 |
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
1 |
# app.py
|
2 |
import streamlit as st
|
3 |
import math
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import numpy as np
|
6 |
|
7 |
# Page Configuration with Icon
|
8 |
st.set_page_config(
|
|
|
60 |
flow_rate = st.number_input("π Enter Flow Rate (mΒ³/s):", min_value=0.0, format="%.4f")
|
61 |
velocity = st.number_input("π¨ Enter Permissible Velocity (m/s):", min_value=0.1, format="%.2f")
|
62 |
|
63 |
+
# Button for Calculation and Visualization
|
64 |
st.markdown("<div class='button'>", unsafe_allow_html=True)
|
65 |
+
if st.button("π Generate Pipe Diameter and Visualize"):
|
66 |
if velocity > 0 and flow_rate > 0:
|
67 |
# Formula: Diameter = sqrt((4 * Flow Rate) / (Ο * Velocity))
|
68 |
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
|
69 |
st.markdown(f"<p class='result'>β
Recommended Pipe Diameter: {diameter:.2f} meters</p>", unsafe_allow_html=True)
|
70 |
+
|
71 |
+
# Visualization
|
72 |
+
st.subheader("π Visualization: Pipe Diameter vs Flow Rate and Velocity")
|
73 |
+
flow_rates = np.linspace(0.1, flow_rate * 2, 100)
|
74 |
+
velocities = np.linspace(0.1, velocity * 2, 100)
|
75 |
+
diameters = [math.sqrt((4 * fr) / (math.pi * velocity)) for fr in flow_rates]
|
76 |
+
|
77 |
+
# Plot
|
78 |
+
fig, ax = plt.subplots()
|
79 |
+
ax.plot(flow_rates, diameters, label='Pipe Diameter (m)', lw=2)
|
80 |
+
ax.scatter(flow_rate, diameter, color='red', zorder=5, label='Your Input')
|
81 |
+
ax.set_xlabel('Flow Rate (mΒ³/s)')
|
82 |
+
ax.set_ylabel('Pipe Diameter (m)')
|
83 |
+
ax.set_title('Pipe Diameter vs Flow Rate')
|
84 |
+
ax.legend()
|
85 |
+
ax.grid(True)
|
86 |
+
|
87 |
+
st.pyplot(fig)
|
88 |
else:
|
89 |
st.warning("β οΈ Please enter valid positive values for flow rate and velocity.")
|
90 |
st.markdown("</div>", unsafe_allow_html=True)
|