|
|
import gradio as gr |
|
|
import requests |
|
|
import matplotlib.pyplot as plt |
|
|
import numpy as np |
|
|
import os |
|
|
|
|
|
import os |
|
|
os.environ["aaa"] = os.environ.get("bbb") |
|
|
ccc= os.environ["aaa"] |
|
|
|
|
|
|
|
|
SUN_IMAGE_PATH = "sun.png" |
|
|
WATER_DROP_IMAGE_PATH = "water_drop.png" |
|
|
|
|
|
|
|
|
def create_sun_image(filepath=SUN_IMAGE_PATH): |
|
|
fig, ax = plt.subplots(figsize=(6, 6), facecolor='none') |
|
|
ax.set_aspect('equal') |
|
|
ax.axis('off') |
|
|
|
|
|
sun_circle = plt.Circle((0, 0), radius=0.8, color='yellow', edgecolor='black') |
|
|
ax.add_patch(sun_circle) |
|
|
|
|
|
num_rays = 20 |
|
|
ray_length = 0.5 |
|
|
|
|
|
for i in range(num_rays): |
|
|
angle = 2 * np.pi * i / num_rays |
|
|
x_start = 0.8 * np.cos(angle) |
|
|
y_start = 0.8 * np.sin(angle) |
|
|
x_end = (0.8 + ray_length) * np.cos(angle) |
|
|
y_end = (0.8 + ray_length) * np.sin(angle) |
|
|
ax.plot([x_start, x_end], [y_start, y_end], color='yellow', linewidth=2) |
|
|
|
|
|
ax.set_xlim([-1.5, 1.5]) |
|
|
ax.set_ylim([-1.5, 1.5]) |
|
|
|
|
|
fig.savefig(filepath, transparent=True, bbox_inches='tight', pad_inches=0) |
|
|
plt.close(fig) |
|
|
|
|
|
|
|
|
def create_water_drop_image(filepath=WATER_DROP_IMAGE_PATH): |
|
|
fig, ax = plt.subplots(figsize=(5, 5), facecolor='none') |
|
|
ax.set_aspect('equal') |
|
|
ax.axis('off') |
|
|
|
|
|
water_drop = plt.Circle((0.5, 0.5), 0.4, color='skyblue', alpha=0.8) |
|
|
ax.add_patch(water_drop) |
|
|
|
|
|
highlight = plt.Circle((0.6, 0.6), 0.15, color='white', alpha=0.6) |
|
|
ax.add_patch(highlight) |
|
|
|
|
|
falling_drop = plt.Circle((0.5, 0.9), 0.05, color='skyblue', alpha=0.6) |
|
|
ax.add_patch(falling_drop) |
|
|
|
|
|
plt.xlim(0, 1) |
|
|
plt.ylim(0, 1) |
|
|
|
|
|
fig.savefig(filepath, transparent=True, bbox_inches='tight', pad_inches=0) |
|
|
plt.close(fig) |
|
|
|
|
|
|
|
|
def ๋นจ๋_์ํ_ํ์ธ(): |
|
|
url = ccc |
|
|
try: |
|
|
response = requests.get(url) |
|
|
response.raise_for_status() |
|
|
humidity_str = response.text.strip() |
|
|
humidity = float(humidity_str) |
|
|
|
|
|
if humidity <= 55: |
|
|
return SUN_IMAGE_PATH, "<font size='6'><b>๋นจ๋๊ฐ ๋ค ๋ง๋์ต๋๋ค!</b></font>" |
|
|
else: |
|
|
return WATER_DROP_IMAGE_PATH, "<font size='6' color='red'><b>์์ง ๋นจ๋๊ฐ ๋ง๋ฅด์ง ์์์ต๋๋ค!</b></font>" |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
return None, f"์์ฒญ ์ค๋ฅ ๋ฐ์: {e}" |
|
|
except ValueError: |
|
|
return None, "์ค๋ฅ: Blynk ์๋ต์ด ์ซ์๊ฐ ์๋๋๋ค." |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("## ๋นจ๋ ๊ฑด์กฐ ์ํ ํ์ธ") |
|
|
image_output = gr.Image(interactive=False) |
|
|
text_output = gr.Markdown() |
|
|
|
|
|
|
|
|
if not os.path.exists(SUN_IMAGE_PATH): |
|
|
create_sun_image() |
|
|
if not os.path.exists(WATER_DROP_IMAGE_PATH): |
|
|
create_water_drop_image() |
|
|
|
|
|
demo.load(๋นจ๋_์ํ_ํ์ธ, outputs=[image_output, text_output]) |
|
|
|
|
|
demo.launch() |