Spaces:
Running
Running
seawolf2357
commited on
Commit
โข
4a056c9
1
Parent(s):
be19db7
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import asyncio
|
4 |
import threading
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
try:
|
9 |
-
|
10 |
-
|
11 |
-
status = f"URL: {url} ์ํ ์ฝ๋: {response.status}, ์ ์ ์ํ: {'์ ์ ์ฑ๊ณต' if response.status == 200 else '์ ์ ์คํจ'}"
|
12 |
-
print(status)
|
13 |
-
return status
|
14 |
except Exception as e:
|
15 |
status = f"URL: {url} ์ ์ ์คํจ: {str(e)}"
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
# ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
if url: # URL์ด ๋น์ด ์์ง ์์ผ๋ฉด ์ฒดํฌ
|
24 |
-
await check_connection(url)
|
25 |
-
await asyncio.sleep(1) # ๊ฐ URL ์ฒดํฌ ํ 1์ด ๋๊ธฐ
|
26 |
-
await asyncio.sleep(interval - len(urls)) # ๋ชจ๋ URL ์ฒดํฌ ํ interval์์ ์ด๋ฏธ ์๋น๋ ์๊ฐ์ ๋บ ๋งํผ ๋๊ธฐ
|
27 |
|
28 |
# ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์
๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค.
|
29 |
def setup_timer(interval, *urls):
|
30 |
interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ
|
31 |
-
|
32 |
-
|
|
|
33 |
return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค."
|
34 |
|
35 |
# Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
@@ -89,6 +83,5 @@ app = gr.Interface(
|
|
89 |
],
|
90 |
cache_examples=False # ์บ์ ๋นํ์ฑํ
|
91 |
)
|
|
|
92 |
|
93 |
-
if __name__ == "__main__":
|
94 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
|
|
3 |
import threading
|
4 |
+
import time
|
5 |
|
6 |
+
# ์ธ๋ถ URL์ ์ ์ํ๋ ํจ์๋ฅผ ์ ์ํฉ๋๋ค.
|
7 |
+
def check_connection(url):
|
8 |
try:
|
9 |
+
response = requests.get(url)
|
10 |
+
status = f"URL: {url} ์ํ ์ฝ๋: {response.status_code}, ์ ์ ์ํ: {'์ ์ ์ฑ๊ณต' if response.status_code == 200 else '์ ์ ์คํจ'}"
|
|
|
|
|
|
|
11 |
except Exception as e:
|
12 |
status = f"URL: {url} ์ ์ ์คํจ: {str(e)}"
|
13 |
+
print(status)
|
14 |
+
return status
|
15 |
|
16 |
+
# ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก ํจ์๋ฅผ ๋ฐ๋ณต ์คํํฉ๋๋ค.
|
17 |
+
def start_timer(url, interval):
|
18 |
+
threading.Timer(interval, start_timer, [url, interval]).start()
|
19 |
+
check_connection(url)
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์
๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค.
|
22 |
def setup_timer(interval, *urls):
|
23 |
interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ
|
24 |
+
for url in urls:
|
25 |
+
if url: # URL์ด ๋น์ด ์์ง ์์ผ๋ฉด ํ์ด๋จธ ์์
|
26 |
+
start_timer(url, interval_seconds)
|
27 |
return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค."
|
28 |
|
29 |
# Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
|
|
83 |
],
|
84 |
cache_examples=False # ์บ์ ๋นํ์ฑํ
|
85 |
)
|
86 |
+
app.launch()
|
87 |
|
|
|
|