ginipick commited on
Commit
14e03a5
ยท
verified ยท
1 Parent(s): 347a801

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -73
app.py CHANGED
@@ -211,76 +211,92 @@ def respond(
211
  def create_ui():
212
  try:
213
  css = """
214
- footer {visibility: hidden;}
 
 
 
 
 
 
 
 
 
215
  .output-group {
216
- border: 1px solid #ddd;
217
- border-radius: 5px;
218
- padding: 10px;
219
  margin-bottom: 20px;
 
 
220
  }
 
221
  .scroll-lock {
222
  overflow-y: auto !important;
223
- max-height: calc((100vh - 200px) / 5) !important;
224
  }
225
  .tree-view-scroll {
226
  overflow-y: auto !important;
227
- max-height: calc((100vh - 200px) / 2) !important;
228
  }
229
  .full-height {
230
- height: calc(200em * 1.2) !important;
231
  overflow-y: auto !important;
232
  }
 
233
  .code-box {
234
  overflow-x: auto !important;
235
  overflow-y: auto !important;
236
  white-space: pre !important;
237
- word-wrap: normal !important;
238
- height: 100% !important;
239
- }
240
- .code-box > div {
241
- min-width: 100% !important;
242
  }
 
243
  .code-box > div > textarea {
244
  word-break: normal !important;
245
  overflow-wrap: normal !important;
246
  }
 
247
  .tab-nav {
248
- background-color: #2c3e50;
249
- border-radius: 5px 5px 0 0;
250
- overflow: hidden;
251
  }
252
  .tab-nav button {
253
- color: #ecf0f1 !important;
254
- background-color: #34495e;
255
  border: none;
256
  padding: 10px 20px;
257
  margin: 0;
258
- transition: background-color 0.3s;
259
  font-size: 16px;
260
- font-weight: bold;
261
- }
262
- .tab-nav button:hover {
263
- background-color: #2980b9;
264
  }
 
265
  .tab-nav button.selected {
266
- color: #2c3e50 !important;
267
- background-color: #ecf0f1;
268
  }
 
269
  input[type="text"], textarea {
270
- color: #2c3e50 !important;
271
- background-color: #ecf0f1 !important;
 
 
 
272
  }
273
  """
274
 
275
- with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
276
- gr.Markdown("# Mouse: HuggingFace")
277
 
278
  with gr.Tabs() as tabs:
279
  with gr.TabItem("๋ถ„์„"):
280
  with gr.Row():
281
- with gr.Column(scale=6): # ์™ผ์ชฝ 60%
282
- url_input = gr.Textbox(label="HuggingFace Space URL")
283
- analyze_button = gr.Button("๋ถ„์„")
284
 
285
  with gr.Group(elem_classes="output-group scroll-lock"):
286
  summary_output = gr.Markdown(label="์š”์•ฝ (3์ค„ ์ด๋‚ด)")
@@ -291,23 +307,21 @@ def create_ui():
291
  with gr.Group(elem_classes="output-group scroll-lock"):
292
  usage_output = gr.Markdown(label="์‚ฌ์šฉ๋ฒ•")
293
 
294
- with gr.Group(elem_classes="output-group tree-view-scroll"): # ํŠธ๋ฆฌ ๋ทฐ ์Šคํฌ๋กค ์ถ”๊ฐ€
295
  tree_view_output = gr.Textbox(label="ํŒŒ์ผ ๊ตฌ์กฐ (Tree View)", lines=30)
296
 
297
- with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ 40%
298
  with gr.Group(elem_classes="output-group full-height"):
299
  code_tabs = gr.Tabs()
300
  with code_tabs:
301
- app_py_tab = gr.TabItem("app.py")
302
- with app_py_tab:
303
  app_py_content = gr.Code(
304
  language="python",
305
  label="app.py",
306
  lines=200,
307
  elem_classes="full-height code-box"
308
  )
309
- requirements_tab = gr.TabItem("requirements.txt")
310
- with requirements_tab:
311
  requirements_content = gr.Textbox(
312
  label="requirements.txt",
313
  lines=200,
@@ -315,11 +329,11 @@ def create_ui():
315
  )
316
 
317
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
318
- chatbot = gr.Chatbot(label="๋Œ€ํ™”")
319
 
320
- msg = gr.Textbox(label="๋ฉ”์‹œ์ง€")
321
 
322
- # ์ˆจ๊ฒจ์ง„ ์ƒํƒœ๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
323
  max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
324
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
325
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
@@ -328,26 +342,24 @@ def create_ui():
328
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
329
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
330
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
331
- ["๋ณธ ์„œ๋น„์Šค๋ฅผ SEO ์ตœ์ ํ™”ํ•˜์—ฌ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ(๋ฐฐ๊ฒฝ ๋ฐ ํ•„์š”์„ฑ, ๊ธฐ์กด ์œ ์‚ฌ ์„œ๋น„์Šค์™€ ๋น„๊ตํ•˜์—ฌ ํŠน์žฅ์ , ํ™œ์šฉ์ฒ˜, ๊ฐ€์น˜, ๊ธฐ๋Œ€ํšจ๊ณผ, ๊ฒฐ๋ก ์„ ํฌํ•จ)๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ"],
332
- ["ํŠนํ—ˆ ์ถœ์›์— ํ™œ์šฉํ•  ๊ธฐ์ˆ  ๋ฐ ๋น„์ฆˆ๋‹ˆ์Šค๋ชจ๋ธ ์ธก๋ฉด์„ ํฌํ•จํ•˜์—ฌ ํŠนํ—ˆ ์ถœ์›์„œ ๊ตฌ์„ฑ์— ๋งž๊ฒŒ ํ˜์‹ ์ ์ธ ์ฐฝ์˜ ๋ฐœ๋ช… ๋‚ด์šฉ์„ ์ค‘์‹ฌ์œผ๋กœ 4000ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ."],
333
  ["๊ณ„์† ์ด์–ด์„œ ๋‹ต๋ณ€ํ•˜๋ผ"],
334
  ]
335
-
336
  gr.Examples(examples, inputs=msg)
337
 
338
  def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
339
  bot_message = ""
340
  for response in respond(message, chat_history, max_tokens=max_tokens, temperature=temperature, top_p=top_p):
341
- bot_message = response # ๋งˆ์ง€๋ง‰ ์‘๋‹ต์„ ์ €์žฅ
342
  yield "", chat_history + [(message, bot_message)]
343
 
344
  chat_history.append((message, bot_message))
345
  return "", chat_history
346
 
347
-
348
-
349
  msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
350
 
 
351
  space_id_state = gr.State()
352
  tree_structure_state = gr.State()
353
  app_py_content_lines = gr.State()
@@ -362,7 +374,7 @@ def create_ui():
362
  outputs=[requirements_content]
363
  )
364
 
365
- # lines ์ˆ˜๋ฅผ ๋™์ ์œผ๋กœ ์„ค์ •
366
  app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
367
 
368
  return demo
@@ -371,29 +383,3 @@ def create_ui():
371
  print(f"Error in create_ui: {str(e)}")
372
  print(traceback.format_exc())
373
  raise
374
-
375
-
376
- if __name__ == "__main__":
377
- try:
378
- print("Starting HuggingFace Space Analyzer...")
379
- demo = create_ui()
380
- print("UI created successfully.")
381
-
382
- print("Configuring Gradio queue...")
383
- demo.queue()
384
- print("Gradio queue configured.")
385
-
386
- print("Launching Gradio app...")
387
- demo.launch(
388
- server_name="0.0.0.0",
389
- server_port=7860,
390
- share=False,
391
- debug=True,
392
- show_api=False
393
- )
394
- print("Gradio app launched successfully.")
395
- except Exception as e:
396
- print(f"Error in main: {str(e)}")
397
- print("Detailed error information:")
398
- print(traceback.format_exc())
399
- raise
 
211
  def create_ui():
212
  try:
213
  css = """
214
+ /* ์ „์ฒด ๋ฐฐ๊ฒฝ ๋ฐ ๊ธฐ๋ณธ ๊ธ€๊ผด ์„ค์ • */
215
+ body {
216
+ background-color: #f9f9f9;
217
+ font-family: 'Helvetica Neue', Arial, sans-serif;
218
+ color: #333;
219
+ }
220
+ /* ํ•˜๋‹จ ํ‘ธํ„ฐ ์ˆจ๊น€ */
221
+ footer { visibility: hidden; }
222
+
223
+ /* ์ถœ๋ ฅ ๊ทธ๋ฃน ์Šคํƒ€์ผ: ๋ฐ์€ ๋ฐฐ๊ฒฝ, ๋ถ€๋“œ๋Ÿฌ์šด ํ…Œ๋‘๋ฆฌ์™€ ๊ทธ๋ฆผ์ž */
224
  .output-group {
225
+ border: 1px solid #ccc;
226
+ border-radius: 8px;
227
+ padding: 15px;
228
  margin-bottom: 20px;
229
+ background-color: #ffffff;
230
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
231
  }
232
+ /* ์Šคํฌ๋กค ์˜์—ญ ์„ค์ • */
233
  .scroll-lock {
234
  overflow-y: auto !important;
235
+ max-height: 300px !important;
236
  }
237
  .tree-view-scroll {
238
  overflow-y: auto !important;
239
+ max-height: 400px !important;
240
  }
241
  .full-height {
242
+ height: 80vh !important;
243
  overflow-y: auto !important;
244
  }
245
+ /* ์ฝ”๋“œ ๋ฐ•์Šค ์Šคํƒ€์ผ: ๋ชจ๋…ธ์ŠคํŽ˜์ด์Šค ํฐํŠธ์™€ ๋ฐ์€ ๋ฐฐ๊ฒฝ */
246
  .code-box {
247
  overflow-x: auto !important;
248
  overflow-y: auto !important;
249
  white-space: pre !important;
250
+ background-color: #f5f5f5;
251
+ border-radius: 4px;
252
+ padding: 10px;
253
+ font-family: 'Courier New', Courier, monospace;
 
254
  }
255
+ .code-box > div { min-width: 100% !important; }
256
  .code-box > div > textarea {
257
  word-break: normal !important;
258
  overflow-wrap: normal !important;
259
  }
260
+ /* ํƒญ ๋‚ด๋น„๊ฒŒ์ด์…˜ ์Šคํƒ€์ผ: ๋‹จ์ˆœํ•˜๊ณ  ๊น”๋”ํ•œ ๋””์ž์ธ */
261
  .tab-nav {
262
+ background-color: #ffffff;
263
+ border-bottom: 1px solid #ccc;
264
+ display: flex;
265
  }
266
  .tab-nav button {
267
+ background: none;
 
268
  border: none;
269
  padding: 10px 20px;
270
  margin: 0;
271
+ cursor: pointer;
272
  font-size: 16px;
273
+ color: #555;
274
+ transition: color 0.3s, border-bottom 0.3s;
 
 
275
  }
276
+ .tab-nav button:hover,
277
  .tab-nav button.selected {
278
+ color: #000;
279
+ border-bottom: 2px solid #007BFF;
280
  }
281
+ /* ์ž…๋ ฅ์ฐฝ ๋ฐ ํ…์ŠคํŠธ ์˜์—ญ ์Šคํƒ€์ผ */
282
  input[type="text"], textarea {
283
+ color: #333;
284
+ background-color: #fff;
285
+ border: 1px solid #ccc;
286
+ border-radius: 4px;
287
+ padding: 8px;
288
  }
289
  """
290
 
291
+ with gr.Blocks(theme="default", css=css) as demo:
292
+ gr.Markdown("# Mouse: HuggingFace", elem_classes="header-markdown")
293
 
294
  with gr.Tabs() as tabs:
295
  with gr.TabItem("๋ถ„์„"):
296
  with gr.Row():
297
+ with gr.Column(scale=6): # ์™ผ์ชฝ ์˜์—ญ
298
+ url_input = gr.Textbox(label="HuggingFace Space URL", placeholder="์˜ˆ: https://huggingface.co/spaces/username/space_name")
299
+ analyze_button = gr.Button("๋ถ„์„", variant="primary")
300
 
301
  with gr.Group(elem_classes="output-group scroll-lock"):
302
  summary_output = gr.Markdown(label="์š”์•ฝ (3์ค„ ์ด๋‚ด)")
 
307
  with gr.Group(elem_classes="output-group scroll-lock"):
308
  usage_output = gr.Markdown(label="์‚ฌ์šฉ๋ฒ•")
309
 
310
+ with gr.Group(elem_classes="output-group tree-view-scroll"):
311
  tree_view_output = gr.Textbox(label="ํŒŒ์ผ ๊ตฌ์กฐ (Tree View)", lines=30)
312
 
313
+ with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ ์˜์—ญ
314
  with gr.Group(elem_classes="output-group full-height"):
315
  code_tabs = gr.Tabs()
316
  with code_tabs:
317
+ with gr.TabItem("app.py"):
 
318
  app_py_content = gr.Code(
319
  language="python",
320
  label="app.py",
321
  lines=200,
322
  elem_classes="full-height code-box"
323
  )
324
+ with gr.TabItem("requirements.txt"):
 
325
  requirements_content = gr.Textbox(
326
  label="requirements.txt",
327
  lines=200,
 
329
  )
330
 
331
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
332
+ chatbot = gr.Chatbot(label="๋Œ€ํ™”", elem_classes="output-group full-height")
333
 
334
+ msg = gr.Textbox(label="๋ฉ”์‹œ์ง€", placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
335
 
336
+ # ์ˆจ๊ฒจ์ง„ ํŒŒ๋ผ๋ฏธํ„ฐ
337
  max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
338
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
339
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
 
342
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
343
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
344
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
345
+ ["๋ณธ ์„œ๋น„์Šค๋ฅผ SEO ์ตœ์ ํ™”ํ•˜์—ฌ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ"],
346
+ ["ํŠนํ—ˆ ์ถœ์›์— ํ™œ์šฉํ•  ํ˜์‹ ์ ์ธ ์ฐฝ์˜ ๋ฐœ๋ช… ๋‚ด์šฉ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์ž‘์„ฑํ•˜๋ผ."],
347
  ["๊ณ„์† ์ด์–ด์„œ ๋‹ต๋ณ€ํ•˜๋ผ"],
348
  ]
 
349
  gr.Examples(examples, inputs=msg)
350
 
351
  def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
352
  bot_message = ""
353
  for response in respond(message, chat_history, max_tokens=max_tokens, temperature=temperature, top_p=top_p):
354
+ bot_message = response # ๋งˆ์ง€๋ง‰ ์‘๋‹ต ์ €์žฅ
355
  yield "", chat_history + [(message, bot_message)]
356
 
357
  chat_history.append((message, bot_message))
358
  return "", chat_history
359
 
 
 
360
  msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
361
 
362
+ # ์ƒํƒœ ์ €์žฅ์šฉ ๋ณ€์ˆ˜
363
  space_id_state = gr.State()
364
  tree_structure_state = gr.State()
365
  app_py_content_lines = gr.State()
 
374
  outputs=[requirements_content]
375
  )
376
 
377
+ # ๋™์ ์œผ๋กœ app.py์˜ ์ค„ ์ˆ˜ ์กฐ์ •
378
  app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
379
 
380
  return demo
 
383
  print(f"Error in create_ui: {str(e)}")
384
  print(traceback.format_exc())
385
  raise