Spaces:
Sleeping
Sleeping
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(interface, interval=60): | |
""" ์ฃผ์ด์ง ์ธํฐํ์ด์ค์ 1๋ถ ๊ฐ๊ฒฉ์ผ๋ก ์ ๋ฐ์ดํธ๋ฅผ ์คํํฉ๋๋ค. """ | |
while True: | |
live_message = update_live_message() | |
# Gradio ์ธํฐํ์ด์ค ์ ๋ฐ์ดํธ | |
interface(live_message) | |
await asyncio.sleep(interval) | |
def run_gradio(): | |
""" Gradio ์น ์ธํฐํ์ด์ค๋ฅผ ์ค์ ํ๊ณ ์คํํฉ๋๋ค. """ | |
with gr.Blocks() as demo: | |
live_output = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output", interactive=False) | |
async def live_update_task(): | |
""" ๋น๋๊ธฐ ์์ ์คํ """ | |
while True: | |
current_time = update_live_message() | |
live_output.update(value=current_time) | |
await asyncio.sleep(60) | |
# Gradio ์ธํฐํ์ด์ค ์คํ ์ ์ด๋ฒคํธ ๋ฃจํ์ ํตํฉ | |
demo.load(live_update_task) | |
demo.launch(server_name="0.0.0.0", server_port=7860, inbrowser=True) | |
if __name__ == "__main__": | |
run_gradio() | |