openfree commited on
Commit
2ff143a
β€’
1 Parent(s): 4fec5a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -1
app.py CHANGED
@@ -109,8 +109,72 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
109
  항상 예의 λ°”λ₯΄κ³  μΉœμ ˆν•˜κ²Œ μ‘λ‹΅ν•˜λ©°, ν•„μš”ν•œ 경우 ꡬ체적인 μ˜ˆμ‹œλ‚˜ μ„€λͺ…을 μΆ”κ°€ν•˜μ—¬
110
  이해λ₯Ό λ•κ² μŠ΅λ‹ˆλ‹€."""
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # UI ν…μŠ€νŠΈ ν•œκΈ€ν™”
113
- with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", title="AI μ–΄μ‹œμŠ€ν„΄νŠΈ πŸ€–") as demo:
114
  gr.HTML(
115
  """
116
  <div style="text-align: center; max-width: 800px; margin: 0 auto;">
 
109
  항상 예의 λ°”λ₯΄κ³  μΉœμ ˆν•˜κ²Œ μ‘λ‹΅ν•˜λ©°, ν•„μš”ν•œ 경우 ꡬ체적인 μ˜ˆμ‹œλ‚˜ μ„€λͺ…을 μΆ”κ°€ν•˜μ—¬
110
  이해λ₯Ό λ•κ² μŠ΅λ‹ˆλ‹€."""
111
 
112
+ if uploaded_file:
113
+ content, file_type = read_uploaded_file(uploaded_file)
114
+ if file_type == "error":
115
+ return "", [{"role": "user", "content": message}, {"role": "assistant", "content": content}]
116
+
117
+ file_summary = analyze_file_content(content, file_type)
118
+
119
+ if file_type in ['parquet', 'csv']:
120
+ system_message += f"\n\n파일 λ‚΄μš©:\n```markdown\n{content}\n```"
121
+ else:
122
+ system_message += f"\n\n파일 λ‚΄μš©:\n```\n{content}\n```"
123
+
124
+ if message == "Starting file analysis...":
125
+ message = f"""[파일 ꡬ쑰 뢄석] {file_summary}
126
+
127
+ λ‹€μŒ κ΄€μ μ—μ„œ 도움을 λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€:
128
+ 1. πŸ“‹ μ „λ°˜μ μΈ λ‚΄μš© νŒŒμ•…
129
+ 2. πŸ’‘ μ£Όμš” νŠΉμ§• μ„€λͺ…
130
+ 3. 🎯 μ‹€μš©μ μΈ ν™œμš© λ°©μ•ˆ
131
+ 4. ✨ κ°œμ„  μ œμ•ˆ
132
+ 5. πŸ’¬ μΆ”κ°€ μ§ˆλ¬Έμ΄λ‚˜ ν•„μš”ν•œ μ„€λͺ…"""
133
+
134
+ messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
135
+
136
+ if history is not None:
137
+ for item in history:
138
+ if isinstance(item, dict):
139
+ messages.append(item)
140
+ elif isinstance(item, (list, tuple)) and len(item) == 2:
141
+ messages.append({"role": "user", "content": item[0]})
142
+ if item[1]:
143
+ messages.append({"role": "assistant", "content": item[1]})
144
+
145
+ messages.append({"role": "user", "content": message})
146
+
147
+ try:
148
+ client = get_client()
149
+ partial_message = ""
150
+ current_history = []
151
+
152
+ for msg in client.chat_completion(
153
+ messages,
154
+ max_tokens=max_tokens,
155
+ stream=True,
156
+ temperature=temperature,
157
+ top_p=top_p,
158
+ ):
159
+ token = msg.choices[0].delta.get('content', None)
160
+ if token:
161
+ partial_message += token
162
+ current_history = [
163
+ {"role": "user", "content": message},
164
+ {"role": "assistant", "content": partial_message}
165
+ ]
166
+ yield "", current_history
167
+
168
+ except Exception as e:
169
+ error_msg = f"❌ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
170
+ error_history = [
171
+ {"role": "user", "content": message},
172
+ {"role": "assistant", "content": error_msg}
173
+ ]
174
+ yield "", error_history
175
+
176
  # UI ν…μŠ€νŠΈ ν•œκΈ€ν™”
177
+ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", title="GiniGEN πŸ€–") as demo:
178
  gr.HTML(
179
  """
180
  <div style="text-align: center; max-width: 800px; margin: 0 auto;">