Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,16 @@
|
|
| 1 |
import time
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# ----- κ³ μ κΈ°λ³Έκ°
|
| 5 |
DEFAULTS = dict(
|
| 6 |
-
Hn=8.0,
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
rho=1000.0,
|
| 12 |
-
g=9.80665
|
| 13 |
)
|
| 14 |
|
| 15 |
-
#
|
| 16 |
def electrical_power_kw(Q, H, eta, rho=DEFAULTS["rho"], g=DEFAULTS["g"]):
|
| 17 |
if Q <= 0 or H <= 0 or eta <= 0:
|
| 18 |
return 0.0
|
|
@@ -29,10 +27,8 @@ def efficiency_from_relative_flow(r):
|
|
| 29 |
return 0.0
|
| 30 |
|
| 31 |
def decide_mode(Q, Qn, rain, dp, soc, rain_thr, dp_limit, soc_limit):
|
| 32 |
-
# μ λΉ μ°μ
|
| 33 |
if (dp is not None and dp > dp_limit) or (soc is not None and soc >= soc_limit):
|
| 34 |
return "μ λΉ"
|
| 35 |
-
# μ λ κΈ°λ° λͺ¨λ
|
| 36 |
if Q < 0.4*Qn:
|
| 37 |
return "μ μ λ"
|
| 38 |
if (Q > 1.2*Qn) or (rain >= rain_thr):
|
|
@@ -77,13 +73,12 @@ def mode_badge(mode:str)->str:
|
|
| 77 |
<span style="font-size:18px">{icon}</span><span>{'μ λΉ λͺ¨λ' if mode=='μ λΉ' else 'μ΄μ λͺ¨λ : '+mode}</span>
|
| 78 |
</div>"""
|
| 79 |
|
| 80 |
-
# --- λ ν¬κ² 보μ΄λλ‘ λλ κ²μ΄μ§ νλ ---
|
| 81 |
def donut(label:str, value:float, maxv:float, unit:str=""):
|
| 82 |
disp_val = round(float(value), 1)
|
| 83 |
maxv = max(1e-6, float(maxv))
|
| 84 |
pct = max(0.0, min(float(value)/maxv, 1.0))
|
| 85 |
|
| 86 |
-
size = 220
|
| 87 |
r = 86
|
| 88 |
stroke = 18
|
| 89 |
C = 2*3.14159*r
|
|
@@ -155,14 +150,14 @@ def _evaluate(Q_in, rain_mm, dp_kpa, soc_pct,
|
|
| 155 |
f"- νμ¬ μ λ Q: {Q_in:.1f} mΒ³/s (κΈ°μ€ Qβ={Qn:.1f})\n"
|
| 156 |
f"- κ°μλ: {rain_mm:.1f} mm/24h (νμ© {rain_thr:.1f})\n"
|
| 157 |
f"- νΈλμλ: {dp_kpa:.1f} kPa (νμ© {dp_limit:.1f})\n"
|
| 158 |
-
f"- ESS
|
| 159 |
f"βΆ {st['note']}")
|
| 160 |
|
| 161 |
panel = f"""<div style="display:flex;flex-direction:column;gap:18px">{header}{donuts}{chips}</div>"""
|
| 162 |
extra = action_box(mode)
|
| 163 |
return summary, panel, extra
|
| 164 |
|
| 165 |
-
#
|
| 166 |
def run(Q_in, rain_mm, dp_kpa, soc_pct):
|
| 167 |
try:
|
| 168 |
Q_in=float(Q_in); rain_mm=float(rain_mm); dp_kpa=float(dp_kpa); soc_pct=float(soc_pct)
|
|
@@ -197,46 +192,45 @@ def autoplay():
|
|
| 197 |
yield (Q, rain, dp, soc, md, panel, extra)
|
| 198 |
time.sleep(2.0)
|
| 199 |
|
| 200 |
-
#
|
| 201 |
with gr.Blocks(theme=gr.themes.Soft(), title="μμλ ₯ μ€λ§νΈ μ΄μ λͺ¨λ λμ보λ") as app:
|
| 202 |
-
# μ½κ°μ μ μ μ€νμΌ(μ°μΈ‘ μΆλ ₯ κ°λ
μ± β)
|
| 203 |
gr.HTML("""
|
| 204 |
<style>
|
| 205 |
-
.gradio-container {max-width:
|
| 206 |
-
.
|
|
|
|
|
|
|
| 207 |
</style>
|
| 208 |
""")
|
| 209 |
-
|
| 210 |
gr.Markdown("## π μμλ ₯ μ€λ§νΈ μ΄μ λͺ¨λ λμ보λ")
|
| 211 |
|
| 212 |
with gr.Row():
|
| 213 |
-
#
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
Q_in = gr.Number(label="μ λ Q (mΒ³/s)", value=2.0)
|
| 216 |
rain = gr.Number(label="κ°μλ (mm/24h)", value=10.0)
|
| 217 |
dp = gr.Number(label="νΈλμλ (kPa)", value=1.0)
|
| 218 |
-
soc = gr.Number(label="
|
| 219 |
-
|
| 220 |
run_btn = gr.Button("βΆ μ€ν", variant="primary")
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
| 232 |
with gr.Column(scale=3):
|
| 233 |
-
out_vis = gr.HTML(elem_classes=["wrap-panel"])
|
| 234 |
-
out_md = gr.Markdown()
|
| 235 |
-
out_extra = gr.HTML()
|
| 236 |
|
| 237 |
-
#
|
| 238 |
-
run_btn.click(fn=run,
|
| 239 |
-
inputs=[Q_in, rain, dp, soc],
|
| 240 |
outputs=[out_md, out_vis, out_extra])
|
| 241 |
|
| 242 |
btn_norm.click(fn=preset_normal_and_run, outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra])
|
|
|
|
| 1 |
import time
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# ----- κ³ μ κΈ°λ³Έκ° -----
|
| 5 |
DEFAULTS = dict(
|
| 6 |
+
Hn=8.0, Qn=3.5,
|
| 7 |
+
rain_thr=40.0,
|
| 8 |
+
dp_limit=3.0,
|
| 9 |
+
soc_limit=90.0,
|
| 10 |
+
rho=1000.0, g=9.80665
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
+
# ===== κ³μ° λ‘μ§ =====
|
| 14 |
def electrical_power_kw(Q, H, eta, rho=DEFAULTS["rho"], g=DEFAULTS["g"]):
|
| 15 |
if Q <= 0 or H <= 0 or eta <= 0:
|
| 16 |
return 0.0
|
|
|
|
| 27 |
return 0.0
|
| 28 |
|
| 29 |
def decide_mode(Q, Qn, rain, dp, soc, rain_thr, dp_limit, soc_limit):
|
|
|
|
| 30 |
if (dp is not None and dp > dp_limit) or (soc is not None and soc >= soc_limit):
|
| 31 |
return "μ λΉ"
|
|
|
|
| 32 |
if Q < 0.4*Qn:
|
| 33 |
return "μ μ λ"
|
| 34 |
if (Q > 1.2*Qn) or (rain >= rain_thr):
|
|
|
|
| 73 |
<span style="font-size:18px">{icon}</span><span>{'μ λΉ λͺ¨λ' if mode=='μ λΉ' else 'μ΄μ λͺ¨λ : '+mode}</span>
|
| 74 |
</div>"""
|
| 75 |
|
|
|
|
| 76 |
def donut(label:str, value:float, maxv:float, unit:str=""):
|
| 77 |
disp_val = round(float(value), 1)
|
| 78 |
maxv = max(1e-6, float(maxv))
|
| 79 |
pct = max(0.0, min(float(value)/maxv, 1.0))
|
| 80 |
|
| 81 |
+
size = 220
|
| 82 |
r = 86
|
| 83 |
stroke = 18
|
| 84 |
C = 2*3.14159*r
|
|
|
|
| 150 |
f"- νμ¬ μ λ Q: {Q_in:.1f} mΒ³/s (κΈ°μ€ Qβ={Qn:.1f})\n"
|
| 151 |
f"- κ°μλ: {rain_mm:.1f} mm/24h (νμ© {rain_thr:.1f})\n"
|
| 152 |
f"- νΈλμλ: {dp_kpa:.1f} kPa (νμ© {dp_limit:.1f})\n"
|
| 153 |
+
f"- ESS μΆ©μ λ₯ : {soc_pct:.1f}% (νμ© {soc_limit:.1f}%)\n\n"
|
| 154 |
f"βΆ {st['note']}")
|
| 155 |
|
| 156 |
panel = f"""<div style="display:flex;flex-direction:column;gap:18px">{header}{donuts}{chips}</div>"""
|
| 157 |
extra = action_box(mode)
|
| 158 |
return summary, panel, extra
|
| 159 |
|
| 160 |
+
# ===== μΈλΆ λ
ΈμΆ ν¨μ =====
|
| 161 |
def run(Q_in, rain_mm, dp_kpa, soc_pct):
|
| 162 |
try:
|
| 163 |
Q_in=float(Q_in); rain_mm=float(rain_mm); dp_kpa=float(dp_kpa); soc_pct=float(soc_pct)
|
|
|
|
| 192 |
yield (Q, rain, dp, soc, md, panel, extra)
|
| 193 |
time.sleep(2.0)
|
| 194 |
|
| 195 |
+
# ===== Gradio UI =====
|
| 196 |
with gr.Blocks(theme=gr.themes.Soft(), title="μμλ ₯ μ€λ§νΈ μ΄μ λͺ¨λ λμ보λ") as app:
|
|
|
|
| 197 |
gr.HTML("""
|
| 198 |
<style>
|
| 199 |
+
.gradio-container {max-width: 1300px !important;}
|
| 200 |
+
.quick-col {min-width: 210px;}
|
| 201 |
+
.quick-col .gr-button {width: 100%;}
|
| 202 |
+
.quick-title {font-weight:700;margin:8px 0 6px 0;}
|
| 203 |
</style>
|
| 204 |
""")
|
|
|
|
| 205 |
gr.Markdown("## π μμλ ₯ μ€λ§νΈ μ΄μ λͺ¨λ λμ보λ")
|
| 206 |
|
| 207 |
with gr.Row():
|
| 208 |
+
# μ’: μ
λ ₯
|
| 209 |
with gr.Column(scale=1):
|
| 210 |
Q_in = gr.Number(label="μ λ Q (mΒ³/s)", value=2.0)
|
| 211 |
rain = gr.Number(label="κ°μλ (mm/24h)", value=10.0)
|
| 212 |
dp = gr.Number(label="νΈλμλ (kPa)", value=1.0)
|
| 213 |
+
soc = gr.Number(label="ESS μΆ©μ λ₯ (%)", value=50.0)
|
|
|
|
| 214 |
run_btn = gr.Button("βΆ μ€ν", variant="primary")
|
| 215 |
|
| 216 |
+
# κ°μ΄λ°: μ¦μ μ€ν ν¨λ
|
| 217 |
+
with gr.Column(scale=1, elem_classes=["quick-col"]):
|
| 218 |
+
gr.Markdown("<div class='quick-title'>β‘ μ¦μ μ€ν</div>")
|
| 219 |
+
btn_norm = gr.Button("μ μ", variant="secondary")
|
| 220 |
+
btn_low = gr.Button("μ μ λ", variant="secondary")
|
| 221 |
+
btn_high = gr.Button("κ³ μ λ", variant="secondary")
|
| 222 |
+
btn_maint = gr.Button("μ λΉ", variant="stop")
|
| 223 |
+
gr.Markdown("<div class='quick-title'>π¬ μλ μμ°</div>")
|
| 224 |
+
demo_btn = gr.Button("μλ μμ°", variant="primary")
|
| 225 |
+
|
| 226 |
+
# μ°: μΆλ ₯
|
| 227 |
with gr.Column(scale=3):
|
| 228 |
+
out_vis = gr.HTML(elem_classes=["wrap-panel"])
|
| 229 |
+
out_md = gr.Markdown()
|
| 230 |
+
out_extra = gr.HTML()
|
| 231 |
|
| 232 |
+
# μ΄λ²€νΈ
|
| 233 |
+
run_btn.click(fn=run, inputs=[Q_in, rain, dp, soc],
|
|
|
|
| 234 |
outputs=[out_md, out_vis, out_extra])
|
| 235 |
|
| 236 |
btn_norm.click(fn=preset_normal_and_run, outputs=[Q_in, rain, dp, soc, out_md, out_vis, out_extra])
|