Update app.py
Browse files
app.py
CHANGED
|
@@ -1,284 +1,137 @@
|
|
| 1 |
-
import time
|
| 2 |
import gradio as gr
|
| 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 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
return "์ ์"
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if mode == "๊ณ ์ ๋":
|
| 44 |
-
curtail = bypass = dumpload = True
|
| 45 |
-
vane = gate = max(20.0, vane - 20.0)
|
| 46 |
-
p *= 0.6
|
| 47 |
-
soc_low, soc_high = 35, 45
|
| 48 |
-
|
| 49 |
elif mode == "์ ์ ๋":
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
dumpload = False
|
| 59 |
-
vane = gate = 0.0
|
| 60 |
eta = 0.0
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
#
|
| 73 |
-
return """
|
| 74 |
-
<div style="display:flex;align-items:center;gap:10px;">
|
| 75 |
-
<svg width="28" height="28" viewBox="0 0 64 64" aria-label="๊ฒฝ๊ณ ">
|
| 76 |
-
<polygon points="32,6 58,54 6,54" fill="#ef4444" stroke="#b91c1c" stroke-width="3"/>
|
| 77 |
-
<rect x="30" y="22" width="4" height="18" fill="#ffffff" rx="2"/>
|
| 78 |
-
<circle cx="32" cy="46" r="3" fill="#ffffff"/>
|
| 79 |
-
</svg>
|
| 80 |
-
<span style="color:#ef4444;font-weight:900;font-size:18px;">๋น์ ๋ชจ๋</span>
|
| 81 |
-
</div>
|
| 82 |
-
"""
|
| 83 |
-
|
| 84 |
-
def mode_badge(mode:str)->str:
|
| 85 |
-
if mode == "๋น์":
|
| 86 |
-
return emergency_svg_badge()
|
| 87 |
-
color = {"์ ์":"#22c55e","์ ์ ๋":"#eab308","๊ณ ์ ๋":"#f97316"}.get(mode,"#6b7280")
|
| 88 |
-
label = f"์ด์ ๋ชจ๋ : {mode}"
|
| 89 |
-
return f"""
|
| 90 |
-
<div style="padding:12px 16px;border-radius:14px;background:{color};
|
| 91 |
-
color:#fff;font-weight:800;display:inline-flex;gap:8px;align-items:center;">
|
| 92 |
-
<span style="font-size:18px">โ</span>
|
| 93 |
-
<span style="font-size:18px">{label}</span>
|
| 94 |
-
</div>
|
| 95 |
-
"""
|
| 96 |
-
|
| 97 |
-
def donut(label:str, value:float, maxv:float, unit:str=""):
|
| 98 |
-
maxv = max(1e-9, maxv)
|
| 99 |
-
pct = max(0.0, min(value/maxv, 1.0))
|
| 100 |
-
r = 42
|
| 101 |
-
C = 2*3.14159*r
|
| 102 |
-
offset = C * (1 - pct)
|
| 103 |
return f"""
|
| 104 |
-
<div style="
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
stroke-linecap="round" transform="rotate(-90 60 60)"/>
|
| 110 |
-
<text x="60" y="60" text-anchor="middle" dominant-baseline="middle"
|
| 111 |
-
font-size="16" font-weight="700">{value:.1f}{unit}</text>
|
| 112 |
-
</svg>
|
| 113 |
-
<div style="font-size:14px;color:#475569">{label}</div>
|
| 114 |
-
</div>
|
| 115 |
-
"""
|
| 116 |
-
|
| 117 |
-
def chip(label:str, on:bool):
|
| 118 |
-
bg = "#10b981" if on else "#e5e7eb"
|
| 119 |
-
fg = "#fff" if on else "#111827"
|
| 120 |
-
text = "ON" if on else "OFF"
|
| 121 |
-
return f"""
|
| 122 |
-
<div style="padding:6px 10px;border-radius:999px;background:{bg};color:{fg};
|
| 123 |
-
font-size:12px;font-weight:700;display:inline-block;">
|
| 124 |
-
{label}: {text}
|
| 125 |
-
</div>
|
| 126 |
-
"""
|
| 127 |
-
|
| 128 |
-
def gauge_bar(label:str, value:float, maxv:float, unit:str=""):
|
| 129 |
-
maxv = max(1e-9, maxv)
|
| 130 |
-
pct = int(round(max(0.0, min(value/maxv,1.0))*100))
|
| 131 |
-
return f"""
|
| 132 |
-
<div style="margin:4px 0 10px 0;">
|
| 133 |
-
<div style="font-size:13px;margin-bottom:4px">{label}: <b>{value:.1f}{unit}</b></div>
|
| 134 |
-
<div style="width:100%;height:10px;border-radius:7px;background:#e5e7eb">
|
| 135 |
-
<div style="width:{pct}%;height:10px;border-radius:7px;background:#6366f1"></div>
|
| 136 |
</div>
|
| 137 |
</div>
|
| 138 |
"""
|
| 139 |
|
| 140 |
-
#
|
| 141 |
-
|
|
|
|
|
|
|
| 142 |
try:
|
| 143 |
-
Q_in
|
| 144 |
-
|
| 145 |
-
|
|
|
|
| 146 |
except:
|
| 147 |
-
return "์
๋ ฅ ์ค๋ฅ
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
|
| 152 |
-
q_low, q_high = 0.4*Qn, 1.2*Qn
|
| 153 |
-
mode = decide_mode(Q_in, q_low, q_high, rain_mm, dp_kpa, rain_thr, dp_limit, emergency)
|
| 154 |
-
st = mode_policy(mode, Q_in, Qn, Hn)
|
| 155 |
-
|
| 156 |
-
# ์์ฝ(ํ๊ตญ์ด)
|
| 157 |
summary = (
|
| 158 |
-
f"**
|
| 159 |
-
f"
|
| 160 |
-
f"
|
| 161 |
-
f"
|
| 162 |
-
f"
|
|
|
|
|
|
|
| 163 |
)
|
| 164 |
-
if mode == "๋น์":
|
| 165 |
-
summary += "\n> ๐ด ๋น์: ๋ฐ์ ์ ์ง, ๋ฒ ์ธ/์ทจ์๋ฌธ 0%, ๋ฐ์ดํจ์ค ๊ฐ๋ฐฉ, ์ด์์ ์น์ธ ๋๊ธฐ"
|
| 166 |
|
| 167 |
-
# ์๊ฐ ์นด๋
|
| 168 |
-
p_ref = electrical_power_kw(Qn, Hn, 0.9)
|
| 169 |
-
header = mode_badge(mode)
|
| 170 |
donuts = f"""
|
| 171 |
<div style="display:flex;gap:28px;flex-wrap:wrap;align-items:center">
|
| 172 |
-
{donut("ํจ์จ
|
| 173 |
-
{donut("์ถ๋ ฅ
|
| 174 |
</div>
|
| 175 |
"""
|
| 176 |
-
bars = f"""
|
| 177 |
-
{gauge_bar("๊ฐ์ด๋๋ฒ ์ธ ๊ฐ๋", st['vane'], 100.0, " %")}
|
| 178 |
-
{gauge_bar("์ทจ์๋ฌธ ๊ฐ๋", st['gate'], 100.0, " %")}
|
| 179 |
-
"""
|
| 180 |
-
chips = f"""
|
| 181 |
-
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
| 182 |
-
{chip("์ถ๋ ฅ ์ ํ", st['curtail'])}
|
| 183 |
-
{chip("๋ฐ์ดํจ์ค", st['bypass'])}
|
| 184 |
-
{chip("๋คํ๋ก๋", st['dumpload'])}
|
| 185 |
-
<div style="padding:6px 10px;border-radius:999px;background:#0ea5e9;color:#fff;font-size:12px;font-weight:700">
|
| 186 |
-
ESS SoC ๋ชฉํ: {st['soc_low']}โ{st['soc_high']}%
|
| 187 |
-
</div>
|
| 188 |
-
</div>
|
| 189 |
-
"""
|
| 190 |
-
|
| 191 |
-
# ๋น์ ๋ชจ๋ ํต์ฌ ๋์(์์ 5๊ฐ) โ ๋น์์ผ ๋๋ง ๋
ธ์ถ
|
| 192 |
-
emergency_actions_html = ""
|
| 193 |
-
if mode == "๋น์":
|
| 194 |
-
emergency_actions_html = """
|
| 195 |
-
<div style="margin-top:8px;padding:10px 12px;border:1px solid #fecaca;border-radius:10px;background:#fef2f2">
|
| 196 |
-
<div style="font-weight:800;color:#b91c1c;margin-bottom:6px">๋น์ ๋ชจ๋ ํต์ฌ ๋์</div>
|
| 197 |
-
<ul style="margin:0 0 0 16px; padding:0; color:#7f1d1d">
|
| 198 |
-
<li><b>๋ฐ์ ์ ์ง</b> (์ถ๋ ฅ 0 kW, ํจ์จ 0)</li>
|
| 199 |
-
<li><b>๊ฐ์ด๋๋ฒ ์ธ 0%</b>, <b>์ทจ์๋ฌธ 0%</b> (๋จ๊ณ์ ๋ซํ)</li>
|
| 200 |
-
<li><b>๋ฐ์ดํจ์ค ๊ฐ๋ฐฉ</b> (์์/ํ ํฌ ์์น ๋ฐฉ์ง)</li>
|
| 201 |
-
<li><b>์ธ๋ฒํฐ ์ฐจ๋จ ๋ฐ DC ๋งํฌ ๋ฐฉ์ </b></li>
|
| 202 |
-
<li><b>๋ก๊ทธ ๊ธฐ๋ก ๋ฐ ์ด์์ ์น์ธ ๋๊ธฐ</b> (๋ณต๊ตฌ ์กฐ๊ฑด ํ์ธ)</li>
|
| 203 |
-
</ul>
|
| 204 |
-
</div>
|
| 205 |
-
"""
|
| 206 |
|
| 207 |
-
|
| 208 |
-
<div style="display:flex;flex-direction:column;gap:14px">
|
| 209 |
-
{header}
|
| 210 |
-
{donuts}
|
| 211 |
-
{bars}
|
| 212 |
-
{chips}
|
| 213 |
-
{emergency_actions_html}
|
| 214 |
-
</div>
|
| 215 |
-
"""
|
| 216 |
-
|
| 217 |
-
return summary, panel, "" # ์ธ ๋ฒ์งธ ์นธ์ ์ฌ์ (์ถ๊ฐ ์ค๋ช
์ฉ)
|
| 218 |
-
|
| 219 |
-
# ===== ํ๋ฆฌ์
=====
|
| 220 |
-
def preset_normal(Qn): Qn=float(Qn); return 0.8*Qn, 10.0, 1.0, False
|
| 221 |
-
def preset_low(Qn): Qn=float(Qn); return 0.3*Qn, 5.0, 0.5, False
|
| 222 |
-
def preset_high(Qn): Qn=float(Qn); return 1.3*Qn, 60.0, 4.0, False
|
| 223 |
-
def preset_emerg(Qn): Qn=float(Qn); return 0.8*Qn, 10.0, 1.0, True
|
| 224 |
-
|
| 225 |
-
# ===== ์๋์ฌ์(๋ฐ๋ชจ) =====
|
| 226 |
-
def autoplay(Qn, Hn, rain_thr, dp_limit):
|
| 227 |
-
steps = [
|
| 228 |
-
("์ ์", preset_normal(Qn)),
|
| 229 |
-
("์ ์ ๋", preset_low(Qn)),
|
| 230 |
-
("๊ณ ์ ๋", preset_high(Qn)),
|
| 231 |
-
("๋น์", preset_emerg(Qn)),
|
| 232 |
-
]
|
| 233 |
-
for name, (Q_in, rain, dp, emer) in steps:
|
| 234 |
-
md, panel, extra = run(Q_in, rain, dp, emer, Hn, Qn, rain_thr, dp_limit)
|
| 235 |
-
yield (Q_in, rain, dp, emer, md, panel, extra)
|
| 236 |
-
time.sleep(1.2)
|
| 237 |
-
|
| 238 |
-
# ===== Gradio UI =====
|
| 239 |
-
with gr.Blocks(theme=gr.themes.Soft(), title="์์๋ ฅ ์ค๋งํธ ์ด์ ๋ชจ๋ ๋์๋ณด๋ (Emergency Enhanced)") as app:
|
| 240 |
-
gr.Markdown("## ๐ ์์๋ ฅ ์ค๋งํธ ์ด์ ๋ชจ๋ ๋์๋ณด๋")
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
with gr.Row():
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
with gr.Accordion("๊ณ ๊ธ ์ค์ (์ค๊ณ/์๊ณ๊ฐ)", open=False):
|
| 250 |
-
with gr.Row():
|
| 251 |
-
Hn = gr.Number(label="์ค๊ณ ๋์ฐจ Hโ (m)", value=8.0)
|
| 252 |
-
Qn = gr.Number(label="์ค๊ณ ์ ๋ Qโ (mยณ/s)", value=3.5)
|
| 253 |
-
with gr.Row():
|
| 254 |
-
rain_thr = gr.Number(label="๊ณ ์ ๋ ํ๋จ ๊ฐ์ฐ ์๊ณ (mm/24h)", value=40.0)
|
| 255 |
-
dp_limit = gr.Number(label="ฮP ์๊ณ (kPa)", value=3.0)
|
| 256 |
-
|
| 257 |
-
with gr.Row():
|
| 258 |
-
gr.Button("ํ๋ฆฌ์
: ์ ์").click(preset_normal, [Qn], [Q_in, rain, dp, emer])
|
| 259 |
-
gr.Button("ํ๋ฆฌ์
: ์ ์ ๋").click(preset_low, [Qn], [Q_in, rain, dp, emer])
|
| 260 |
-
gr.Button("ํ๋ฆฌ์
: ๊ณ ์ ๋").click(preset_high, [Qn], [Q_in, rain, dp, emer])
|
| 261 |
-
gr.Button("ํ๋ฆฌ์
: ๋น์").click(preset_emerg, [Qn], [Q_in, rain, dp, emer])
|
| 262 |
|
| 263 |
-
|
| 264 |
-
demo_btn = gr.Button("๐ฌ ์์ฐ ์๋์ฌ์", variant="secondary")
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
out_extra = gr.HTML()
|
| 270 |
|
| 271 |
-
run_btn.click(
|
| 272 |
-
|
| 273 |
-
inputs=[Q_in, rain, dp, emer, Hn, Qn, rain_thr, dp_limit],
|
| 274 |
-
outputs=[out_md, out_vis, out_extra]
|
| 275 |
-
)
|
| 276 |
-
|
| 277 |
-
demo_btn.click(
|
| 278 |
-
fn=autoplay,
|
| 279 |
-
inputs=[Qn, Hn, rain_thr, dp_limit],
|
| 280 |
-
outputs=[Q_in, rain, dp, emer, out_md, out_vis, out_extra]
|
| 281 |
-
)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
| 283 |
if __name__ == "__main__":
|
| 284 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# ------------------------------
|
| 4 |
+
# ์ค๊ณ ์์
|
| 5 |
+
# ------------------------------
|
| 6 |
+
Hn = 8.0 # ์ค๊ณ ๋์ฐจ (m)
|
| 7 |
+
Qn = 3.5 # ์ค๊ณ ์ ๋ (mยณ/s)
|
| 8 |
+
rain_thr = 40 # ๊ณ ์ ๋ ํ์ ๊ฐ์๋ (mm/24h)
|
| 9 |
+
dp_limit = 3.0 # ํธ๋์๋ ๋งํ ํ๊ณ (kPa)
|
| 10 |
+
soc_limit = 90 # ESS ๊ณผ์ถฉ์ ํ๊ณ (%)
|
| 11 |
+
|
| 12 |
+
PF_TARGET = 0.95 # ๋ชฉํ ์ญ๋ฅ
|
| 13 |
+
RHO = 1000 # ๋ฌผ ๋ฐ๋ (kg/mยณ)
|
| 14 |
+
G = 9.81 # ์ค๋ ฅ๊ฐ์๋ (m/sยฒ)
|
| 15 |
+
|
| 16 |
+
# ------------------------------
|
| 17 |
+
# ์ถ๋ ฅ ๊ณ์ฐ ํจ์
|
| 18 |
+
# ------------------------------
|
| 19 |
+
def electrical_power_kw(Q, H, eta):
|
| 20 |
+
return RHO * G * Q * H * eta / 1000.0
|
| 21 |
+
|
| 22 |
+
# ------------------------------
|
| 23 |
+
# ๋ชจ๋ ํ์ ํจ์
|
| 24 |
+
# ------------------------------
|
| 25 |
+
def decide_mode(Q, rain, dp, soc):
|
| 26 |
+
# ์ ๋น ๋ชจ๋ ์ต์ฐ์ (ํธ๋์๋ ๋งํ, ESS ๊ณผ์ถฉ์ )
|
| 27 |
+
if dp > dp_limit or soc >= soc_limit:
|
| 28 |
+
return "์ ๋น"
|
| 29 |
+
# ์ ์ ๋
|
| 30 |
+
if Q < 0.4 * Qn:
|
| 31 |
+
return "์ ์ ๋"
|
| 32 |
+
# ๊ณ ์ ๋
|
| 33 |
+
if Q > 1.2 * Qn or rain >= rain_thr:
|
| 34 |
+
return "๊ณ ์ ๋"
|
| 35 |
+
# ์ ์
|
| 36 |
return "์ ์"
|
| 37 |
|
| 38 |
+
# ------------------------------
|
| 39 |
+
# ๋ชจ๋๋ณ ๋์ ์ ์ฑ
|
| 40 |
+
# ------------------------------
|
| 41 |
+
def mode_policy(mode, Q, H):
|
| 42 |
+
if mode == "์ ์":
|
| 43 |
+
eta = 0.90
|
| 44 |
+
p_kw = electrical_power_kw(Q, H, eta)
|
| 45 |
+
return {"eta": eta, "p_kw": p_kw, "desc": "์ ์ ์ด์ : ํจ์จ ์ต์ ์ ์์ ๋ฐ์ "}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
elif mode == "์ ์ ๋":
|
| 47 |
+
eta = 0.75
|
| 48 |
+
p_kw = electrical_power_kw(Q, H, eta)
|
| 49 |
+
return {"eta": eta, "p_kw": p_kw, "desc": "์ ์ ๋ ๋ชจ๋: ์ถ๋ ฅ ๊ฐ์, ํจ์จ ์ ํ"}
|
| 50 |
+
elif mode == "๊ณ ์ ๋":
|
| 51 |
+
eta = 0.70
|
| 52 |
+
p_kw = electrical_power_kw(Q, H, eta) * 0.6 # ์ปคํ
์ผ๋ง
|
| 53 |
+
return {"eta": eta, "p_kw": p_kw, "desc": "๊ณ ์ ๋ ๋ชจ๋: ์ถ๋ ฅ ์ ํ, ๋ฐ์ดํจ์ค ๋ณํ"}
|
| 54 |
+
elif mode == "์ ๋น":
|
|
|
|
|
|
|
| 55 |
eta = 0.0
|
| 56 |
+
p_kw = 0.0
|
| 57 |
+
return {"eta": eta, "p_kw": p_kw, "desc": "์ ๋น ๋ชจ๋: ๋ฐ์ ์ค์ง, ์ ๋น ํ์"}
|
| 58 |
+
else:
|
| 59 |
+
return {"eta": 0, "p_kw": 0, "desc": "์ ์ ์๋ ๋ชจ๋"}
|
| 60 |
+
|
| 61 |
+
# ------------------------------
|
| 62 |
+
# ์๊ฐํ ํจ์
|
| 63 |
+
# ------------------------------
|
| 64 |
+
def donut(label, value, max_val, unit=""):
|
| 65 |
+
pct = int((value / max_val) * 100) if max_val > 0 else 0
|
| 66 |
+
if pct > 100: pct = 100
|
| 67 |
+
color = "#16a34a" if pct > 70 else "#facc15" if pct > 40 else "#dc2626"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return f"""
|
| 69 |
+
<div style="width:160px;height:160px;border-radius:50%;border:14px solid {color};
|
| 70 |
+
display:flex;align-items:center;justify-content:center;font-size:18px;
|
| 71 |
+
font-weight:bold;color:#111;">
|
| 72 |
+
<div style="text-align:center">
|
| 73 |
+
{label}<br>{value:.1f}{unit}<br><span style="font-size:14px;color:#666">{pct}%</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
</div>
|
| 75 |
</div>
|
| 76 |
"""
|
| 77 |
|
| 78 |
+
# ------------------------------
|
| 79 |
+
# ์คํ ํจ์
|
| 80 |
+
# ------------------------------
|
| 81 |
+
def run(Q_in, rain_mm, dp_kpa, soc_perc):
|
| 82 |
try:
|
| 83 |
+
Q_in = float(Q_in)
|
| 84 |
+
rain_mm = float(rain_mm)
|
| 85 |
+
dp_kpa = float(dp_kpa)
|
| 86 |
+
soc_perc = float(soc_perc)
|
| 87 |
except:
|
| 88 |
+
return "โ ๏ธ ์
๋ ฅ ์ค๋ฅ", "", ""
|
| 89 |
|
| 90 |
+
mode = decide_mode(Q_in, rain_mm, dp_kpa, soc_perc)
|
| 91 |
+
st = mode_policy(mode, Q_in, Hn)
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
summary = (
|
| 94 |
+
f"**ํ์ฌ ๋ชจ๋**: {mode}\n\n"
|
| 95 |
+
f"- ํ์ฌ ์ ๋ Q: {Q_in:.2f} mยณ/s (์ค๊ณ Qโ={Qn} mยณ/s)\n"
|
| 96 |
+
f"- ๋์ฐจ H: {Hn:.2f} m\n"
|
| 97 |
+
f"- ๊ฐ์๋: {rain_mm:.1f} mm/24h\n"
|
| 98 |
+
f"- ํธ๋์๋ ฮP: {dp_kpa:.1f} kPa\n"
|
| 99 |
+
f"- ESS SoC: {soc_perc:.0f} %\n\n"
|
| 100 |
+
f"โถ {st['desc']}"
|
| 101 |
)
|
|
|
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
| 103 |
donuts = f"""
|
| 104 |
<div style="display:flex;gap:28px;flex-wrap:wrap;align-items:center">
|
| 105 |
+
{donut("ํจ์จ ฮท", st['eta']*100, 100, "%")}
|
| 106 |
+
{donut("์ถ๋ ฅ P", st['p_kw'], 100, " kW")}
|
| 107 |
</div>
|
| 108 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
return summary, donuts, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
# ------------------------------
|
| 113 |
+
# Gradio UI
|
| 114 |
+
# ------------------------------
|
| 115 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 116 |
+
gr.Markdown("## ๐ ์ค๋งํธ ์์๋ ฅ ๋ฐ์ ๋ชจ๋ ์๋ฎฌ๋ ์ดํฐ")
|
| 117 |
with gr.Row():
|
| 118 |
+
Q_in = gr.Number(label="ํ์ฌ ์ ๋ Q (mยณ/s)", value=2.0)
|
| 119 |
+
rain_mm = gr.Number(label="๊ฐ์๋ (mm/24h)", value=10)
|
| 120 |
+
with gr.Row():
|
| 121 |
+
dp_kpa = gr.Number(label="ํธ๋์๋ ฮP (kPa)", value=1.0)
|
| 122 |
+
soc_perc = gr.Number(label="ESS SoC (%)", value=50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
run_btn = gr.Button("์คํ")
|
|
|
|
| 125 |
|
| 126 |
+
summary = gr.Markdown()
|
| 127 |
+
donuts = gr.HTML()
|
| 128 |
+
extra = gr.Markdown()
|
|
|
|
| 129 |
|
| 130 |
+
run_btn.click(fn=run, inputs=[Q_in, rain_mm, dp_kpa, soc_perc],
|
| 131 |
+
outputs=[summary, donuts, extra])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
# ------------------------------
|
| 134 |
+
# ์คํ ์์
|
| 135 |
+
# ------------------------------
|
| 136 |
if __name__ == "__main__":
|
| 137 |
+
demo.launch()
|