Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,90 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import sched
|
| 4 |
-
from datetime import datetime
|
| 5 |
-
import logging
|
| 6 |
-
|
| 7 |
-
# ๋ก๊ทธ ์ค์
|
| 8 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 9 |
-
|
| 10 |
-
# ์ค์ผ์ค๋ฌ ์ด๊ธฐํ
|
| 11 |
-
s = sched.scheduler(time.time, time.sleep)
|
| 12 |
-
|
| 13 |
-
# URL ๋ฆฌ์คํธ (์ด 100๊ฐ์ URL์ด ์๋ค๊ณ ๊ฐ์ )
|
| 14 |
-
urls = [
|
| 15 |
-
"https://fantaxy-timer1.hf.space",
|
| 16 |
-
|
| 17 |
-
# ์ฌ๊ธฐ์ ์ถ๊ฐ URL์ ์ถ๊ฐํ์ธ์
|
| 18 |
-
]
|
| 19 |
-
|
| 20 |
-
# URL์ ์ ์์ ์๋ํ๋ ํจ์
|
| 21 |
-
def check_url(url):
|
| 22 |
try:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
def
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
logging.info("๋ค์ ์คํ์ด ์์ฝ๋์์ต๋๋ค.")
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 1 |
+
# ๋น๋๊ธฐ์ ์ผ๋ก ์ธ๋ถ URL์ ์ ์ํ๋ ํจ์๋ฅผ ์ ์ํฉ๋๋ค.
|
| 2 |
+
async def check_connection(url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
try:
|
| 4 |
+
async with aiohttp.ClientSession() as session:
|
| 5 |
+
async with session.get(url) as response:
|
| 6 |
+
status = f"URL: {url} ์ํ ์ฝ๋: {response.status}, ์ ์ ์ํ: {'์ ์ ์ฑ๊ณต' if response.status == 200 else '์ ์ ์คํจ'}"
|
| 7 |
+
print(status)
|
| 8 |
+
return status
|
| 9 |
+
except Exception as e:
|
| 10 |
+
status = f"URL: {url} ์ ์ ์คํจ: {str(e)}"
|
| 11 |
+
print(status)
|
| 12 |
+
return status
|
| 13 |
+
|
| 14 |
+
# ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก ๋น๋๊ธฐ ํจ์๋ฅผ ๋ฐ๋ณต ์คํํฉ๋๋ค.
|
| 15 |
+
async def start_timer(urls, interval):
|
| 16 |
+
while True:
|
| 17 |
+
for url in urls:
|
| 18 |
+
if url: # URL์ด ๋น์ด ์์ง ์์ผ๋ฉด ์ฒดํฌ
|
| 19 |
+
await check_connection(url)
|
| 20 |
+
await asyncio.sleep(1) # ๊ฐ URL ์ฒดํฌ ํ 1์ด ๋๊ธฐ
|
| 21 |
+
await asyncio.sleep(interval - len(urls)) # ๋ชจ๋ URL ์ฒดํฌ ํ interval์์ ์ด๋ฏธ ์๋น๋ ์๊ฐ์ ๋บ ๋งํผ ๋๊ธฐ
|
| 22 |
|
| 23 |
+
# ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์
๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค.
|
| 24 |
+
def setup_timer(interval, *urls):
|
| 25 |
+
interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ
|
| 26 |
+
# ๋น๋๊ธฐ ์์
์ ๋ณ๋์ ์ค๋ ๋์์ ์คํ
|
| 27 |
+
threading.Thread(target=asyncio.run, args=(start_timer(urls, interval_seconds),)).start()
|
| 28 |
+
return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค."
|
| 29 |
|
| 30 |
+
# Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
| 31 |
+
url_inputs = [gr.Text(label=f"URL {i+1}", placeholder=f"์ ์ํ URL {i+1}์ ์
๋ ฅํ์ธ์") for i in range(40)]
|
| 32 |
+
interval_input = gr.Slider(minimum=1, maximum=60, step=1, value=5, label="์ ์ ์ฃผ๊ธฐ(๋ถ)")
|
|
|
|
| 33 |
|
| 34 |
+
# Gradio ์ฑ ์ค์
|
| 35 |
+
app = gr.Interface(
|
| 36 |
+
fn=setup_timer,
|
| 37 |
+
inputs=[interval_input] + url_inputs,
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="URL ์ ์ ์ฒด์ปค",
|
| 40 |
+
description="์ต๋ 40๊ฐ์ URL๊ณผ ์ ์ ์ฃผ๊ธฐ๋ฅผ ์
๋ ฅํ๊ณ '์์' ๋ฒํผ์ ํด๋ฆญํ์ธ์. ์ง์ ๋ ์ฃผ๊ธฐ๋ก HTTP ์ํ ์ฝ๋ ๋ฐ ์ ์ ์ํ๋ฅผ ํ์ธํฉ๋๋ค.",
|
| 41 |
+
examples=[
|
| 42 |
+
[
|
| 43 |
+
15,
|
| 44 |
+
"https://fantaxy-timer1.hf.space",
|
| 45 |
+
"https://seawolf2357-FastGPT.hf.space",
|
| 46 |
+
"https://seawolf2357-NaverTalk.hf.space",
|
| 47 |
+
"https://seawolf2357-timer.hf.space",
|
| 48 |
+
"https://seawolf2357-kai-pluting.hf.space",
|
| 49 |
+
"https://seawolf2357-kai-chatbot.hf.space",
|
| 50 |
+
"https://seawolf2357-kai-girlfriend.hf.space",
|
| 51 |
+
"https://seawolf2357-kai-boyfriend.hf.space",
|
| 52 |
+
"https://seawolf2357-kai-grandma.hf.space",
|
| 53 |
+
"https://seawolf2357-kai-simsime.hf.space",
|
| 54 |
+
"https://seawolf2357-kai-blog.hf.space",
|
| 55 |
+
"https://seawolf2357-kai-anak.hf.space",
|
| 56 |
+
"https://seawolf2357-kai-trans.hf.space",
|
| 57 |
+
"https://seawolf2357-kai-sum.hf.space",
|
| 58 |
+
"https://seawolf2357-kai-l3-70b.hf.space",
|
| 59 |
+
"https://seawolf2357-kai-l3-8b.hf.space",
|
| 60 |
+
"https://seawolf2357-kai-aya23-35B.hf.space",
|
| 61 |
+
"https://seawolf2357-kai-law.hf.space",
|
| 62 |
+
"https://seawolf2357-kai-law2.hf.space",
|
| 63 |
+
"https://seawolf2357-kai-zephyr.hf.space",
|
| 64 |
+
"https://seawolf2357-kai-mistral.hf.space",
|
| 65 |
+
"https://seawolf2357-kai-commu-dc.hf.space",
|
| 66 |
+
"https://seawolf2357-kai-commu-1253181097311731712.hf.space",
|
| 67 |
+
"https://seawolf2357-kai-commu-1253181128152449075.hf.space",
|
| 68 |
+
"https://ginipick-kai-commu-1253181193180942367.hf.space",
|
| 69 |
+
"https://ginipick-kai-commu-1253181193180942367.hf.space",
|
| 70 |
+
"https://ginipick-kai-commu-1253181238676557884.hf.space",
|
| 71 |
+
"https://ginipick-kai-commu-1253181258561884161.hf.space",
|
| 72 |
+
"https://ginipick-kai-commu-1253181305739411567.hf.space",
|
| 73 |
+
"https://ginipick-kai-commu-1253181326060949585.hf.space",
|
| 74 |
+
"https://ginipick-kai-commu-1253181359371980892.hf.space",
|
| 75 |
+
"https://ginipick-kai-commu-1253181380091973715.hf.space",
|
| 76 |
+
"https://ginipick-kai-commu-1253181427605045329.hf.space",
|
| 77 |
+
"https://ginipick-kai-commu-1253181449008320553.hf.space",
|
| 78 |
+
"https://ginipick-kai-commu-1253181487818211348.hf.space",
|
| 79 |
+
"https://ginipick-kai-commu-1253181517593837568.hf.space",
|
| 80 |
+
"https://ginipick-kai-commu-1253181557233946665.hf.space",
|
| 81 |
+
"https://ginipick-kai-commu-1253181575252803634.hf.space",
|
| 82 |
+
"https://ginipick-kai-commu-1253181626750341141.hf.space",
|
| 83 |
+
"https://fantaxy-kai-tts.hf.space"
|
| 84 |
+
]
|
| 85 |
+
],
|
| 86 |
+
cache_examples=False # ์บ์ ๋นํ์ฑํ
|
| 87 |
+
)
|
| 88 |
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
app.launch()
|