fantaxy commited on
Commit
8f909a0
ยท
verified ยท
1 Parent(s): 3ada8ea

Update web.py

Browse files
Files changed (1) hide show
  1. web.py +4 -12
web.py CHANGED
@@ -3,34 +3,26 @@ import datetime
3
  import asyncio
4
 
5
  def update_live_message():
6
- """ ํ˜„์žฌ ์‹œ๊ฐ„๊ณผ 'live' ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. """
7
  current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
8
  return f"{current_time} - live"
9
 
10
  async def periodic_update(interface, interval=60):
11
- """ ์ฃผ์–ด์ง„ ์ธํ„ฐํŽ˜์ด์Šค์— 1๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. """
12
  while True:
13
  live_message = update_live_message()
14
- interface.update(value=live_message) # Gradio interface์˜ ๊ฐ’์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
15
  await asyncio.sleep(interval)
16
 
17
  def run_gradio():
18
- """ Gradio ์›น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. """
19
  live_block = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output")
20
-
21
  demo = gr.Blocks()
22
 
23
  with demo:
24
  gr.Markdown("## Live Server Output")
25
  live_block
26
 
27
- # ๋น„๋™๊ธฐ ์—…๋ฐ์ดํŠธ ์ž‘์—… ์‹œ์ž‘
28
- loop = asyncio.new_event_loop()
29
- asyncio.set_event_loop(loop)
30
- task = loop.create_task(periodic_update(live_block))
31
-
32
- demo.launch(server_name="0.0.0.0", server_port=7860, inbrowser=True, enable_queue=True)
33
- loop.run_until_complete(task)
34
 
35
  if __name__ == "__main__":
36
  run_gradio()
 
3
  import asyncio
4
 
5
  def update_live_message():
 
6
  current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
7
  return f"{current_time} - live"
8
 
9
  async def periodic_update(interface, interval=60):
 
10
  while True:
11
  live_message = update_live_message()
12
+ interface.update(value=live_message)
13
  await asyncio.sleep(interval)
14
 
15
  def run_gradio():
 
16
  live_block = gr.Textbox(label="Live Output", value="Starting...", elem_id="live_output")
 
17
  demo = gr.Blocks()
18
 
19
  with demo:
20
  gr.Markdown("## Live Server Output")
21
  live_block
22
 
23
+ asyncio.run(periodic_update(live_block))
24
+
25
+ demo.launch(server_name="0.0.0.0", debug=True, enable_queue=True)
 
 
 
 
26
 
27
  if __name__ == "__main__":
28
  run_gradio()