File size: 3,105 Bytes
13250a7
 
 
4960406
 
13250a7
4fff0ef
13250a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4fff0ef
13250a7
 
 
 
 
 
 
4fff0ef
 
 
 
 
 
 
 
 
13250a7
 
 
4fff0ef
 
13250a7
 
 
 
 
 
 
 
4960406
4fff0ef
4960406
13250a7
 
 
 
4960406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13250a7
 
4fff0ef
13250a7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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)