ginipick commited on
Commit
7cbbdae
Β·
verified Β·
1 Parent(s): 919d187

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -77
app.py CHANGED
@@ -123,27 +123,13 @@ def explain_usage(app_content: str):
123
  return f"μ‚¬μš©λ²• μ„€λͺ… 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
124
 
125
  def adjust_lines_for_code(code_content: str, min_lines: int = 10, max_lines: int = 100) -> int:
126
- """
127
- μ½”λ“œ λ‚΄μš©μ— 따라 lines 수λ₯Ό λ™μ μœΌλ‘œ μ‘°μ •ν•©λ‹ˆλ‹€.
128
-
129
- Parameters:
130
- - code_content (str): μ½”λ“œ ν…μŠ€νŠΈ λ‚΄μš©
131
- - min_lines (int): μ΅œμ†Œ lines 수
132
- - max_lines (int): μ΅œλŒ€ lines 수
133
-
134
- Returns:
135
- - int: μ„€μ •λœ lines 수
136
- """
137
- # μ½”λ“œμ˜ 쀄 수 계산
138
  num_lines = len(code_content.split('\n'))
139
- # 쀄 μˆ˜κ°€ min_lines보닀 적닀면 min_lines μ‚¬μš©, max_lines보닀 크면 max_lines μ‚¬μš©
140
  return min(max(num_lines, min_lines), max_lines)
141
 
142
  def analyze_space(url: str, progress=gr.Progress()):
143
  try:
144
  space_id = url.split('spaces/')[-1]
145
 
146
- # Space ID μœ νš¨μ„± 검사 μˆ˜μ •
147
  if not re.match(r'^[\w.-]+/[\w.-]+$', space_id):
148
  raise ValueError(f"Invalid Space ID format: {space_id}")
149
 
@@ -165,7 +151,6 @@ def analyze_space(url: str, progress=gr.Progress()):
165
  progress(0.9, desc="μ‚¬μš©λ²• μ„€λͺ… 생성 쀑...")
166
  usage = explain_usage(app_content)
167
 
168
- # 쀄 수 κ³„μ‚°ν•˜μ—¬ lines μ„€μ •
169
  app_py_lines = adjust_lines_for_code(app_content)
170
 
171
  progress(1.0, desc="μ™„λ£Œ")
@@ -252,23 +237,7 @@ def create_ui():
252
  color: #2c3e50 !important;
253
  background-color: #ecf0f1 !important;
254
  }
255
- .copy-button {
256
- padding: 5px 10px;
257
- background-color: #3498db;
258
- color: white;
259
- border: none;
260
- border-radius: 3px;
261
- cursor: pointer;
262
- font-size: 12px;
263
- }
264
- .copy-button:hover {
265
- background-color: #2980b9;
266
- }
267
  """
268
-
269
-
270
- def copy_text(text):
271
- return text, f"'{text[:20]}...' 볡사됨"
272
 
273
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
274
  gr.Markdown("# Mouse: HuggingFace")
@@ -281,30 +250,16 @@ def create_ui():
281
  analyze_button = gr.Button("뢄석")
282
 
283
  with gr.Group(elem_classes="output-group scroll-lock"):
284
- with gr.Row():
285
- summary_output = gr.Markdown(label="μš”μ•½ (3쀄 이내)")
286
- copy_summary = gr.Button("볡사", elem_classes="copy-button")
287
- copy_summary_output = gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False)
288
 
289
  with gr.Group(elem_classes="output-group scroll-lock"):
290
- with gr.Row():
291
- analysis_output = gr.Markdown(label="뢄석")
292
- copy_analysis = gr.Button("볡사", elem_classes="copy-button")
293
- copy_analysis_output = gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False)
294
 
295
  with gr.Group(elem_classes="output-group scroll-lock"):
296
- with gr.Row():
297
- usage_output = gr.Markdown(label="μ‚¬μš©λ²•")
298
- copy_usage = gr.Button("볡사", elem_classes="copy-button")
299
- copy_usage_output = gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False)
300
 
301
  with gr.Group(elem_classes="output-group tree-view-scroll"):
302
- with gr.Row():
303
- tree_view_output = gr.Textbox(label="파일 ꡬ쑰 (Tree View)", lines=30)
304
- copy_tree = gr.Button("볡사", elem_classes="copy-button")
305
- copy_tree_output = gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False)
306
-
307
-
308
 
309
  with gr.Column(scale=4): # 였λ₯Έμͺ½ 40%
310
  with gr.Group(elem_classes="output-group full-height"):
@@ -312,30 +267,24 @@ def create_ui():
312
  with code_tabs:
313
  app_py_tab = gr.TabItem("app.py")
314
  with app_py_tab:
315
- with gr.Row():
316
- app_py_content = gr.Code(
317
- language="python",
318
- label="app.py",
319
- lines=200,
320
- elem_classes="full-height code-box"
321
- )
322
- copy_app_py = gr.Button("볡사", elem_classes="copy-button")
323
  requirements_tab = gr.TabItem("requirements.txt")
324
  with requirements_tab:
325
- with gr.Row():
326
- requirements_content = gr.Textbox(
327
- label="requirements.txt",
328
- lines=200,
329
- elem_classes="full-height code-box"
330
- )
331
- copy_requirements = gr.Button("볡사", elem_classes="copy-button")
332
-
333
 
334
  with gr.TabItem("AI μ½”λ”©"):
335
  chatbot = gr.Chatbot(label="λŒ€ν™”", type='messages')
336
  msg = gr.Textbox(label="λ©”μ‹œμ§€")
337
 
338
- # μˆ¨κ²¨μ§„ μƒνƒœλ‘œ νŒŒλΌλ―Έν„° μ„€μ •
339
  max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
340
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
341
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
@@ -372,18 +321,7 @@ def create_ui():
372
  inputs=[space_id_state],
373
  outputs=[requirements_content]
374
  )
375
- # 볡사 κΈ°λŠ₯ μ—°κ²°
376
- copy_summary.click(copy_text, inputs=[summary_output], outputs=[copy_summary_output, gr.Textbox(label="μƒνƒœ")])
377
- copy_analysis.click(copy_text, inputs=[analysis_output], outputs=[copy_analysis_output, gr.Textbox(label="μƒνƒœ")])
378
- copy_usage.click(copy_text, inputs=[usage_output], outputs=[copy_usage_output, gr.Textbox(label="μƒνƒœ")])
379
- copy_tree.click(copy_text, inputs=[tree_view_output], outputs=[copy_tree_output, gr.Textbox(label="μƒνƒœ")])
380
- copy_app_py.click(copy_text, inputs=[app_py_content], outputs=[gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False), gr.Textbox(label="μƒνƒœ")])
381
- copy_requirements.click(copy_text, inputs=[requirements_content], outputs=[gr.Textbox(label="λ³΅μ‚¬λœ λ‚΄μš©", visible=False), gr.Textbox(label="μƒνƒœ")])
382
-
383
-
384
-
385
 
386
- # lines 수λ₯Ό λ™μ μœΌλ‘œ μ„€μ •
387
  app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
388
 
389
  return demo
 
123
  return f"μ‚¬μš©λ²• μ„€λͺ… 생성 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
124
 
125
  def adjust_lines_for_code(code_content: str, min_lines: int = 10, max_lines: int = 100) -> int:
 
 
 
 
 
 
 
 
 
 
 
 
126
  num_lines = len(code_content.split('\n'))
 
127
  return min(max(num_lines, min_lines), max_lines)
128
 
129
  def analyze_space(url: str, progress=gr.Progress()):
130
  try:
131
  space_id = url.split('spaces/')[-1]
132
 
 
133
  if not re.match(r'^[\w.-]+/[\w.-]+$', space_id):
134
  raise ValueError(f"Invalid Space ID format: {space_id}")
135
 
 
151
  progress(0.9, desc="μ‚¬μš©λ²• μ„€λͺ… 생성 쀑...")
152
  usage = explain_usage(app_content)
153
 
 
154
  app_py_lines = adjust_lines_for_code(app_content)
155
 
156
  progress(1.0, desc="μ™„λ£Œ")
 
237
  color: #2c3e50 !important;
238
  background-color: #ecf0f1 !important;
239
  }
 
 
 
 
 
 
 
 
 
 
 
 
240
  """
 
 
 
 
241
 
242
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
243
  gr.Markdown("# Mouse: HuggingFace")
 
250
  analyze_button = gr.Button("뢄석")
251
 
252
  with gr.Group(elem_classes="output-group scroll-lock"):
253
+ summary_output = gr.Markdown(label="μš”μ•½ (3쀄 이내)")
 
 
 
254
 
255
  with gr.Group(elem_classes="output-group scroll-lock"):
256
+ analysis_output = gr.Markdown(label="뢄석")
 
 
 
257
 
258
  with gr.Group(elem_classes="output-group scroll-lock"):
259
+ usage_output = gr.Markdown(label="μ‚¬μš©λ²•")
 
 
 
260
 
261
  with gr.Group(elem_classes="output-group tree-view-scroll"):
262
+ tree_view_output = gr.Textbox(label="파일 ꡬ쑰 (Tree View)", lines=30)
 
 
 
 
 
263
 
264
  with gr.Column(scale=4): # 였λ₯Έμͺ½ 40%
265
  with gr.Group(elem_classes="output-group full-height"):
 
267
  with code_tabs:
268
  app_py_tab = gr.TabItem("app.py")
269
  with app_py_tab:
270
+ app_py_content = gr.Code(
271
+ language="python",
272
+ label="app.py",
273
+ lines=200,
274
+ elem_classes="full-height code-box"
275
+ )
 
 
276
  requirements_tab = gr.TabItem("requirements.txt")
277
  with requirements_tab:
278
+ requirements_content = gr.Textbox(
279
+ label="requirements.txt",
280
+ lines=200,
281
+ elem_classes="full-height code-box"
282
+ )
 
 
 
283
 
284
  with gr.TabItem("AI μ½”λ”©"):
285
  chatbot = gr.Chatbot(label="λŒ€ν™”", type='messages')
286
  msg = gr.Textbox(label="λ©”μ‹œμ§€")
287
 
 
288
  max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
289
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
290
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
 
321
  inputs=[space_id_state],
322
  outputs=[requirements_content]
323
  )
 
 
 
 
 
 
 
 
 
 
324
 
 
325
  app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
326
 
327
  return demo