ginipick commited on
Commit
d2b005e
ยท
verified ยท
1 Parent(s): dabbea6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -31
app.py CHANGED
@@ -176,6 +176,8 @@ def respond(
176
 
177
 
178
 
 
 
179
  def create_ui():
180
  try:
181
  css = """
@@ -199,13 +201,6 @@ def create_ui():
199
  }
200
  """
201
 
202
- js = """
203
- function openFile(path, spaceId) {
204
- const event = new CustomEvent('open-file', { detail: { path, spaceId } });
205
- window.dispatchEvent(event);
206
- }
207
- """
208
-
209
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
210
  gr.Markdown("# HuggingFace Space Analyzer")
211
 
@@ -243,7 +238,7 @@ def create_ui():
243
  requirements_content = gr.Textbox(label="requirements.txt", lines=30)
244
 
245
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
246
- chatbot = gr.Chatbot()
247
  msg = gr.Textbox(label="๋ฉ”์‹œ์ง€")
248
  with gr.Row():
249
  system_message = gr.Textbox(label="System Message", value="")
@@ -252,6 +247,7 @@ def create_ui():
252
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
253
 
254
  examples = [
 
255
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
256
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
257
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
@@ -264,7 +260,8 @@ def create_ui():
264
 
265
  def respond_wrapper(message, chat_history, system_message, max_tokens, temperature, top_p):
266
  bot_message = respond(message, chat_history, system_message, max_tokens, temperature, top_p)
267
- chat_history.append((message, bot_message))
 
268
  return "", chat_history
269
 
270
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
@@ -326,26 +323,6 @@ def create_ui():
326
  outputs=[code_tabs, code_tabs]
327
  )
328
 
329
- # JavaScript ์ฝ”๋“œ๋ฅผ HTML์— ์ง์ ‘ ์‚ฝ์ž…
330
- gr.HTML(f"<script>{js}</script>")
331
-
332
- # ํŒŒ์ผ ์—ด๊ธฐ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ถ”๊ฐ€
333
- demo.load(None, None, None, _js="""
334
- () => {
335
- function handleOpenFile(event) {
336
- const { path, spaceId } = event.detail;
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
- window.addEventListener('open-file', handleOpenFile);
346
- }
347
- """)
348
-
349
  return demo
350
 
351
  except Exception as e:
@@ -357,7 +334,22 @@ if __name__ == "__main__":
357
  try:
358
  demo = create_ui()
359
  demo.queue()
360
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  except Exception as e:
362
  print(f"Error in main: {str(e)}")
363
- print(traceback.format_exc())
 
176
 
177
 
178
 
179
+
180
+
181
  def create_ui():
182
  try:
183
  css = """
 
201
  }
202
  """
203
 
 
 
 
 
 
 
 
204
  with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
205
  gr.Markdown("# HuggingFace Space Analyzer")
206
 
 
238
  requirements_content = gr.Textbox(label="requirements.txt", lines=30)
239
 
240
  with gr.TabItem("AI ์ฝ”๋”ฉ"):
241
+ chatbot = gr.Chatbot(label="๋Œ€ํ™”", type="messages")
242
  msg = gr.Textbox(label="๋ฉ”์‹œ์ง€")
243
  with gr.Row():
244
  system_message = gr.Textbox(label="System Message", value="")
 
247
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
248
 
249
  examples = [
250
+
251
  ["์ƒ์„ธํ•œ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋ฉด์„œ ์„ค๋ช…ํ•˜๋“ฏ์ด 4000 ํ† ํฐ ์ด์ƒ ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๋ผ"],
252
  ["FAQ 20๊ฑด์„ ์ƒ์„ธํ•˜๊ฒŒ ์ž‘์„ฑํ•˜๋ผ. 4000ํ† ํฐ ์ด์ƒ ์‚ฌ์šฉํ•˜๋ผ."],
253
  ["์‚ฌ์šฉ ๋ฐฉ๋ฒ•๊ณผ ์ฐจ๋ณ„์ , ํŠน์ง•, ๊ฐ•์ ์„ ์ค‘์‹ฌ์œผ๋กœ 4000 ํ† ํฐ ์ด์ƒ ์œ ํŠœ๋ธŒ ์˜์ƒ ์Šคํฌ๋ฆฝํŠธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑํ•˜๋ผ"],
 
260
 
261
  def respond_wrapper(message, chat_history, system_message, max_tokens, temperature, top_p):
262
  bot_message = respond(message, chat_history, system_message, max_tokens, temperature, top_p)
263
+ chat_history.append({"role": "user", "content": message})
264
+ chat_history.append({"role": "assistant", "content": bot_message})
265
  return "", chat_history
266
 
267
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
 
323
  outputs=[code_tabs, code_tabs]
324
  )
325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  return demo
327
 
328
  except Exception as e:
 
334
  try:
335
  demo = create_ui()
336
  demo.queue()
337
+ demo.launch(
338
+ share=False,
339
+ debug=True,
340
+ show_api=False,
341
+ js="""
342
+ function openFile(path, spaceId) {
343
+ const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
344
+ const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
345
+ if (filePathInput && spaceIdInput) {
346
+ filePathInput.value = path;
347
+ spaceIdInput.value = spaceId;
348
+ filePathInput.dispatchEvent(new Event('change'));
349
+ }
350
+ }
351
+ """
352
+ )
353
  except Exception as e:
354
  print(f"Error in main: {str(e)}")
355
+ print(traceback.format_exc())