ginipick commited on
Commit
cbc2346
Β·
verified Β·
1 Parent(s): 11aeea5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -93,17 +93,21 @@ def on_select(space):
93
  try:
94
  summary = summarize_space(space)
95
  app_content = get_app_py_content(space['id'])
96
- screenshot = take_screenshot(space['url'])
97
  info = f"μ„ νƒλœ Space: {space['name']} (ID: {space['id']})\n"
98
  info += f"Author: {space['author']}\n"
99
  info += f"Likes: {space['likes']}\n"
100
  info += f"URL: {space['url']}\n\n"
101
  info += f"μš”μ•½:\n{summary}"
102
- return info, app_content, screenshot
103
  except Exception as e:
104
  print(f"Error in on_select: {str(e)}")
105
  print(traceback.format_exc())
106
- return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", Image.new('RGB', (1080, 720), color='lightgray')
 
 
 
 
 
107
 
108
  def take_screenshot(url):
109
  try:
@@ -142,16 +146,18 @@ def create_ui():
142
 
143
  with gr.Column(scale=1):
144
  info_output = gr.Textbox(label="Space 정보 및 μš”μ•½", lines=20)
145
- screenshot_output = gr.Image(type="pil", label="Space μŠ€ν¬λ¦°μƒ·", height=360, width=600)
146
- app_py_content = gr.Code(language="python", label="app.py λ‚΄μš©")
 
147
 
148
  for _, button, space in space_rows:
149
  button.click(
150
  lambda s=space: on_select(s),
151
- inputs=[],
152
- outputs=[info_output, app_py_content, screenshot_output]
153
  )
154
 
 
155
 
156
  return demo
157
 
 
93
  try:
94
  summary = summarize_space(space)
95
  app_content = get_app_py_content(space['id'])
 
96
  info = f"μ„ νƒλœ Space: {space['name']} (ID: {space['id']})\n"
97
  info += f"Author: {space['author']}\n"
98
  info += f"Likes: {space['likes']}\n"
99
  info += f"URL: {space['url']}\n\n"
100
  info += f"μš”μ•½:\n{summary}"
101
+ return info, app_content, space['url']
102
  except Exception as e:
103
  print(f"Error in on_select: {str(e)}")
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
 
147
  with gr.Column(scale=1):
148
  info_output = gr.Textbox(label="Space 정보 및 μš”μ•½", lines=20)
149
+ screenshot_output = gr.Image(type="pil", label="Live ν™”λ©΄", height=360, width=600)
150
+ app_py_content = gr.Code(language="python", label="메인 μ†ŒμŠ€μ½”λ“œ")
151
+ url_state = gr.State("")
152
 
153
  for _, button, space in space_rows:
154
  button.click(
155
  lambda s=space: on_select(s),
156
+ inputs=[],
157
+ outputs=[info_output, app_py_content, url_state]
158
  )
159
 
160
+ demo.load(update_screenshot, inputs=[url_state], outputs=[screenshot_output], every=5)
161
 
162
  return demo
163