Aoi785 commited on
Commit
9425479
Β·
verified Β·
1 Parent(s): 3bf2af4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -39
app.py CHANGED
@@ -1,18 +1,16 @@
1
  import time
2
  import gradio as gr
3
 
4
- # ----- κ³ μ • κΈ°λ³Έκ°’(ν™”λ©΄μ—λŠ” λ…ΈμΆœ μ•ˆ 함) -----
5
  DEFAULTS = dict(
6
- Hn=8.0, # κΈ°μ€€ λ‚™μ°¨ (m)
7
- Qn=3.5, # κΈ°μ€€ μœ λŸ‰ (m3/s)
8
- rain_thr=40.0,# κ³ μœ λŸ‰ νŒμ • κ°•μˆ˜λŸ‰ (mm/24h)
9
- dp_limit=3.0, # νŠΈλž˜μ‹œλž™ ν—ˆμš© ν•œκ³„ (kPa) -> μ •λΉ„
10
- soc_limit=90.0, # ESS SoC ν—ˆμš© ν•œκ³„ (%) -> μ •λΉ„
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 μΆ©μ „μƒνƒœ: {soc_pct:.1f}% (ν—ˆμš© {soc_limit:.1f}%)\n\n"
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
- # ====== μ™ΈλΆ€μ—μ„œ ν˜ΈμΆœλ˜λŠ” ν•¨μˆ˜λ“€(화면은 Q/rain/dp/soc만 λ°›μŒ) ======
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
- # ====== Gradio UI (ν•œ ν™”λ©΄, 우츑 좜λ ₯ 크게) ======
201
  with gr.Blocks(theme=gr.themes.Soft(), title="μ†Œμˆ˜λ ₯ 슀마트 μš΄μ „λͺ¨λ“œ λŒ€μ‹œλ³΄λ“œ") as app:
202
- # μ•½κ°„μ˜ μ „μ—­ μŠ€νƒ€μΌ(우츑 좜λ ₯ 가독성 ↑)
203
  gr.HTML("""
204
  <style>
205
- .gradio-container {max-width: 1200px !important;}
206
- .wrap-panel > div {font-size: 16px;}
 
 
207
  </style>
208
  """)
209
-
210
  gr.Markdown("## 🌊 μ†Œμˆ˜λ ₯ 슀마트 μš΄μ „λͺ¨λ“œ λŒ€μ‹œλ³΄λ“œ")
211
 
212
  with gr.Row():
213
- # 쒌츑 μž…λ ₯(ν•„μš”ν•œ 4개만)
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="SoC (%)", value=50.0)
219
-
220
  run_btn = gr.Button("β–Ά μ‹€ν–‰", variant="primary")
221
 
222
- gr.Markdown("πŸ”˜ μ¦‰μ‹œ μ‹€ν–‰")
223
- with gr.Row():
224
- btn_norm = gr.Button("정상", variant="secondary")
225
- btn_low = gr.Button("μ €μœ λŸ‰", variant="secondary")
226
- btn_high = gr.Button("κ³ μœ λŸ‰", variant="secondary")
227
- btn_maint = gr.Button("μ •λΉ„", variant="stop")
228
-
229
- demo_btn = gr.Button("μžλ™ μ‹œμ—°")
230
-
231
- # 우츑 좜λ ₯(더 크게: scale=3)
 
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
- # 바인딩 (μž…λ ₯ 4개만 μ‚¬μš©)
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])