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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -47
app.py CHANGED
@@ -122,6 +122,8 @@ def explain_usage(app_content: str):
122
  except Exception as e:
123
  return f"μ‚¬μš©λ²• μ„€λͺ… 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
124
 
 
 
125
  def analyze_space(url: str, progress=gr.Progress()):
126
  try:
127
  space_id = url.split('spaces/')[-1]
@@ -139,12 +141,24 @@ def analyze_space(url: str, progress=gr.Progress()):
139
  progress(0.3, desc="app.py λ‚΄μš© κ°€μ Έμ˜€λŠ” 쀑...")
140
  app_content = get_file_content(space_id, "app.py")
141
 
 
 
 
 
 
 
 
 
 
142
  progress(1.0, desc="μ™„λ£Œ")
143
- return app_content, tree_view, tree_structure, space_id
144
  except Exception as e:
145
  print(f"Error in analyze_space: {str(e)}")
146
  print(traceback.format_exc())
147
- return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", None, ""
 
 
 
148
 
149
  def respond(message: str, chat_history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float):
150
  messages = [{"role": "system", "content": system_message}]
@@ -201,7 +215,7 @@ def create_ui():
201
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
202
  gr.Markdown("# HuggingFace Space Analyzer")
203
 
204
- with gr.Tabs() as tabs:
205
  with gr.TabItem("뢄석"):
206
  with gr.Row():
207
  with gr.Column(scale=6): # μ™Όμͺ½ 60%
@@ -225,7 +239,7 @@ def create_ui():
225
 
226
  with gr.Column(scale=4): # 였λ₯Έμͺ½ 40%
227
  with gr.Group(elem_classes="output-group full-height"):
228
- code_tabs = gr.Tabs()
229
  with code_tabs:
230
  app_py_tab = gr.TabItem("app.py")
231
  with app_py_tab:
@@ -244,7 +258,6 @@ def create_ui():
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 토큰 이상 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
@@ -271,7 +284,6 @@ def create_ui():
271
  return ""
272
 
273
  def get_files(node):
274
-
275
  files = []
276
  if node["type"] == "file":
277
  files.append(node)
@@ -298,23 +310,11 @@ def create_ui():
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],
@@ -336,31 +336,4 @@ def create_ui():
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
-
350
- except Exception as e:
351
- print(f"Error in create_ui: {str(e)}")
352
- print(traceback.format_exc())
353
- raise
354
-
355
- if __name__ == "__main__":
356
- try:
357
- demo = create_ui()
358
- demo.queue()
359
- demo.launch(
360
- share=False,
361
- debug=True,
362
- show_api=False
363
- )
364
- except Exception as e:
365
- print(f"Error in main: {str(e)}")
366
- print(traceback.format_exc())
 
122
  except Exception as e:
123
  return f"μ‚¬μš©λ²• μ„€λͺ… 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
124
 
125
+
126
+
127
  def analyze_space(url: str, progress=gr.Progress()):
128
  try:
129
  space_id = url.split('spaces/')[-1]
 
141
  progress(0.3, desc="app.py λ‚΄μš© κ°€μ Έμ˜€λŠ” 쀑...")
142
  app_content = get_file_content(space_id, "app.py")
143
 
144
+ progress(0.5, desc="μ½”λ“œ μš”μ•½ 쀑...")
145
+ summary = summarize_code(app_content)
146
+
147
+ progress(0.7, desc="μ½”λ“œ 뢄석 쀑...")
148
+ analysis = analyze_code(app_content)
149
+
150
+ progress(0.9, desc="μ‚¬μš©λ²• μ„€λͺ… 생성 쀑...")
151
+ usage = explain_usage(app_content)
152
+
153
  progress(1.0, desc="μ™„λ£Œ")
154
+ return app_content, tree_view, tree_structure, space_id, summary, analysis, usage
155
  except Exception as e:
156
  print(f"Error in analyze_space: {str(e)}")
157
  print(traceback.format_exc())
158
+ return f"였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", None, "", "", "", ""
159
+
160
+
161
+
162
 
163
  def respond(message: str, chat_history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float):
164
  messages = [{"role": "system", "content": system_message}]
 
215
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
216
  gr.Markdown("# HuggingFace Space Analyzer")
217
 
218
+ with gr.Tabs(elem_classes="main-tabs") as tabs:
219
  with gr.TabItem("뢄석"):
220
  with gr.Row():
221
  with gr.Column(scale=6): # μ™Όμͺ½ 60%
 
239
 
240
  with gr.Column(scale=4): # 였λ₯Έμͺ½ 40%
241
  with gr.Group(elem_classes="output-group full-height"):
242
+ code_tabs = gr.Tabs(elem_classes="code-tabs")
243
  with code_tabs:
244
  app_py_tab = gr.TabItem("app.py")
245
  with app_py_tab:
 
258
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
259
 
260
  examples = [
 
261
  ["μƒμ„Έν•œ μ‚¬μš© 방법을 마치 화면을 λ³΄λ©΄μ„œ μ„€λͺ…ν•˜λ“―이 4000 토큰 이상 μžμ„Ένžˆ μ„€λͺ…ν•˜λΌ"],
262
  ["FAQ 20건을 μƒμ„Έν•˜κ²Œ μž‘μ„±ν•˜λΌ. 4000토큰 이상 μ‚¬μš©ν•˜λΌ."],
263
  ["μ‚¬μš© 방법과 차별점, νŠΉμ§•, 강점을 μ€‘μ‹¬μœΌλ‘œ 4000 토큰 이상 유튜브 μ˜μƒ 슀크립트 ν˜•νƒœλ‘œ μž‘μ„±ν•˜λΌ"],
 
284
  return ""
285
 
286
  def get_files(node):
 
287
  files = []
288
  if node["type"] == "file":
289
  files.append(node)
 
310
  analyze_button.click(
311
  analyze_space,
312
  inputs=[url_input],
313
+ outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state, summary_output, analysis_output, usage_output]
314
  ).then(
315
  update_file_buttons,
316
  inputs=[tree_structure_state, space_id_state],
317
  outputs=[file_buttons]
 
 
 
 
 
 
 
 
 
 
 
 
318
  ).then(
319
  lambda space_id: get_file_content(space_id, "requirements.txt"),
320
  inputs=[space_id_state],
 
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