Download app.py from fantaxy/timer1: direct link, hf CLI and curl.
- Browser
- Download file 4.73 kB
-
https://huggingface.co/spaces/fantaxy/timer1/resolve/main/app.py
- Command line
-
hf download hf://spaces/fantaxy/timer1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fantaxy/timer1/resolve/main/app.py
4.73 kB
| import gradio as gr | |
| import aiohttp | |
| import asyncio | |
| import threading | |
| # ๋น๋๊ธฐ์ ์ผ๋ก ์ธ๋ถ URL์ ์ ์ํ๋ ํจ์๋ฅผ ์ ์ํฉ๋๋ค. | |
| async def check_connection(url): | |
| try: | |
| async with aiohttp.ClientSession() as session: | |
| async with session.get(url) as response: | |
| status = f"URL: {url} ์ํ ์ฝ๋: {response.status}, ์ ์ ์ํ: {'์ ์ ์ฑ๊ณต' if response.status == 200 else '์ ์ ์คํจ'}" | |
| print(status) | |
| return status | |
| except Exception as e: | |
| status = f"URL: {url} ์ ์ ์คํจ: {str(e)}" | |
| print(status) | |
| return status | |
| # ํ์ด๋จธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํด์ง ์ฃผ๊ธฐ๋ก ๋น๋๊ธฐ ํจ์๋ฅผ ๋ฐ๋ณต ์คํํฉ๋๋ค. | |
| async def start_timer(urls, interval): | |
| while True: | |
| for url in urls: | |
| if url: # URL์ด ๋น์ด ์์ง ์์ผ๋ฉด ์ฒดํฌ | |
| await check_connection(url) | |
| await asyncio.sleep(1) # ๊ฐ URL ์ฒดํฌ ํ 1์ด ๋๊ธฐ | |
| await asyncio.sleep(interval - len(urls)) # ๋ชจ๋ URL ์ฒดํฌ ํ interval์์ ์ด๋ฏธ ์๋น๋ ์๊ฐ์ ๋บ ๋งํผ ๋๊ธฐ | |
| # ํ์ด๋จธ ์์ ํจ์๋ฅผ Gradio์ ์ ๋ ฅ๊ณผ ํจ๊ป ์ฐ๊ฒฐํฉ๋๋ค. | |
| def setup_timer(interval, *urls): | |
| interval_seconds = interval * 60 # ๋ถ์ ์ด๋ก ๋ณํ | |
| # ๋น๋๊ธฐ ์์ ์ ๋ณ๋์ ์ค๋ ๋์์ ์คํ | |
| threading.Thread(target=asyncio.run, args=(start_timer(urls, interval_seconds),)).start() | |
| return "ํ์ด๋จธ๊ฐ ์ค์ ๋์์ต๋๋ค." | |
| # Gradio UI ์ปดํฌ๋ํธ๋ฅผ ์ ์ํฉ๋๋ค. | |
| url_inputs = [gr.Text(label=f"URL {i+1}", placeholder=f"์ ์ํ URL {i+1}์ ์ ๋ ฅํ์ธ์") for i in range(40)] | |
| interval_input = gr.Slider(minimum=1, maximum=60, step=1, value=5, label="์ ์ ์ฃผ๊ธฐ(๋ถ)") | |
| # Gradio ์ฑ ์ค์ | |
| app = gr.Interface( | |
| fn=setup_timer, | |
| inputs=[interval_input] + url_inputs, | |
| outputs="text", | |
| title="URL ์ ์ ์ฒด์ปค", | |
| description="์ต๋ 40๊ฐ์ URL๊ณผ ์ ์ ์ฃผ๊ธฐ๋ฅผ ์ ๋ ฅํ๊ณ '์์' ๋ฒํผ์ ํด๋ฆญํ์ธ์. ์ง์ ๋ ์ฃผ๊ธฐ๋ก HTTP ์ํ ์ฝ๋ ๋ฐ ์ ์ ์ํ๋ฅผ ํ์ธํฉ๋๋ค.", | |
| examples=[ | |
| [ | |
| 15, | |
| "https://fantaxy-timer2.hf.space", | |
| "https://fantaxy-kai-llm-chat.hf.space", | |
| "https://fantaxy-kai-llm-chat-speech.hf.space", | |
| "https://fantaxy-kai-llm-blog.hf.space", | |
| "https://ginipick-gini-llm-chatbot-text.hf.space", | |
| "https://ginipick-gini-llm-chat-speech.hf.space", | |
| "https://ginipick-gini-llm-blog.hf.space", | |
| "https://fantaxy-kai-tts.hf.space", | |
| "https://fantaxy-kai-ytb-audio.hf.space", | |
| "https://fantaxy-kai-ytb-blog.hf.space", | |
| "https://fantaxy-kai-girlfriend19.hf.space", | |
| "https://fantaxy-kai-person-lee.hf.space", | |
| "https://fantaxy-kai-person-jobs.hf.space", | |
| "https://fantaxy-kai-person-eins.hf.space", | |
| "https://fantaxy-kai-person-musk.hf.space", | |
| "https://fantaxy-kai-person-hwang.hf.space", | |
| "https://ginipick-kai-commu-1253181171853164544.hf.space", | |
| "https://ginipick-kai-commu-1253181193180942367.hf.space", | |
| "https://ginipick-kai-commu-1253181238676557884.hf.space", | |
| "https://ginipick-kai-commu-1253181258561884161.hf.space", | |
| "https://ginipick-kai-commu-1253181305739411567.hf.space", | |
| "https://ginipick-kai-commu-1253181326060949585.hf.space", | |
| "https://ginipick-kai-commu-1253181359371980892.hf.space", | |
| "https://ginipick-kai-commu-1253181380091973715.hf.space", | |
| "https://ginipick-kai-commu-1253181427605045329.hf.space", | |
| "https://ginipick-kai-commu-1253181449008320553.hf.space", | |
| "https://ginipick-kai-commu-1253181487818211348.hf.space", | |
| "https://ginipick-kai-commu-1253181517593837568.hf.space", | |
| "https://ginipick-kai-commu-1253181557233946665.hf.space", | |
| "https://ginipick-kai-commu-1253181575252803634.hf.space", | |
| "https://ginipick-kai-commu-1253181626750341141.hf.space", | |
| "https://fantaxy-kai-llm-claude35.hf.space", | |
| "https://fantaxy-kai-llm-gpt4o.hf.space", | |
| "https://fantaxy-kai-llm-l370b.hf.space", | |
| "https://fantaxy-kai-llm-l38b.hf.space", | |
| "https://fantaxy-kai-llm-phi3.hf.space", | |
| "https://fantaxy-kai-llm-mix87.hf.space", | |
| "https://fantaxy-kai-llm-aya.hf.space", | |
| "https://fantaxy-kai-llm-zepr.hf.space", | |
| "https://fantaxy-kai-llm-yi.hf.space" | |
| # ์ฌ๊ธฐ์ ์ถ๊ฐ URL์ ์ถ๊ฐํ์ธ์ | |
| ] | |
| ], | |
| cache_examples=False # ์บ์ ๋นํ์ฑํ | |
| ) | |
| if __name__ == "__main__": | |
| app.launch() |