Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def λΉ¨λ_μν_νμΈ():
|
| 5 |
+
url = 'https://blynk.cloud/external/api/get?token=F44y9xVfUZZXCqxDGzHpYzGC7ih8yAdI&V0'
|
| 6 |
+
try:
|
| 7 |
+
response = requests.get(url)
|
| 8 |
+
response.raise_for_status() # HTTP μλ¬ λ°μ μ μμΈ μ²λ¦¬
|
| 9 |
+
humidity_str = response.text.strip() # μλ΅ ν
μ€νΈλ₯Ό λ°κ³ μλ€ κ³΅λ°± μ κ±°
|
| 10 |
+
humidity = float(humidity_str) # λ¬Έμμ΄μ μ«μλ‘ λ³ν
|
| 11 |
+
|
| 12 |
+
if humidity <= 55:
|
| 13 |
+
return "λΉ¨λκ° λ€ λ§λμ΅λλ€!"
|
| 14 |
+
else:
|
| 15 |
+
return "μμ§ λΉ¨λκ° λ§λ₯΄μ§ μμμ΅λλ€!"
|
| 16 |
+
|
| 17 |
+
except requests.exceptions.RequestException as e:
|
| 18 |
+
return f"μμ² μ€λ₯ λ°μ: {e}" # μμ² μλ¬ λ©μμ§ νμ
|
| 19 |
+
except ValueError:
|
| 20 |
+
return "μ€λ₯: Blynk μλ΅μ΄ μ«μκ° μλλλ€." # μ«μ λ³ν μλ¬ λ©μμ§ νμ
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# λΉ¨λ 건쑰 μν νμΈ") # μ λͺ©
|
| 24 |
+
output_text = gr.Markdown() # κ²°κ³Ό ν
μ€νΈλ₯Ό νμν Markdown μ»΄ν¬λνΈ
|
| 25 |
+
check_button = gr.Button("λΉ¨λ μν νμΈ") # μν νμΈ λ²νΌ
|
| 26 |
+
check_button.click(fn=λΉ¨λ_μν_νμΈ, outputs=output_text) # λ²νΌ ν΄λ¦ μ λΉ¨λ_μν_νμΈ ν¨μ νΈμΆ λ° κ²°κ³Ό μΆλ ₯
|
| 27 |
+
|
| 28 |
+
demo.launch()
|