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()