Talha1786 commited on
Commit
ca3b44e
·
verified ·
1 Parent(s): fcb501b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -15
app.py CHANGED
@@ -1,20 +1,75 @@
1
  import streamlit as st
2
  import math
3
 
4
- # Application title
5
- st.title("Pipe Size Calculator")
 
 
 
 
 
6
 
7
- # Input fields for flow rate and velocity
8
- flow_rate = st.number_input("Enter flow rate (m³/s):", min_value=0.0, step=0.01, format="%.2f")
9
- velocity = st.number_input("Enter velocity (m/s):", min_value=0.0, step=0.01, format="%.2f")
10
-
11
- # Calculate and display the recommended pipe diameter
12
- if flow_rate > 0 and velocity > 0:
13
- # Calculate pipe diameter in meters
14
- diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
15
 
16
- # Convert diameter to centimeters for better readability
17
- diameter_cm = diameter * 100
18
- st.success(f"Recommended Pipe Diameter: {diameter:.4f} meters ({diameter_cm:.2f} cm)")
19
- else:
20
- st.warning("Please enter valid positive values for both flow rate and velocity.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import math
3
 
4
+ # Set page configuration
5
+ st.set_page_config(
6
+ page_title="Pipe Size Calculator",
7
+ page_icon="💧",
8
+ layout="centered",
9
+ initial_sidebar_state="expanded",
10
+ )
11
 
12
+ # Sidebar for input and app information
13
+ st.sidebar.title("Pipe Size Calculator 💧")
14
+ st.sidebar.markdown(
15
+ """
16
+ Calculate the **recommended pipe diameter** based on:
17
+ - Flow Rate (\( Q \)) in cubic meters per second.
18
+ - Velocity (\( V \)) in meters per second.
 
19
 
20
+ Developed for engineers and fluid mechanics enthusiasts! 🌊
21
+ """
22
+ )
23
+
24
+ # Main application title
25
+ st.title("💧 Pipe Size Calculator")
26
+
27
+ # Add layout with two columns
28
+ col1, col2 = st.columns(2)
29
+
30
+ # Input section
31
+ with col1:
32
+ st.header("Input Parameters")
33
+ flow_rate = st.number_input(
34
+ "Enter Flow Rate (m³/s):",
35
+ min_value=0.0,
36
+ step=0.01,
37
+ format="%.2f"
38
+ )
39
+ velocity = st.number_input(
40
+ "Enter Velocity (m/s):",
41
+ min_value=0.0,
42
+ step=0.01,
43
+ format="%.2f"
44
+ )
45
+
46
+ # Add a button to calculate the diameter
47
+ with col2:
48
+ st.header("Action")
49
+ if st.button("Generate Pipe Diameter"):
50
+ if flow_rate > 0 and velocity > 0:
51
+ # Calculate pipe diameter
52
+ diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
53
+ diameter_cm = diameter * 100 # Convert to cm for better readability
54
+
55
+ # Display results in success box
56
+ st.success(
57
+ f"Recommended Pipe Diameter: \n"
58
+ f"- **{diameter:.4f} meters** \n"
59
+ f"- **{diameter_cm:.2f} centimeters**"
60
+ )
61
+ else:
62
+ # Warning for invalid input
63
+ st.error("Please enter positive values for both flow rate and velocity.")
64
+ else:
65
+ st.info("Click the button to calculate the pipe diameter.")
66
+
67
+ # Footer with additional info
68
+ st.sidebar.markdown("---")
69
+ st.sidebar.markdown(
70
+ """
71
+ **Note:** Ensure flow rate and velocity are within realistic ranges for best results. 🌟
72
+ Created with ❤️ using [Streamlit](https://streamlit.io).
73
+ """
74
+ )
75
+