usebeecopy / web.py
SUHHHH's picture
Update web.py
039160b verified
raw
history blame
1.3 kB
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()