Spaces:
Sleeping
Sleeping
# app.py | |
import streamlit as st | |
import math | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Page Configuration with Icon | |
st.set_page_config( | |
page_title="π§ Pipe Sizing Helper", | |
page_icon="π§", | |
layout="centered" | |
) | |
# Custom CSS for Styling | |
st.markdown(""" | |
<style> | |
.title { | |
text-align: center; | |
font-size: 2.5em; | |
font-weight: bold; | |
color: #4CAF50; | |
} | |
.subtitle { | |
text-align: center; | |
font-size: 1.2em; | |
color: #555; | |
} | |
.result { | |
text-align: center; | |
font-size: 1.3em; | |
font-weight: bold; | |
color: #2196F3; | |
margin-top: 20px; | |
} | |
.footer { | |
text-align: center; | |
margin-top: 50px; | |
font-size: 0.9em; | |
color: #777; | |
} | |
.icon { | |
text-align: center; | |
font-size: 4em; | |
color: #FF9800; | |
} | |
.button { | |
text-align: center; | |
margin-top: 30px; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# Header with Icon | |
st.markdown("<div class='icon'>π§</div>", unsafe_allow_html=True) | |
st.markdown("<h1 class='title'>π§ Pipe Sizing Helper</h1>", unsafe_allow_html=True) | |
st.markdown("<p class='subtitle'>Calculate optimal pipe size based on flow rate and velocity</p>", unsafe_allow_html=True) | |
# User Inputs | |
st.subheader("π‘ Input Parameters") | |
flow_rate = st.number_input("π Enter Flow Rate (mΒ³/s):", min_value=0.0, format="%.4f") | |
velocity = st.number_input("π¨ Enter Permissible Velocity (m/s):", min_value=0.1, format="%.2f") | |
# Button for Calculation and Visualization | |
st.markdown("<div class='button'>", unsafe_allow_html=True) | |
if st.button("π Generate Pipe Diameter and Visualize"): | |
if velocity > 0 and flow_rate > 0: | |
# Formula: Diameter = sqrt((4 * Flow Rate) / (Ο * Velocity)) | |
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity)) | |
st.markdown(f"<p class='result'>β Recommended Pipe Diameter: {diameter:.2f} meters</p>", unsafe_allow_html=True) | |
# Visualization | |
st.subheader("π Visualization: Pipe Diameter vs Flow Rate and Velocity") | |
flow_rates = np.linspace(0.1, flow_rate * 2, 100) | |
velocities = np.linspace(0.1, velocity * 2, 100) | |
diameters = [math.sqrt((4 * fr) / (math.pi * velocity)) for fr in flow_rates] | |
# Plot | |
fig, ax = plt.subplots() | |
ax.plot(flow_rates, diameters, label='Pipe Diameter (m)', lw=2) | |
ax.scatter(flow_rate, diameter, color='red', zorder=5, label='Your Input') | |
ax.set_xlabel('Flow Rate (mΒ³/s)') | |
ax.set_ylabel('Pipe Diameter (m)') | |
ax.set_title('Pipe Diameter vs Flow Rate') | |
ax.legend() | |
ax.grid(True) | |
st.pyplot(fig) | |
else: | |
st.warning("β οΈ Please enter valid positive values for flow rate and velocity.") | |
st.markdown("</div>", unsafe_allow_html=True) | |
# Footer | |
st.markdown("<p class='footer'>π» <b>Developed by ChatGPT</b></p>", unsafe_allow_html=True) | |