ahmad123445 commited on
Commit
0b6c6e6
·
verified ·
1 Parent(s): 6d07cec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -28
app.py CHANGED
@@ -1,19 +1,19 @@
1
  import streamlit as st
2
 
3
  # Function to calculate pump parameters
4
- def calculate_parameters(option, flow_rate, head, density, efficiency, speed, impeller_diameter, height):
5
  try:
6
- flow_rate = float(flow_rate) # m³/h
7
- head = float(head) # meters
8
- density = float(density) # kg/m³
9
- efficiency = float(efficiency) / 100 # Percentage to decimal
10
- speed = float(speed) # RPM
11
- impeller_diameter = float(impeller_diameter) # meters
12
- height = float(height) # meters
13
-
14
  g = 9.81 # Gravitational acceleration (m/s²)
15
-
16
- # Initialize results
 
 
 
 
 
 
 
 
17
  result = {}
18
 
19
  if option == "Hydraulic Power":
@@ -54,16 +54,6 @@ st.title("Pump Design and Performance Calculator")
54
  st.subheader("Developed by Ahmad Hassan")
55
  st.caption("Supervised by Dr. Hidayatullah Mahar")
56
 
57
- # Input Section
58
- st.header("Input Parameters")
59
- flow_rate = st.text_input("Flow Rate (m³/h):", "100")
60
- head = st.text_input("Head (meters):", "50")
61
- density = st.text_input("Fluid Density (kg/m³):", "1000")
62
- efficiency = st.text_input("Pump Efficiency (%):", "75")
63
- speed = st.text_input("Pump Speed (RPM):", "2900")
64
- impeller_diameter = st.text_input("Impeller Diameter (meters):", "0.3")
65
- height = st.text_input("Transport Height (meters):", "10")
66
-
67
  # Dropdown Menu for Quantity to Calculate
68
  st.header("Select Quantity to Calculate")
69
  calculation_option = st.selectbox(
@@ -77,11 +67,38 @@ calculation_option = st.selectbox(
77
  ]
78
  )
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  # Button to Calculate
81
  if st.button("Calculate"):
82
- result = calculate_parameters(
83
- calculation_option, flow_rate, head, density, efficiency, speed, impeller_diameter, height
84
- )
85
  if isinstance(result, dict):
86
  st.success("Calculation Results:")
87
  for key, value in result.items():
@@ -93,9 +110,9 @@ if st.button("Calculate"):
93
  st.info(
94
  """
95
  ### Notes:
96
- - **Flow Rate**: Volume of fluid pumped per hour.
97
- - **Head**: Pressure increase produced by the pump.
98
- - **Efficiency**: Mechanical efficiency of the pump.
99
- - **Pump Specifications for Height**: Estimates specifications required to transport fluid to a given height.
100
  """
101
  )
 
1
  import streamlit as st
2
 
3
  # Function to calculate pump parameters
4
+ def calculate_parameters(option, inputs):
5
  try:
 
 
 
 
 
 
 
 
6
  g = 9.81 # Gravitational acceleration (m/s²)
7
+
8
+ # Extract relevant inputs
9
+ flow_rate = float(inputs.get("Flow Rate", 0)) # m³/h
10
+ head = float(inputs.get("Head", 0)) # meters
11
+ density = float(inputs.get("Density", 0)) # kg/m³
12
+ efficiency = float(inputs.get("Efficiency", 0)) / 100 # % to decimal
13
+ speed = float(inputs.get("Speed", 0)) # RPM
14
+ impeller_diameter = float(inputs.get("Impeller Diameter", 0)) # meters
15
+ height = float(inputs.get("Height", 0)) # meters
16
+
17
  result = {}
18
 
19
  if option == "Hydraulic Power":
 
54
  st.subheader("Developed by Ahmad Hassan")
55
  st.caption("Supervised by Dr. Hidayatullah Mahar")
56
 
 
 
 
 
 
 
 
 
 
 
57
  # Dropdown Menu for Quantity to Calculate
58
  st.header("Select Quantity to Calculate")
59
  calculation_option = st.selectbox(
 
67
  ]
68
  )
69
 
70
+ # Dynamic Input Fields Based on Selection
71
+ inputs = {}
72
+
73
+ if calculation_option == "Hydraulic Power":
74
+ inputs["Flow Rate"] = st.text_input("Flow Rate (m³/h):", "100")
75
+ inputs["Head"] = st.text_input("Head (meters):", "50")
76
+ inputs["Density"] = st.text_input("Fluid Density (kg/m³):", "1000")
77
+
78
+ elif calculation_option == "Input Power":
79
+ inputs["Flow Rate"] = st.text_input("Flow Rate (m³/h):", "100")
80
+ inputs["Head"] = st.text_input("Head (meters):", "50")
81
+ inputs["Density"] = st.text_input("Fluid Density (kg/m³):", "1000")
82
+ inputs["Efficiency"] = st.text_input("Pump Efficiency (%):", "75")
83
+
84
+ elif calculation_option == "Efficiency":
85
+ inputs["Flow Rate"] = st.text_input("Flow Rate (m³/h):", "100")
86
+ inputs["Head"] = st.text_input("Head (meters):", "50")
87
+ inputs["Density"] = st.text_input("Fluid Density (kg/m³):", "1000")
88
+ inputs["Efficiency"] = st.text_input("Actual Efficiency (%):", "70")
89
+
90
+ elif calculation_option == "Impeller Speed":
91
+ inputs["Head"] = st.text_input("Head (meters):", "50")
92
+ inputs["Impeller Diameter"] = st.text_input("Impeller Diameter (meters):", "0.3")
93
+ inputs["Speed"] = st.text_input("Pump Speed (RPM):", "2900")
94
+
95
+ elif calculation_option == "Pump Specifications for Height":
96
+ inputs["Height"] = st.text_input("Transport Height (meters):", "10")
97
+ inputs["Density"] = st.text_input("Fluid Density (kg/m³):", "1000")
98
+
99
  # Button to Calculate
100
  if st.button("Calculate"):
101
+ result = calculate_parameters(calculation_option, inputs)
 
 
102
  if isinstance(result, dict):
103
  st.success("Calculation Results:")
104
  for key, value in result.items():
 
110
  st.info(
111
  """
112
  ### Notes:
113
+ - Relevant inputs will appear dynamically based on the selected parameter.
114
+ - For example:
115
+ - To calculate Hydraulic Power, you need Flow Rate, Head, and Density.
116
+ - To calculate Impeller Speed, you need Head, Impeller Diameter, and Speed.
117
  """
118
  )