ginipick's picture
Rename web (3).py to web.py
f5554f8 verified
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()
interface.update(live_message)
await asyncio.sleep(interval)
def run_gradio():
""" Gradio μ›Ή μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ„€μ •ν•˜κ³  μ‹€ν–‰ν•©λ‹ˆλ‹€. """
live_block = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output")
demo = gr.Blocks()
with demo:
gr.Markdown("## Live Server Output")
live_block
demo.launch(server_name="0.0.0.0", server_port=7860, inbrowser=True)
# 비동기 μ—…λ°μ΄νŠΈ μž‘μ—… μ‹œμž‘
asyncio.run(periodic_update(live_block))
if __name__ == "__main__":
run_gradio()