Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import time
|
5 |
|
6 |
-
# ์ธ๋ถ URL์ ์ ์ํ๋ ํจ์๋ฅผ ์ ์ํฉ๋๋ค.
|
7 |
-
def check_connection(url):
|
8 |
try:
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
except Exception as e:
|
12 |
status = f"URL: {url} ์ ์ ์คํจ: {str(e)}"
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
# ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก ํจ์๋ฅผ ๋ฐ๋ณต ์คํํฉ๋๋ค.
|
17 |
-
def start_timer(
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์
๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค.
|
22 |
def setup_timer(interval, *urls):
|
23 |
interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ
|
24 |
-
|
25 |
-
|
26 |
-
start_timer(url, interval_seconds)
|
27 |
return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค."
|
28 |
|
29 |
# Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
@@ -79,9 +84,11 @@ app = gr.Interface(
|
|
79 |
"https://seawolf2357-kai-commu-1253181449008320553.hf.space",
|
80 |
"https://seawolf2357-kai-commu-1253181487818211348.hf.space",
|
81 |
"https://seawolf2357-kai-commu-1253181517593837568.hf.space",
|
82 |
-
"https://seawolf2357-kai-commu-1253181557233946665.hf.space"
|
83 |
]
|
84 |
],
|
85 |
cache_examples=False # ์บ์ ๋นํ์ฑํ
|
86 |
)
|
87 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import aiohttp
|
3 |
+
import asyncio
|
|
|
4 |
|
5 |
+
# ๋น๋๊ธฐ์ ์ผ๋ก ์ธ๋ถ URL์ ์ ์ํ๋ ํจ์๋ฅผ ์ ์ํฉ๋๋ค.
|
6 |
+
async def check_connection(url):
|
7 |
try:
|
8 |
+
async with aiohttp.ClientSession() as session:
|
9 |
+
async with session.get(url) as response:
|
10 |
+
status = f"URL: {url} ์ํ ์ฝ๋: {response.status}, ์ ์ ์ํ: {'์ ์ ์ฑ๊ณต' if response.status == 200 else '์ ์ ์คํจ'}"
|
11 |
+
print(status)
|
12 |
+
return status
|
13 |
except Exception as e:
|
14 |
status = f"URL: {url} ์ ์ ์คํจ: {str(e)}"
|
15 |
+
print(status)
|
16 |
+
return status
|
17 |
|
18 |
+
# ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก ๋น๋๊ธฐ ํจ์๋ฅผ ๋ฐ๋ณต ์คํํฉ๋๋ค.
|
19 |
+
async def start_timer(urls, interval):
|
20 |
+
while True:
|
21 |
+
for url in urls:
|
22 |
+
if url: # URL์ด ๋น์ด ์์ง ์์ผ๋ฉด ์ฒดํฌ
|
23 |
+
await check_connection(url)
|
24 |
+
await asyncio.sleep(1) # ๊ฐ URL ์ฒดํฌ ํ 1์ด ๋๊ธฐ
|
25 |
+
await asyncio.sleep(interval - len(urls)) # ๋ชจ๋ URL ์ฒดํฌ ํ interval์์ ์ด๋ฏธ ์๋น๋ ์๊ฐ์ ๋บ ๋งํผ ๋๊ธฐ
|
26 |
|
27 |
# ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์
๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค.
|
28 |
def setup_timer(interval, *urls):
|
29 |
interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ
|
30 |
+
loop = asyncio.get_event_loop()
|
31 |
+
loop.create_task(start_timer(urls, interval_seconds))
|
|
|
32 |
return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค."
|
33 |
|
34 |
# Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
|
|
84 |
"https://seawolf2357-kai-commu-1253181449008320553.hf.space",
|
85 |
"https://seawolf2357-kai-commu-1253181487818211348.hf.space",
|
86 |
"https://seawolf2357-kai-commu-1253181517593837568.hf.space",
|
87 |
+
"https://seawolf2357-kai-commu-1253181557233946665.hf.space"
|
88 |
]
|
89 |
],
|
90 |
cache_examples=False # ์บ์ ๋นํ์ฑํ
|
91 |
)
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
app.launch()
|