timer / app.py
seawolf2357's picture
Update app.py
1eb1070 verified
raw
history blame
1.8 kB
import gradio as gr
import requests
import threading
import time
# ์™ธ๋ถ€ URL์— ์ ‘์†ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
def check_connection(url):
try:
response = requests.get(url)
status = f"URL: {url} ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}, ์ ‘์† ์ƒํƒœ: {'์ ‘์† ์„ฑ๊ณต' if response.status_code == 200 else '์ ‘์† ์‹คํŒจ'}"
except Exception as e:
status = f"URL: {url} ์ ‘์† ์‹คํŒจ: {str(e)}"
print(status)
return status
# ํƒ€์ด๋จธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ •ํ•ด์ง„ ์ฃผ๊ธฐ๋กœ ํ•จ์ˆ˜๋ฅผ ๋ฐ˜๋ณต ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
def start_timer(url, interval):
threading.Timer(interval, start_timer, [url, interval]).start()
check_connection(url)
# Gradio UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
url_input1 = gr.Text(label="URL 1", placeholder="์ ‘์†ํ•  ์ฒซ ๋ฒˆ์งธ URL์„ ์ž…๋ ฅํ•˜์„ธ์š”")
url_input2 = gr.Text(label="URL 2", placeholder="์ ‘์†ํ•  ๋‘ ๋ฒˆ์งธ URL์„ ์ž…๋ ฅํ•˜์„ธ์š”")
interval_input = gr.Slider(minimum=1, maximum=60, step=1, value=5, label="์ ‘์† ์ฃผ๊ธฐ(๋ถ„)")
# ํƒ€์ด๋จธ ์‹œ์ž‘ ํ•จ์ˆ˜๋ฅผ Gradio์˜ ์ž…๋ ฅ๊ณผ ํ•จ๊ป˜ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
def setup_timer(url1, url2, interval):
interval_seconds = interval * 60 # ๋ถ„์„ ์ดˆ๋กœ ๋ณ€ํ™˜
start_timer(url1, interval_seconds)
start_timer(url2, interval_seconds)
return "ํƒ€์ด๋จธ๊ฐ€ ์„ค์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
# Gradio ์•ฑ ์„ค์ •
app = gr.Interface(
fn=setup_timer,
inputs=[url_input1, url_input2, interval_input],
outputs="text",
title="URL ์ ‘์† ์ฒด์ปค",
description="๋‘ ๊ฐœ์˜ URL๊ณผ ์ ‘์† ์ฃผ๊ธฐ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  '์‹œ์ž‘' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”. ์ง€์ •๋œ ์ฃผ๊ธฐ๋กœ HTTP ์ƒํƒœ ์ฝ”๋“œ ๋ฐ ์ ‘์† ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.",
examples=[
["https://seawolf2357-FastGPT.hf.space", "https://seawolf2357-NaverTalk.hf.space", 5]
]
)
app.launch(share=True)