Spaces:
Build error
Build error
| 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() | |