fantaxy commited on
Commit
66212c0
ยท
verified ยท
1 Parent(s): be1f47c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -66
app.py CHANGED
@@ -1,72 +1,86 @@
1
- import requests
2
- import time
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-timer2.hf.space",
16
- "https://ginipick-gini-llm-chatbot-text.hf.space",
17
- "https://ginipick-gini-llm-chat-speech.hf.space",
18
- "https://ginipick-gini-llm-blog.hf.space",
19
- "https://fantaxy-kai-chat-speech.hf.space",
20
- "https://fantaxy-kai-tts.hf.space",
21
- "https://fantaxy-kai-ytb-audio.hf.space",
22
- "https://fantaxy-kai-ytb-blog.hf.space",
23
- "https://fantaxy-kai-girlfriend19.hf.space",
24
- "https://fantaxy-kai-person-lee.hf.space",
25
- "https://fantaxy-kai-person-jobs.hf.space",
26
- "https://fantaxy-kai-person-eins.hf.space",
27
- "https://fantaxy-kai-person-musk.hf.space",
28
- "https://fantaxy-kai-person-hwang.hf.space",
29
- "https://ginipick-kai-commu-1253181171853164544.hf.space",
30
- "https://ginipick-kai-commu-1253181193180942367.hf.space",
31
- "https://ginipick-kai-commu-1253181238676557884.hf.space",
32
- "https://ginipick-kai-commu-1253181258561884161.hf.space",
33
- "https://ginipick-kai-commu-1253181305739411567.hf.space",
34
- "https://ginipick-kai-commu-1253181326060949585.hf.space",
35
- "https://ginipick-kai-commu-1253181359371980892.hf.space",
36
- "https://ginipick-kai-commu-1253181380091973715.hf.space",
37
- "https://ginipick-kai-commu-1253181427605045329.hf.space",
38
- "https://ginipick-kai-commu-1253181449008320553.hf.space",
39
- "https://ginipick-kai-commu-1253181487818211348.hf.space",
40
- "https://ginipick-kai-commu-1253181517593837568.hf.space",
41
- "https://ginipick-kai-commu-1253181557233946665.hf.space",
42
- "https://ginipick-kai-commu-1253181575252803634.hf.space",
43
- "https://ginipick-kai-commu-1253181626750341141.hf.space"
44
- # ์—ฌ๊ธฐ์— ์ถ”๊ฐ€ URL์„ ์ถ”๊ฐ€ํ•˜์„ธ์š”
45
- ]
46
-
47
- # URL์— ์ ‘์†์„ ์‹œ๋„ํ•˜๋Š” ํ•จ์ˆ˜
48
- def check_url(url):
49
  try:
50
- response = requests.get(url)
51
- status = response.status_code
52
- logging.info(f"{url} - ์ƒํƒœ ์ฝ”๋“œ: {status}")
53
- except requests.RequestException as e:
54
- logging.error(f"{url} - ์˜ค๋ฅ˜: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- # ๋ชจ๋“  URL์„ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
57
- def check_all_urls():
58
- for url in urls:
59
- check_url(url)
60
- schedule_next_run()
 
61
 
62
- # ๋‹ค์Œ ์‹คํ–‰์„ ์˜ˆ์•ฝํ•˜๋Š” ํ•จ์ˆ˜ (15๋ถ„๋งˆ๋‹ค ์‹คํ–‰)
63
- def schedule_next_run():
64
- s.enter(900, 1, check_all_urls) # 900์ดˆ = 15๋ถ„
65
- logging.info("๋‹ค์Œ ์‹คํ–‰์ด ์˜ˆ์•ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
66
 
67
- # ์ดˆ๊ธฐ ์‹คํ–‰
68
- logging.info("ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘")
69
- check_all_urls() # ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ์‹œ ์ฒซ ๋ฒˆ์งธ URL ์ฒดํฌ๋ฅผ ์‹คํ–‰
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- # ์Šค์ผ€์ค„๋Ÿฌ ์‹คํ–‰
72
- s.run()
 
1
+ import gradio as gr
2
+ import aiohttp
3
+ import asyncio
4
+ import threading
 
5
 
6
+ # ๋น„๋™๊ธฐ์ ์œผ๋กœ ์™ธ๋ถ€ URL์— ์ ‘์†ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
7
+ async def check_connection(url):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  try:
9
+ async with aiohttp.ClientSession() as session:
10
+ async with session.get(url) as response:
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
+ print(status)
17
+ return status
18
+
19
+ # ํƒ€์ด๋จธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ •ํ•ด์ง„ ์ฃผ๊ธฐ๋กœ ๋น„๋™๊ธฐ ํ•จ์ˆ˜๋ฅผ ๋ฐ˜๋ณต ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
20
+ async def start_timer(urls, interval):
21
+ while True:
22
+ for url in urls:
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
+ threading.Thread(target=asyncio.run, args=(start_timer(urls, interval_seconds),)).start()
33
+ return "ํƒ€์ด๋จธ๊ฐ€ ์„ค์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
34
 
35
+ # Gradio UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
36
+ url_inputs = [gr.Text(label=f"URL {i+1}", placeholder=f"์ ‘์†ํ•  URL {i+1}์„ ์ž…๋ ฅํ•˜์„ธ์š”") for i in range(40)]
37
+ interval_input = gr.Slider(minimum=1, maximum=60, step=1, value=5, label="์ ‘์† ์ฃผ๊ธฐ(๋ถ„)")
 
38
 
39
+ # Gradio ์•ฑ ์„ค์ •
40
+ app = gr.Interface(
41
+ fn=setup_timer,
42
+ inputs=[interval_input] + url_inputs,
43
+ outputs="text",
44
+ title="URL ์ ‘์† ์ฒด์ปค",
45
+ description="์ตœ๋Œ€ 40๊ฐœ์˜ URL๊ณผ ์ ‘์† ์ฃผ๊ธฐ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  '์‹œ์ž‘' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”. ์ง€์ •๋œ ์ฃผ๊ธฐ๋กœ HTTP ์ƒํƒœ ์ฝ”๋“œ ๋ฐ ์ ‘์† ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.",
46
+ examples=[
47
+ [
48
+ 15,
49
+ "https://fantaxy-timer2.hf.space",
50
+ "https://ginipick-gini-llm-chatbot-text.hf.space",
51
+ "https://ginipick-gini-llm-chat-speech.hf.space",
52
+ "https://ginipick-gini-llm-blog.hf.space",
53
+ "https://fantaxy-kai-chat-speech.hf.space",
54
+ "https://fantaxy-kai-tts.hf.space",
55
+ "https://fantaxy-kai-ytb-audio.hf.space",
56
+ "https://fantaxy-kai-ytb-blog.hf.space",
57
+ "https://fantaxy-kai-girlfriend19.hf.space",
58
+ "https://fantaxy-kai-person-lee.hf.space",
59
+ "https://fantaxy-kai-person-jobs.hf.space",
60
+ "https://fantaxy-kai-person-eins.hf.space",
61
+ "https://fantaxy-kai-person-musk.hf.space",
62
+ "https://fantaxy-kai-person-hwang.hf.space",
63
+ "https://ginipick-kai-commu-1253181171853164544.hf.space",
64
+ "https://ginipick-kai-commu-1253181193180942367.hf.space",
65
+ "https://ginipick-kai-commu-1253181238676557884.hf.space",
66
+ "https://ginipick-kai-commu-1253181258561884161.hf.space",
67
+ "https://ginipick-kai-commu-1253181305739411567.hf.space",
68
+ "https://ginipick-kai-commu-1253181326060949585.hf.space",
69
+ "https://ginipick-kai-commu-1253181359371980892.hf.space",
70
+ "https://ginipick-kai-commu-1253181380091973715.hf.space",
71
+ "https://ginipick-kai-commu-1253181427605045329.hf.space",
72
+ "https://ginipick-kai-commu-1253181449008320553.hf.space",
73
+ "https://ginipick-kai-commu-1253181487818211348.hf.space",
74
+ "https://ginipick-kai-commu-1253181517593837568.hf.space",
75
+ "https://ginipick-kai-commu-1253181557233946665.hf.space",
76
+ "https://ginipick-kai-commu-1253181575252803634.hf.space",
77
+ "https://ginipick-kai-commu-1253181626750341141.hf.space"
78
+ # ์—ฌ๊ธฐ์— ์ถ”๊ฐ€ URL์„ ์ถ”๊ฐ€ํ•˜์„ธ์š”
79
+ ]
80
+ ]
81
+ ],
82
+ cache_examples=False # ์บ์‹œ ๋น„ํ™œ์„ฑํ™”
83
+ )
84
 
85
+ if __name__ == "__main__":
86
+ app.launch()