ginipick commited on
Commit
81ba805
Β·
verified Β·
1 Parent(s): e0713c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -8
app.py CHANGED
@@ -86,7 +86,6 @@ def summarize_code(app_content: str):
86
  except Exception as e:
87
  return f"μš”μ•½ 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
88
 
89
-
90
  def analyze_code(app_content: str):
91
  system_message = """당신은 Python μ½”λ“œλ₯Ό λΆ„μ„ν•˜λŠ” AI μ‘°μˆ˜μž…λ‹ˆλ‹€. μ£Όμ–΄μ§„ μ½”λ“œλ₯Ό λΆ„μ„ν•˜μ—¬ λ‹€μŒ ν•­λͺ©μ— λŒ€ν•΄ μ„€λͺ…ν•΄μ£Όμ„Έμš”:
92
  A. λ°°κ²½ 및 ν•„μš”μ„±
@@ -160,8 +159,6 @@ def respond(message: str, chat_history: List[Dict[str, str]], system_message: st
160
  except Exception as e:
161
  return f"응닡 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
162
 
163
-
164
-
165
  def create_ui():
166
  try:
167
  css = """
@@ -247,9 +244,7 @@ def create_ui():
247
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
248
 
249
  examples = [
250
- ["νŒ¨μ…˜ μ½”λ“œ μ‹€ν–‰"],
251
- ["UHD 이미지 μ½”λ“œ μ‹€ν–‰"],
252
- ["MixGEN μ½”λ“œ μ‹€ν–‰"],
253
  ["μƒμ„Έν•œ μ‚¬μš© 방법을 마치 화면을 λ³΄λ©΄μ„œ μ„€λͺ…ν•˜λ“―이 4000 토큰 이상 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
254
  ["FAQ 20건을 μƒμ„Έν•˜κ²Œ μž‘μ„±ν•˜λΌ. 4000토큰 이상 μ‚¬μš©ν•˜λΌ."],
255
  ["μ‚¬μš© 방법과 차별점, νŠΉμ§•, 강점을 μ€‘μ‹¬μœΌλ‘œ 4000 토큰 이상 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
@@ -268,7 +263,87 @@ def create_ui():
268
 
269
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
270
 
271
- # ... (λ‚˜λ¨Έμ§€ μ½”λ“œλŠ” κ·ΈλŒ€λ‘œ μœ μ§€)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  return demo
274
 
@@ -288,4 +363,4 @@ if __name__ == "__main__":
288
  )
289
  except Exception as e:
290
  print(f"Error in main: {str(e)}")
291
- print(traceback.format_exc())
 
86
  except Exception as e:
87
  return f"μš”μ•½ 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
88
 
 
89
  def analyze_code(app_content: str):
90
  system_message = """당신은 Python μ½”λ“œλ₯Ό λΆ„μ„ν•˜λŠ” AI μ‘°μˆ˜μž…λ‹ˆλ‹€. μ£Όμ–΄μ§„ μ½”λ“œλ₯Ό λΆ„μ„ν•˜μ—¬ λ‹€μŒ ν•­λͺ©μ— λŒ€ν•΄ μ„€λͺ…ν•΄μ£Όμ„Έμš”:
91
  A. λ°°κ²½ 및 ν•„μš”μ„±
 
159
  except Exception as e:
160
  return f"응닡 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
161
 
 
 
162
  def create_ui():
163
  try:
164
  css = """
 
244
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
245
 
246
  examples = [
247
+
 
 
248
  ["μƒμ„Έν•œ μ‚¬μš© 방법을 마치 화면을 λ³΄λ©΄μ„œ μ„€λͺ…ν•˜λ“―이 4000 토큰 이상 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
249
  ["FAQ 20건을 μƒμ„Έν•˜κ²Œ μž‘μ„±ν•˜λΌ. 4000토큰 이상 μ‚¬μš©ν•˜λΌ."],
250
  ["μ‚¬μš© 방법과 차별점, νŠΉμ§•, 강점을 μ€‘μ‹¬μœΌλ‘œ 4000 토큰 이상 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
 
263
 
264
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
265
 
266
+ space_id_state = gr.State()
267
+ tree_structure_state = gr.State()
268
+
269
+ def update_file_buttons(tree_structure, space_id):
270
+ if tree_structure is None:
271
+ return ""
272
+
273
+ def get_files(node):
274
+
275
+ files = []
276
+ if node["type"] == "file":
277
+ files.append(node)
278
+ elif node["type"] == "directory":
279
+ for child in node.get("children", []):
280
+ files.extend(get_files(child))
281
+ return files
282
+
283
+ files = get_files(tree_structure)
284
+ buttons_html = "<div style='display: flex; flex-direction: column;'>"
285
+ for file in files:
286
+ buttons_html += f"<button class='file-button' onclick='openFile(\"{file['path']}\", \"{space_id}\")'>{file['path']}</button>"
287
+ buttons_html += "</div>"
288
+ return buttons_html
289
+
290
+ def open_file(file_path: str, space_id: str):
291
+ content = get_file_content(space_id, file_path)
292
+ file_name = file_path.split('/')[-1]
293
+ if file_name == "requirements.txt":
294
+ return gr.Tabs.update(selected="requirements.txt"), gr.Textbox.update(value=content, label=file_name)
295
+ else:
296
+ return gr.Tabs.update(selected=file_name), gr.Code.update(value=content, language="python" if file_name.endswith('.py') else "plaintext", label=file_name)
297
+
298
+ analyze_button.click(
299
+ analyze_space,
300
+ inputs=[url_input],
301
+ outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state]
302
+ ).then(
303
+ update_file_buttons,
304
+ inputs=[tree_structure_state, space_id_state],
305
+ outputs=[file_buttons]
306
+ ).then(
307
+ summarize_code,
308
+ inputs=[app_py_content],
309
+ outputs=[summary_output]
310
+ ).then(
311
+ analyze_code,
312
+ inputs=[app_py_content],
313
+ outputs=[analysis_output]
314
+ ).then(
315
+ explain_usage,
316
+ inputs=[app_py_content],
317
+ outputs=[usage_output]
318
+ ).then(
319
+ lambda space_id: get_file_content(space_id, "requirements.txt"),
320
+ inputs=[space_id_state],
321
+ outputs=[requirements_content]
322
+ )
323
+
324
+ file_path_input = gr.Textbox(visible=False)
325
+ space_id_input = gr.Textbox(visible=False)
326
+
327
+ file_path_input.change(
328
+ open_file,
329
+ inputs=[file_path_input, space_id_input],
330
+ outputs=[code_tabs, code_tabs]
331
+ )
332
+
333
+ # JavaScript μ½”λ“œλ₯Ό HTML에 직접 μ‚½μž…
334
+ gr.HTML("""
335
+ <script>
336
+ function openFile(path, spaceId) {
337
+ const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
338
+ const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
339
+ if (filePathInput && spaceIdInput) {
340
+ filePathInput.value = path;
341
+ spaceIdInput.value = spaceId;
342
+ filePathInput.dispatchEvent(new Event('change'));
343
+ }
344
+ }
345
+ </script>
346
+ """)
347
 
348
  return demo
349
 
 
363
  )
364
  except Exception as e:
365
  print(f"Error in main: {str(e)}")
366
+ print(traceback.format_exc())