File size: 1,147 Bytes
0530853
 
 
 
 
 
 
 
 
8a31c70
0530853
 
 
8a31c70
 
0530853
 
 
 
42728ed
0530853
42728ed
 
 
 
0530853
 
42728ed
 
0530853
 
8a31c70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
import datetime
import asyncio

def update_live_message():
    """ ํ˜„์žฌ ์‹œ๊ฐ„๊ณผ 'live' ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. """
    current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    return f"{current_time} - live"

async def periodic_update(live_block, interval=60):
    """ ์ฃผ์–ด์ง„ ์ธํ„ฐํŽ˜์ด์Šค์— 1๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. """
    while True:
        live_message = update_live_message()
        live_block.value = live_message
        await live_block.update()
        await asyncio.sleep(interval)

def run_gradio():
    """ Gradio ์›น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. """
    with gr.Blocks() as demo:
        gr.Markdown("## Live Server Output")
        live_block = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output")
        
    # Gradio ์„œ๋ฒ„ ์‹œ์ž‘
    demo.queue(concurrency_count=20).launch(server_name="0.0.0.0", server_port=7860, inbrowser=True)

    # ๋น„๋™๊ธฐ ์—…๋ฐ์ดํŠธ ์ž‘์—… ์‹œ์ž‘
    loop = asyncio.get_event_loop()
    loop.create_task(periodic_update(live_block))

if __name__ == "__main__":
    run_gradio()