ginipick commited on
Commit
3fb4458
ยท
verified ยท
1 Parent(s): 6035bfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -11
app.py CHANGED
@@ -192,17 +192,15 @@ def create_ui():
192
  height: calc(100vh - 200px) !important;
193
  overflow-y: auto !important;
194
  }
 
 
 
195
  """
196
 
197
  js = """
198
  function openFile(path, spaceId) {
199
- const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
200
- const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
201
- if (filePathInput && spaceIdInput) {
202
- filePathInput.value = path;
203
- spaceIdInput.value = spaceId;
204
- filePathInput.dispatchEvent(new Event('change'));
205
- }
206
  }
207
  """
208
 
@@ -233,11 +231,14 @@ def create_ui():
233
 
234
  with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ 40%
235
  with gr.Group(elem_classes="output-group full-height"):
236
- code_tabs = gr.Tabs()
237
  with code_tabs:
238
  app_py_tab = gr.TabItem("app.py")
239
  with app_py_tab:
240
  app_py_content = gr.Code(language="python", label="app.py", lines=30)
 
 
 
241
 
242
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
243
  chatbot = gr.Chatbot()
@@ -249,6 +250,9 @@ def create_ui():
249
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
250
 
251
  examples = [
 
 
 
252
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
253
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
254
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
@@ -285,13 +289,14 @@ def create_ui():
285
  files = get_files(tree_structure)
286
  buttons_html = "<div style='display: flex; flex-direction: column;'>"
287
  for file in files:
288
- buttons_html += f"<button onclick=\"openFile('{file['path']}', '{space_id}')\" style='margin: 5px 0; padding: 5px;'>{file['path']}</button>"
289
  buttons_html += "</div>"
290
  return buttons_html
291
 
292
  def open_file(file_path: str, space_id: str):
293
  content = get_file_content(space_id, file_path)
294
- return gr.Tabs.update(selected=file_path), gr.Code(value=content, language="python", label=file_path, lines=30)
 
295
 
296
  analyze_button.click(
297
  analyze_space,
@@ -301,6 +306,10 @@ def create_ui():
301
  update_file_buttons,
302
  inputs=[tree_structure_state, space_id_state],
303
  outputs=[file_buttons]
 
 
 
 
304
  )
305
 
306
  file_path_input = gr.Textbox(visible=False)
@@ -318,6 +327,23 @@ def create_ui():
318
  # JavaScript ์ฝ”๋“œ๋ฅผ HTML์— ์ง์ ‘ ์‚ฝ์ž…
319
  gr.HTML(f"<script>{js}</script>")
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  return demo
322
 
323
  except Exception as e:
@@ -332,4 +358,4 @@ if __name__ == "__main__":
332
  demo.launch()
333
  except Exception as e:
334
  print(f"Error in main: {str(e)}")
335
- print(traceback.format_exc())
 
192
  height: calc(100vh - 200px) !important;
193
  overflow-y: auto !important;
194
  }
195
+ .tabs-style {
196
+ background-color: #ffff00;
197
+ }
198
  """
199
 
200
  js = """
201
  function openFile(path, spaceId) {
202
+ const event = new CustomEvent('open-file', { detail: { path, spaceId } });
203
+ window.dispatchEvent(event);
 
 
 
 
 
204
  }
205
  """
206
 
 
231
 
232
  with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ 40%
233
  with gr.Group(elem_classes="output-group full-height"):
234
+ code_tabs = gr.Tabs(elem_classes="tabs-style")
235
  with code_tabs:
236
  app_py_tab = gr.TabItem("app.py")
237
  with app_py_tab:
238
  app_py_content = gr.Code(language="python", label="app.py", lines=30)
239
+ requirements_tab = gr.TabItem("requirements.txt")
240
+ with requirements_tab:
241
+ requirements_content = gr.Code(language="text", label="requirements.txt", lines=30)
242
 
243
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
244
  chatbot = gr.Chatbot()
 
250
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
251
 
252
  examples = [
253
+ ["ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰"],
254
+ ["UHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰"],
255
+ ["MixGEN ์ฝ”๋“œ ์‹คํ–‰"],
256
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
257
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
258
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
 
289
  files = get_files(tree_structure)
290
  buttons_html = "<div style='display: flex; flex-direction: column;'>"
291
  for file in files:
292
+ buttons_html += f"<button onclick=\"openFile('{file['path']}', '{space_id}')\" style='margin: 5px 0; padding: 5px; cursor: pointer;'>{file['path']}</button>"
293
  buttons_html += "</div>"
294
  return buttons_html
295
 
296
  def open_file(file_path: str, space_id: str):
297
  content = get_file_content(space_id, file_path)
298
+ file_name = file_path.split('/')[-1]
299
+ return gr.Tabs.update(selected=file_name), gr.Code(value=content, language="python" if file_name.endswith('.py') else "text", label=file_name, lines=30)
300
 
301
  analyze_button.click(
302
  analyze_space,
 
306
  update_file_buttons,
307
  inputs=[tree_structure_state, space_id_state],
308
  outputs=[file_buttons]
309
+ ).then(
310
+ lambda space_id: get_file_content(space_id, "requirements.txt"),
311
+ inputs=[space_id_state],
312
+ outputs=[requirements_content]
313
  )
314
 
315
  file_path_input = gr.Textbox(visible=False)
 
327
  # JavaScript ์ฝ”๋“œ๋ฅผ HTML์— ์ง์ ‘ ์‚ฝ์ž…
328
  gr.HTML(f"<script>{js}</script>")
329
 
330
+ # ํŒŒ์ผ ์—ด๊ธฐ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ถ”๊ฐ€
331
+ demo.load(None, None, None, _js="""
332
+ () => {
333
+ function handleOpenFile(event) {
334
+ const { path, spaceId } = event.detail;
335
+ const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
336
+ const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
337
+ if (filePathInput && spaceIdInput) {
338
+ filePathInput.value = path;
339
+ spaceIdInput.value = spaceId;
340
+ filePathInput.dispatchEvent(new Event('change'));
341
+ }
342
+ }
343
+ window.addEventListener('open-file', handleOpenFile);
344
+ }
345
+ """)
346
+
347
  return demo
348
 
349
  except Exception as e:
 
358
  demo.launch()
359
  except Exception as e:
360
  print(f"Error in main: {str(e)}")
361
+ print(traceback.format_exc())