MuhammadSajid commited on
Commit
6504c55
·
verified ·
1 Parent(s): c1bed7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -15,8 +15,8 @@ def calculate_power_parameters(voltage, current, power_factor):
15
  power_factor (float): Power factor (0.0 to 1.0).
16
 
17
  Returns:
18
- dict: A dictionary containing the calculated apparent, real, and reactive power,
19
- and calculated power factor. Returns None if input is invalid.
20
  """
21
  if voltage > 0 and current > 0:
22
  # Apparent Power (VA) for Three-Phase
@@ -38,11 +38,13 @@ def calculate_power_parameters(voltage, current, power_factor):
38
  "apparent_power": round(apparent_power, 2),
39
  "real_power": round(real_power, 2),
40
  "reactive_power": round(reactive_power, 2),
41
- "calculated_pf": round(calculated_pf, 2),
42
  }
43
  else:
44
  return None
45
 
 
 
46
  def design_capacitor_bank(reactive_power, num_caps):
47
  """
48
  Designs a capacitor bank to compensate for reactive power.
@@ -92,6 +94,8 @@ def design_capacitor_bank(reactive_power, num_caps):
92
  return {"message": "Could not find a suitable combination with the given number of capacitors."}
93
  else:
94
  return None
 
 
95
  def three_phase_power_calculator(voltage, current, power_factor, frequency):
96
  """
97
  Main function to calculate power parameters and design capacitor bank.
@@ -103,7 +107,7 @@ def three_phase_power_calculator(voltage, current, power_factor, frequency):
103
  frequency (int): Selected frequency.
104
 
105
  Returns:
106
- tuple: Tuple containing output for the four output components
107
  """
108
  # 1. Perform electrical calculations
109
  power_results = calculate_power_parameters(voltage, current, power_factor)
@@ -130,11 +134,7 @@ def three_phase_power_calculator(voltage, current, power_factor, frequency):
130
  [f"🔹 Capacitor {idx + 1}: **{cap}**" for idx, cap in enumerate(cap_bank_design['suggested_capacitors'])]
131
  )
132
  cap_bank_message = cap_bank_design['message']
133
- total_kvar = cap_bank_design['total_kvar']
134
- if 'mismatch' in cap_bank_design and cap_bank_design['mismatch']:
135
- total_kvar_out = f"<span style='color:red;'>{cap_bank_design['message']}</span>"
136
- else:
137
- total_kvar_out = f"{cap_bank_design['message']}"
138
  else:
139
  suggested_capacitors_text = "Could not find a suitable combination."
140
  cap_bank_message = ""
@@ -146,19 +146,7 @@ def three_phase_power_calculator(voltage, current, power_factor, frequency):
146
 
147
  return apparent_power_out, real_power_out, reactive_power_out, calculated_pf_out, suggested_capacitors_text, total_kvar_out, cap_bank_message
148
 
149
- def about_tab():
150
- """
151
- Function for About tab
152
- """
153
- about_text = """
154
- This app is designed for engineers and manufacturers to:
155
- - Calculate three-phase system parameters
156
- - Estimate reactive power
157
- - Design capacitor banks based on user preferences
158
- ---
159
- **Developed by:** Muhendis & ChatGPT 🚀
160
- """
161
- return about_text
162
 
163
  # Create Gradio interface
164
  iface = gr.Interface(
@@ -183,7 +171,7 @@ iface = gr.Interface(
183
  allow_flagging=False,
184
  examples=[
185
  [400, 100, 0.8, 50], # Example 1
186
- [220, 50, 0.95, 60], # Example 2
187
  [415, 120, 0.75, 50]
188
  ]
189
  )
 
15
  power_factor (float): Power factor (0.0 to 1.0).
16
 
17
  Returns:
18
+ dict: A dictionary containing the calculated apparent, real, and reactive power.
19
+ Returns None if input is invalid.
20
  """
21
  if voltage > 0 and current > 0:
22
  # Apparent Power (VA) for Three-Phase
 
38
  "apparent_power": round(apparent_power, 2),
39
  "real_power": round(real_power, 2),
40
  "reactive_power": round(reactive_power, 2),
41
+ "calculated_pf": round(calculated_pf, 2)
42
  }
43
  else:
44
  return None
45
 
46
+
47
+
48
  def design_capacitor_bank(reactive_power, num_caps):
49
  """
50
  Designs a capacitor bank to compensate for reactive power.
 
94
  return {"message": "Could not find a suitable combination with the given number of capacitors."}
95
  else:
96
  return None
97
+
98
+
99
  def three_phase_power_calculator(voltage, current, power_factor, frequency):
100
  """
101
  Main function to calculate power parameters and design capacitor bank.
 
107
  frequency (int): Selected frequency.
108
 
109
  Returns:
110
+ tuple: Tuple containing output for the components
111
  """
112
  # 1. Perform electrical calculations
113
  power_results = calculate_power_parameters(voltage, current, power_factor)
 
134
  [f"🔹 Capacitor {idx + 1}: **{cap}**" for idx, cap in enumerate(cap_bank_design['suggested_capacitors'])]
135
  )
136
  cap_bank_message = cap_bank_design['message']
137
+ total_kvar_out = f"{cap_bank_design['message']}"
 
 
 
 
138
  else:
139
  suggested_capacitors_text = "Could not find a suitable combination."
140
  cap_bank_message = ""
 
146
 
147
  return apparent_power_out, real_power_out, reactive_power_out, calculated_pf_out, suggested_capacitors_text, total_kvar_out, cap_bank_message
148
 
149
+
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  # Create Gradio interface
152
  iface = gr.Interface(
 
171
  allow_flagging=False,
172
  examples=[
173
  [400, 100, 0.8, 50], # Example 1
174
+ [220, 50, 0.95, 60], # Example 2
175
  [415, 120, 0.75, 50]
176
  ]
177
  )