openfree commited on
Commit
d57197f
β€’
1 Parent(s): d5c1f25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -22,6 +22,14 @@ def read_uploaded_file(file):
22
  except Exception as e:
23
  return f"νŒŒμΌμ„ μ½λŠ” 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
24
 
 
 
 
 
 
 
 
 
25
  def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
26
  system_prefix = """λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ 닡변할것. λ„ˆλŠ” 주어진 μ†ŒμŠ€μ½”λ“œλ‚˜ 데이터λ₯Ό 기반으둜 "μ„œλΉ„μŠ€ μ‚¬μš© μ„€λͺ… 및 μ•ˆλ‚΄, Q&Aλ₯Ό ν•˜λŠ” 역할이닀". μ•„μ£Ό μΉœμ ˆν•˜κ³  μžμ„Έν•˜κ²Œ 4000토큰 이상 Markdown ν˜•μ‹μœΌλ‘œ μž‘μ„±ν•˜λΌ. λ„ˆλŠ” μž…λ ₯된 λ‚΄μš©μ„ 기반으둜 μ‚¬μš© μ„€λͺ… 및 질의 응닡을 μ§„ν–‰ν•˜λ©°, μ΄μš©μžμ—κ²Œ 도움을 μ£Όμ–΄μ•Ό ν•œλ‹€. μ΄μš©μžκ°€ κΆκΈˆν•΄ ν•  λ§Œν•œ λ‚΄μš©μ— μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όλ„λ‘ ν•˜λΌ. 전체 λ‚΄μš©μ— λŒ€ν•΄μ„œλŠ” λ³΄μ•ˆμ„ μœ μ§€ν•˜κ³ , ν‚€ κ°’ 및 μ—”λ“œν¬μΈνŠΈμ™€ ꡬ체적인 λͺ¨λΈμ€ κ³΅κ°œν•˜μ§€ 마라."""
27
 
@@ -43,11 +51,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
43
  5. κΈ°λŒ€νš¨κ³Ό 및 μž₯점"""
44
 
45
  messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
46
- for val in history:
47
- if val[0]:
48
- messages.append({"role": "user", "content": val[0]})
49
- if val[1]:
50
- messages.append({"role": "assistant", "content": val[1]})
51
  messages.append({"role": "user", "content": message})
52
 
53
  response = ""
@@ -62,21 +66,22 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
62
  token = msg.choices[0].delta.get('content', None)
63
  if token:
64
  response += token
65
- return "", history + [(message, response)]
 
 
66
  except Exception as e:
67
  error_msg = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
68
- return "", history + [(message, error_msg)]
 
69
 
70
  css = """
71
  footer {visibility: hidden}
72
  """
73
 
74
- # ... (이전 μ½”λ“œ 동일)
75
-
76
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
77
  with gr.Row():
78
  with gr.Column(scale=2):
79
- chatbot = gr.Chatbot(height=600, type="messages")
80
  msg = gr.Textbox(
81
  label="λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”",
82
  show_label=False,
@@ -87,9 +92,9 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
87
 
88
  with gr.Column(scale=1):
89
  file_upload = gr.File(
90
- label="파일 μ—…λ‘œλ“œ (.csv, .txt, .py, .js, .html, .parquet)",
91
- file_types=[".csv, .txt, .py, .js, .html, .parquet"],
92
- type="filepath" # 'file'μ—μ„œ 'filepath'둜 μˆ˜μ •
93
  )
94
 
95
  with gr.Accordion("κ³ κΈ‰ μ„€μ •", open=False):
 
22
  except Exception as e:
23
  return f"νŒŒμΌμ„ μ½λŠ” 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
24
 
25
+ def format_history(history):
26
+ formatted_history = []
27
+ for user_msg, assistant_msg in history:
28
+ formatted_history.append({"role": "user", "content": user_msg})
29
+ if assistant_msg:
30
+ formatted_history.append({"role": "assistant", "content": assistant_msg})
31
+ return formatted_history
32
+
33
  def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
34
  system_prefix = """λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ 닡변할것. λ„ˆλŠ” 주어진 μ†ŒμŠ€μ½”λ“œλ‚˜ 데이터λ₯Ό 기반으둜 "μ„œλΉ„μŠ€ μ‚¬μš© μ„€λͺ… 및 μ•ˆλ‚΄, Q&Aλ₯Ό ν•˜λŠ” 역할이닀". μ•„μ£Ό μΉœμ ˆν•˜κ³  μžμ„Έν•˜κ²Œ 4000토큰 이상 Markdown ν˜•μ‹μœΌλ‘œ μž‘μ„±ν•˜λΌ. λ„ˆλŠ” μž…λ ₯된 λ‚΄μš©μ„ 기반으둜 μ‚¬μš© μ„€λͺ… 및 질의 응닡을 μ§„ν–‰ν•˜λ©°, μ΄μš©μžμ—κ²Œ 도움을 μ£Όμ–΄μ•Ό ν•œλ‹€. μ΄μš©μžκ°€ κΆκΈˆν•΄ ν•  λ§Œν•œ λ‚΄μš©μ— μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όλ„λ‘ ν•˜λΌ. 전체 λ‚΄μš©μ— λŒ€ν•΄μ„œλŠ” λ³΄μ•ˆμ„ μœ μ§€ν•˜κ³ , ν‚€ κ°’ 및 μ—”λ“œν¬μΈνŠΈμ™€ ꡬ체적인 λͺ¨λΈμ€ κ³΅κ°œν•˜μ§€ 마라."""
35
 
 
51
  5. κΈ°λŒ€νš¨κ³Ό 및 μž₯점"""
52
 
53
  messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
54
+ messages.extend(format_history(history))
 
 
 
 
55
  messages.append({"role": "user", "content": message})
56
 
57
  response = ""
 
66
  token = msg.choices[0].delta.get('content', None)
67
  if token:
68
  response += token
69
+
70
+ history = history + [[message, response]]
71
+ return "", history
72
  except Exception as e:
73
  error_msg = f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
74
+ history = history + [[message, error_msg]]
75
+ return "", history
76
 
77
  css = """
78
  footer {visibility: hidden}
79
  """
80
 
 
 
81
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
82
  with gr.Row():
83
  with gr.Column(scale=2):
84
+ chatbot = gr.Chatbot(height=600) # type="messages" 제거
85
  msg = gr.Textbox(
86
  label="λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”",
87
  show_label=False,
 
92
 
93
  with gr.Column(scale=1):
94
  file_upload = gr.File(
95
+ label="파일 μ—…λ‘œλ“œ (.cod, .txt, .py, .parquet)",
96
+ file_types=[".cod", ".txt", ".py", ".parquet"],
97
+ type="filepath"
98
  )
99
 
100
  with gr.Accordion("κ³ κΈ‰ μ„€μ •", open=False):