ginipick commited on
Commit
7e8c8ee
ยท
verified ยท
1 Parent(s): 5d7fe5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -104,10 +104,10 @@ def on_select(space):
104
  print(traceback.format_exc())
105
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", "", ""
106
 
107
- def update_screenshot(url):
108
- if url:
109
- return take_screenshot(url)
110
- return None
111
 
112
  def take_screenshot(url):
113
  try:
@@ -146,7 +146,8 @@ def create_ui():
146
 
147
  with gr.Column(scale=1):
148
  info_output = gr.Textbox(label="Space ์ •๋ณด ๋ฐ ์š”์•ฝ", lines=20)
149
- url_state = gr.Textbox(visible=False)
 
150
  screenshot_output = gr.Image(type="pil", label="Live ํ™”๋ฉด", height=360, width=600)
151
  app_py_content = gr.Code(language="python", label="๋ฉ”์ธ ์†Œ์Šค์ฝ”๋“œ")
152
 
@@ -157,11 +158,11 @@ def create_ui():
157
  outputs=[info_output, app_py_content, url_state]
158
  )
159
 
160
- url_state.change(
161
- update_screenshot,
162
- inputs=[url_state],
163
- outputs=[screenshot_output],
164
- every=5
165
  )
166
 
167
  return demo
 
104
  print(traceback.format_exc())
105
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", "", ""
106
 
107
+ def update_screenshot(url, last_url):
108
+ if url and url != last_url:
109
+ return take_screenshot(url), url
110
+ return None, last_url
111
 
112
  def take_screenshot(url):
113
  try:
 
146
 
147
  with gr.Column(scale=1):
148
  info_output = gr.Textbox(label="Space ์ •๋ณด ๋ฐ ์š”์•ฝ", lines=20)
149
+ url_state = gr.State("")
150
+ last_url_state = gr.State("")
151
  screenshot_output = gr.Image(type="pil", label="Live ํ™”๋ฉด", height=360, width=600)
152
  app_py_content = gr.Code(language="python", label="๋ฉ”์ธ ์†Œ์Šค์ฝ”๋“œ")
153
 
 
158
  outputs=[info_output, app_py_content, url_state]
159
  )
160
 
161
+ demo.add_periodic_callback(
162
+ lambda: update_screenshot(url_state.value, last_url_state.value),
163
+ 5,
164
+ inputs=[url_state, last_url_state],
165
+ outputs=[screenshot_output, last_url_state]
166
  )
167
 
168
  return demo