ginipick commited on
Commit
6081210
ยท
verified ยท
1 Parent(s): 3581d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -78
app.py CHANGED
@@ -165,7 +165,7 @@ def create_ui():
165
  footer {visibility: hidden;}
166
  .minimal-button {min-width: 30px !important; height: 25px !important; line-height: 1 !important; font-size: 12px !important; padding: 2px 5px !important;}
167
  .space-row {margin-bottom: 5px !important;}
168
- #refresh-button, #manual-button {
169
  width: 100% !important;
170
  margin-top: 5px !important;
171
  }
@@ -185,40 +185,6 @@ def create_ui():
185
  padding: 10px;
186
  margin-bottom: 20px;
187
  }
188
- #embedded-space {
189
- width: 100%;
190
- height: 600px;
191
- border: none;
192
- }
193
- .iframe-container {
194
- position: relative;
195
- width: 100%;
196
- height: 600px;
197
- overflow: hidden;
198
- }
199
- .iframe-container iframe {
200
- width: 100%;
201
- height: 100%;
202
- border: none;
203
- }
204
- .loading-overlay {
205
- position: absolute;
206
- top: 0;
207
- left: 0;
208
- width: 100%;
209
- height: 100%;
210
- background-color: rgba(255, 255, 255, 0.8);
211
- display: flex;
212
- justify-content: center;
213
- align-items: center;
214
- font-size: 24px;
215
- z-index: 1000;
216
- }
217
- .error-message {
218
- color: red;
219
- font-weight: bold;
220
- text-align: center;
221
- }
222
  """
223
 
224
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
@@ -250,63 +216,39 @@ def create_ui():
250
  with gr.Group(elem_classes="output-group"):
251
  app_py_content = gr.Code(language="python", label="๋ฉ”์ธ ์†Œ์Šค์ฝ”๋“œ", elem_id="app-py-content", lines=None, max_lines=None)
252
 
253
- # iframe์„ ์œ„ํ•œ HTML ์š”์†Œ
254
- embedded_space = gr.HTML(
255
- """
256
- <div class="iframe-container">
257
- <div id="loading-overlay" class="loading-overlay">๋กœ๋”ฉ ์ค‘...</div>
258
- <iframe id="space-iframe" src="about:blank" onload="hideLoading()"></iframe>
259
- </div>
260
- <div id="error-message" class="error-message"></div>
261
- <script>
262
- function hideLoading() {
263
- document.getElementById('loading-overlay').style.display = 'none';
264
- }
265
- function showLoading() {
266
- document.getElementById('loading-overlay').style.display = 'flex';
267
- }
268
- function updateIframe(url) {
269
- showLoading();
270
- const iframe = document.getElementById('space-iframe');
271
- const errorMessage = document.getElementById('error-message');
272
- iframe.src = url;
273
- iframe.onload = function() {
274
- hideLoading();
275
- errorMessage.textContent = '';
276
- };
277
- iframe.onerror = function() {
278
- hideLoading();
279
- errorMessage.textContent = 'Space๋ฅผ ๋กœ๋“œํ•˜๋Š” ๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ ํƒญ์—์„œ ์—ด์–ด๋ณด์„ธ์š”.';
280
- };
281
- }
282
- </script>
283
- """
284
- )
285
 
286
  update_trigger = gr.Button("Update Screenshot", visible=False)
287
 
288
- def update_embedded_space(url):
289
- return f"""
290
- <script>
291
- updateIframe("{url}");
292
- </script>
293
- """
294
 
295
  for _, button, space in space_rows:
296
  button.click(
297
- lambda s=space: on_select(s),
298
  inputs=[],
299
  outputs=[info_output, app_py_content, url_state]
300
  ).then(
301
  update_screenshot,
302
  inputs=[url_state, last_url_state],
303
  outputs=[screenshot_output, last_url_state]
304
- ).then(
305
- update_embedded_space,
306
- inputs=[url_state],
307
- outputs=[embedded_space]
308
  )
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
 
311
  def refresh_screenshot(url, last_url):
312
  print(f"Refresh button clicked. URL: {url}, Last URL: {last_url}")
 
165
  footer {visibility: hidden;}
166
  .minimal-button {min-width: 30px !important; height: 25px !important; line-height: 1 !important; font-size: 12px !important; padding: 2px 5px !important;}
167
  .space-row {margin-bottom: 5px !important;}
168
+ #refresh-button, #manual-button, #open-space-button {
169
  width: 100% !important;
170
  margin-top: 5px !important;
171
  }
 
185
  padding: 10px;
186
  margin-bottom: 20px;
187
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  """
189
 
190
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
 
216
  with gr.Group(elem_classes="output-group"):
217
  app_py_content = gr.Code(language="python", label="๋ฉ”์ธ ์†Œ์Šค์ฝ”๋“œ", elem_id="app-py-content", lines=None, max_lines=None)
218
 
219
+ open_space_button = gr.Button("์„ ํƒํ•œ Space ์—ด๊ธฐ", elem_id="open-space-button")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  update_trigger = gr.Button("Update Screenshot", visible=False)
222
 
223
+ def on_select_with_link(space):
224
+ info, app_content, url = on_select(space)
225
+ info += f"\n\n[Space ์—ด๊ธฐ]({url})"
226
+ return info, app_content, url
 
 
227
 
228
  for _, button, space in space_rows:
229
  button.click(
230
+ lambda s=space: on_select_with_link(s),
231
  inputs=[],
232
  outputs=[info_output, app_py_content, url_state]
233
  ).then(
234
  update_screenshot,
235
  inputs=[url_state, last_url_state],
236
  outputs=[screenshot_output, last_url_state]
 
 
 
 
237
  )
238
 
239
+ def open_space(url):
240
+ return f"""
241
+ <script>
242
+ window.open('{url}', '_blank');
243
+ </script>
244
+ """
245
+
246
+ open_space_button.click(
247
+ open_space,
248
+ inputs=[url_state],
249
+ outputs=[gr.HTML()]
250
+ )
251
+
252
 
253
  def refresh_screenshot(url, last_url):
254
  print(f"Refresh button clicked. URL: {url}, Last URL: {last_url}")