cutechicken commited on
Commit
0223744
ยท
verified ยท
1 Parent(s): 0de5bb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +235 -134
app.py CHANGED
@@ -8,10 +8,15 @@ import random
8
  from datasets import load_dataset
9
  import numpy as np
10
  from sklearn.feature_extraction.text import TfidfVectorizer
 
 
 
 
11
 
12
  # GPU ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ
13
  torch.cuda.empty_cache()
14
 
 
15
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
16
  MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
17
  MODELS = os.environ.get("MODELS")
@@ -36,6 +41,64 @@ vectorizer = TfidfVectorizer(max_features=1000)
36
  question_vectors = vectorizer.fit_transform(questions)
37
  print("TF-IDF ๋ฒกํ„ฐํ™” ์™„๋ฃŒ")
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  def find_relevant_context(query, top_k=3):
40
  # ์ฟผ๋ฆฌ ๋ฒกํ„ฐํ™”
41
  query_vector = vectorizer.transform([query])
@@ -49,7 +112,7 @@ def find_relevant_context(query, top_k=3):
49
  # ๊ด€๋ จ ์ปจํ…์ŠคํŠธ ์ถ”์ถœ
50
  relevant_contexts = []
51
  for idx in top_indices:
52
- if similarities[idx] > 0: # ์œ ์‚ฌ๋„๊ฐ€ 0๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ๋งŒ ํฌํ•จ
53
  relevant_contexts.append({
54
  'question': questions[idx],
55
  'answer': wiki_dataset['train']['answer'][idx],
@@ -58,16 +121,94 @@ def find_relevant_context(query, top_k=3):
58
 
59
  return relevant_contexts
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  @spaces.GPU
62
- def stream_chat(message: str, history: list, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float):
63
  print(f'message is - {message}')
64
  print(f'history is - {history}')
65
 
 
 
 
 
 
 
 
66
  # ๊ด€๋ จ ์ปจํ…์ŠคํŠธ ์ฐพ๊ธฐ
67
  relevant_contexts = find_relevant_context(message)
68
- context_prompt = "\n\n๊ด€๋ จ ์ฐธ๊ณ  ์ •๋ณด:\n"
69
  for ctx in relevant_contexts:
70
- context_prompt += f"Q: {ctx['question']}\nA: {ctx['answer']}\n์œ ์‚ฌ๋„: {ctx['similarity']:.3f}\n\n"
71
 
72
  # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ๊ตฌ์„ฑ
73
  conversation = []
@@ -76,15 +217,13 @@ def stream_chat(message: str, history: list, temperature: float, max_new_tokens:
76
  {"role": "user", "content": prompt},
77
  {"role": "assistant", "content": answer}
78
  ])
79
-
80
 
81
- # ์ปจํ…์ŠคํŠธ๋ฅผ ํฌํ•จํ•œ ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ ๊ตฌ์„ฑ
82
- final_message = context_prompt + "\nํ˜„์žฌ ์งˆ๋ฌธ: " + message
83
  conversation.append({"role": "user", "content": final_message})
84
 
85
  input_ids = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
86
  inputs = tokenizer(input_ids, return_tensors="pt").to(0)
87
-
88
 
89
  streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
90
 
@@ -108,8 +247,6 @@ def stream_chat(message: str, history: list, temperature: float, max_new_tokens:
108
  buffer += new_text
109
  yield buffer
110
 
111
- chatbot = gr.Chatbot(height=500)
112
-
113
  CSS = """
114
  /* ์ „์ฒด ํŽ˜์ด์ง€ ์Šคํƒ€์ผ๋ง */
115
  body {
@@ -117,131 +254,72 @@ body {
117
  min-height: 100vh;
118
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
119
  }
120
- /* ๋ฉ”์ธ ์ปจํ…Œ์ด๋„ˆ */
121
- .container {
122
- max-width: 1200px;
123
- margin: 0 auto;
124
- padding: 2rem;
125
- background: rgba(255, 255, 255, 0.95);
126
- border-radius: 20px;
127
- box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
128
- backdrop-filter: blur(10px);
129
- transform: perspective(1000px) translateZ(0);
130
- transition: all 0.3s ease;
131
- }
132
- /* ์ œ๋ชฉ ์Šคํƒ€์ผ๋ง */
133
- h1 {
134
- color: #2d3436;
135
- font-size: 2.5rem;
136
- text-align: center;
137
- margin-bottom: 2rem;
138
- text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
139
- transform: perspective(1000px) translateZ(20px);
140
- }
141
- h3 {
142
- text-align: center;
143
- color: #2d3436;
144
- font-size: 1.5rem;
145
- margin: 1rem 0;
146
- }
147
- /* ์ฑ„ํŒ…๋ฐ•์Šค ์Šคํƒ€์ผ๋ง */
148
- .chatbox {
149
- background: white;
150
- border-radius: 15px;
151
- box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
152
- backdrop-filter: blur(4px);
153
- border: 1px solid rgba(255, 255, 255, 0.18);
154
- padding: 1rem;
155
- margin: 1rem 0;
156
- transform: translateZ(0);
157
- transition: all 0.3s ease;
158
- }
159
- /* ๋ฉ”์‹œ์ง€ ์Šคํƒ€์ผ๋ง */
160
- .chatbox .messages .message.user {
161
- background: linear-gradient(145deg, #e1f5fe, #bbdefb);
162
- border-radius: 15px;
163
- padding: 1rem;
164
- margin: 0.5rem;
165
- box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.05);
166
- transform: translateZ(10px);
167
- animation: messageIn 0.3s ease-out;
168
- }
169
- .chatbox .messages .message.bot {
170
- background: linear-gradient(145deg, #f5f5f5, #eeeeee);
171
- border-radius: 15px;
172
- padding: 1rem;
173
- margin: 0.5rem;
174
- box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.05);
175
- transform: translateZ(10px);
176
- animation: messageIn 0.3s ease-out;
177
- }
178
- /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ๋ง */
179
- .duplicate-button {
180
- background: linear-gradient(145deg, #24292e, #1a1e22) !important;
181
- color: white !important;
182
- border-radius: 100vh !important;
183
- padding: 0.8rem 1.5rem !important;
184
- box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2) !important;
185
- transition: all 0.3s ease !important;
186
- border: none !important;
187
- cursor: pointer !important;
188
- }
189
- .duplicate-button:hover {
190
- transform: translateY(-2px) !important;
191
- box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3) !important;
192
- }
193
- /* ์ž…๋ ฅ ํ•„๋“œ ์Šคํƒ€์ผ๋ง */
194
  """
195
 
196
  with gr.Blocks(css=CSS) as demo:
197
- gr.ChatInterface(
198
- fn=stream_chat,
199
- chatbot=chatbot,
200
- fill_height=True,
201
- theme="soft",
202
- additional_inputs_accordion=gr.Accordion(label="โš™๏ธ ์˜ต์…˜", open=False, render=False),
203
- additional_inputs=[
204
- gr.Slider(
205
- minimum=0,
206
- maximum=1,
207
- step=0.1,
208
- value=0.8,
209
- label="์˜จ๋„",
210
- render=False,
211
- ),
212
- gr.Slider(
213
- minimum=128,
214
- maximum=8000,
215
- step=1,
216
- value=4000,
217
- label="์ตœ๋Œ€ ํ† ํฐ ์ˆ˜",
218
- render=False,
219
- ),
220
- gr.Slider(
221
- minimum=0.0,
222
- maximum=1.0,
223
- step=0.1,
224
- value=0.8,
225
- label="์ƒ์œ„ ํ™•๋ฅ ",
226
- render=False,
227
- ),
228
- gr.Slider(
229
- minimum=1,
230
- maximum=20,
231
- step=1,
232
- value=20,
233
- label="์ƒ์œ„ K",
234
- render=False,
235
- ),
236
- gr.Slider(
237
- minimum=0.0,
238
- maximum=2.0,
239
- step=0.1,
240
- value=1.0,
241
- label="๋ฐ˜๋ณต ํŒจ๋„ํ‹ฐ",
242
- render=False,
243
- ),
244
- ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  examples=[
246
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ์ ˆ๊ธฐ์™€ 24์ ˆ๊ธฐ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
247
  ["์šฐ๋ฆฌ๋‚˜๋ผ ์ „ํ†ต ์Œ์‹ ์ค‘ ๊ฑด๊ฐ•์— ์ข‹์€ ๋ฐœํšจ์Œ์‹ 5๊ฐ€์ง€๋ฅผ ์ถ”์ฒœํ•˜๊ณ  ๊ทธ ํšจ๋Šฅ์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
@@ -256,8 +334,31 @@ with gr.Blocks(css=CSS) as demo:
256
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ์˜๋ณต์ธ ํ•œ๋ณต์˜ ๊ตฌ์กฐ์™€ ํŠน์ง•์„ ๊ณผํ•™์ , ๋ฏธํ•™์  ๊ด€์ ์—์„œ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”."],
257
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ๊ฐ€์˜ฅ ๊ตฌ์กฐ๋ฅผ ๊ธฐํ›„์™€ ํ™˜๊ฒฝ ๊ด€์ ์—์„œ ๋ถ„์„ํ•˜๊ณ , ํ˜„๋Œ€ ๊ฑด์ถ•์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์š”์†Œ๋ฅผ ์ œ์•ˆํ•ด์ฃผ์„ธ์š”."]
258
  ],
259
- cache_examples=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  )
261
 
262
  if __name__ == "__main__":
263
- demo.launch()
 
8
  from datasets import load_dataset
9
  import numpy as np
10
  from sklearn.feature_extraction.text import TfidfVectorizer
11
+ import pandas as pd
12
+ from typing import List, Tuple
13
+ import json
14
+ from datetime import datetime
15
 
16
  # GPU ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ
17
  torch.cuda.empty_cache()
18
 
19
+ # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
20
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
21
  MODEL_ID = "CohereForAI/c4ai-command-r7b-12-2024"
22
  MODELS = os.environ.get("MODELS")
 
41
  question_vectors = vectorizer.fit_transform(questions)
42
  print("TF-IDF ๋ฒกํ„ฐํ™” ์™„๋ฃŒ")
43
 
44
+ class ChatHistory:
45
+ def __init__(self):
46
+ self.history = []
47
+ self.history_file = "/tmp/chat_history.json"
48
+ self.load_history()
49
+
50
+ def add_conversation(self, user_msg: str, assistant_msg: str):
51
+ conversation = {
52
+ "timestamp": datetime.now().isoformat(),
53
+ "messages": [
54
+ {"role": "user", "content": user_msg},
55
+ {"role": "assistant", "content": assistant_msg}
56
+ ]
57
+ }
58
+ self.history.append(conversation)
59
+ self.save_history()
60
+
61
+ def format_for_display(self):
62
+ formatted = []
63
+ for conv in self.history:
64
+ formatted.append([
65
+ conv["messages"][0]["content"],
66
+ conv["messages"][1]["content"]
67
+ ])
68
+ return formatted
69
+
70
+ def get_messages_for_api(self):
71
+ messages = []
72
+ for conv in self.history:
73
+ messages.extend([
74
+ {"role": "user", "content": conv["messages"][0]["content"]},
75
+ {"role": "assistant", "content": conv["messages"][1]["content"]}
76
+ ])
77
+ return messages
78
+
79
+ def clear_history(self):
80
+ self.history = []
81
+ self.save_history()
82
+
83
+ def save_history(self):
84
+ try:
85
+ with open(self.history_file, 'w', encoding='utf-8') as f:
86
+ json.dump(self.history, f, ensure_ascii=False, indent=2)
87
+ except Exception as e:
88
+ print(f"ํžˆ์Šคํ† ๋ฆฌ ์ €์žฅ ์‹คํŒจ: {e}")
89
+
90
+ def load_history(self):
91
+ try:
92
+ if os.path.exists(self.history_file):
93
+ with open(self.history_file, 'r', encoding='utf-8') as f:
94
+ self.history = json.load(f)
95
+ except Exception as e:
96
+ print(f"ํžˆ์Šคํ† ๋ฆฌ ๋กœ๋“œ ์‹คํŒจ: {e}")
97
+ self.history = []
98
+
99
+ # ์ „์—ญ ChatHistory ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
100
+ chat_history = ChatHistory()
101
+
102
  def find_relevant_context(query, top_k=3):
103
  # ์ฟผ๋ฆฌ ๋ฒกํ„ฐํ™”
104
  query_vector = vectorizer.transform([query])
 
112
  # ๊ด€๋ จ ์ปจํ…์ŠคํŠธ ์ถ”์ถœ
113
  relevant_contexts = []
114
  for idx in top_indices:
115
+ if similarities[idx] > 0:
116
  relevant_contexts.append({
117
  'question': questions[idx],
118
  'answer': wiki_dataset['train']['answer'][idx],
 
121
 
122
  return relevant_contexts
123
 
124
+ def analyze_file_content(content, file_type):
125
+ """Analyze file content and return structural summary"""
126
+ if file_type in ['parquet', 'csv']:
127
+ try:
128
+ lines = content.split('\n')
129
+ header = lines[0]
130
+ columns = header.count('|') - 1
131
+ rows = len(lines) - 3
132
+ return f"๐Ÿ“Š ๋ฐ์ดํ„ฐ์…‹ ๊ตฌ์กฐ: {columns}๊ฐœ ์ปฌ๋Ÿผ, {rows}๊ฐœ ๋ฐ์ดํ„ฐ"
133
+ except:
134
+ return "โŒ ๋ฐ์ดํ„ฐ์…‹ ๊ตฌ์กฐ ๋ถ„์„ ์‹คํŒจ"
135
+
136
+ lines = content.split('\n')
137
+ total_lines = len(lines)
138
+ non_empty_lines = len([line for line in lines if line.strip()])
139
+
140
+ if any(keyword in content.lower() for keyword in ['def ', 'class ', 'import ', 'function']):
141
+ functions = len([line for line in lines if 'def ' in line])
142
+ classes = len([line for line in lines if 'class ' in line])
143
+ imports = len([line for line in lines if 'import ' in line or 'from ' in line])
144
+ return f"๐Ÿ’ป ์ฝ”๋“œ ๊ตฌ์กฐ: {total_lines}์ค„ (ํ•จ์ˆ˜: {functions}, ํด๋ž˜์Šค: {classes}, ์ž„ํฌํŠธ: {imports})"
145
+
146
+ paragraphs = content.count('\n\n') + 1
147
+ words = len(content.split())
148
+ return f"๐Ÿ“ ๋ฌธ์„œ ๊ตฌ์กฐ: {total_lines}์ค„, {paragraphs}๋‹จ๋ฝ, ์•ฝ {words}๋‹จ์–ด"
149
+
150
+ def read_uploaded_file(file):
151
+ if file is None:
152
+ return "", ""
153
+ try:
154
+ file_ext = os.path.splitext(file.name)[1].lower()
155
+
156
+ if file_ext == '.parquet':
157
+ df = pd.read_parquet(file.name, engine='pyarrow')
158
+ content = df.head(10).to_markdown(index=False)
159
+ return content, "parquet"
160
+ elif file_ext == '.csv':
161
+ encodings = ['utf-8', 'cp949', 'euc-kr', 'latin1']
162
+ for encoding in encodings:
163
+ try:
164
+ df = pd.read_csv(file.name, encoding=encoding)
165
+ content = f"๐Ÿ“Š ๋ฐ์ดํ„ฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:\n{df.head(10).to_markdown(index=False)}\n\n"
166
+ content += f"\n๐Ÿ“ˆ ๋ฐ์ดํ„ฐ ์ •๋ณด:\n"
167
+ content += f"- ์ „์ฒด ํ–‰ ์ˆ˜: {len(df)}\n"
168
+ content += f"- ์ „์ฒด ์—ด ์ˆ˜: {len(df.columns)}\n"
169
+ content += f"- ์ปฌ๋Ÿผ ๋ชฉ๋ก: {', '.join(df.columns)}\n"
170
+ content += f"\n๐Ÿ“‹ ์ปฌ๋Ÿผ ๋ฐ์ดํ„ฐ ํƒ€์ž…:\n"
171
+ for col, dtype in df.dtypes.items():
172
+ content += f"- {col}: {dtype}\n"
173
+ null_counts = df.isnull().sum()
174
+ if null_counts.any():
175
+ content += f"\nโš ๏ธ ๊ฒฐ์ธก์น˜:\n"
176
+ for col, null_count in null_counts[null_counts > 0].items():
177
+ content += f"- {col}: {null_count}๊ฐœ ๋ˆ„๋ฝ\n"
178
+ return content, "csv"
179
+ except UnicodeDecodeError:
180
+ continue
181
+ raise UnicodeDecodeError(f"โŒ ์ง€์›๋˜๋Š” ์ธ์ฝ”๋”ฉ์œผ๋กœ ํŒŒ์ผ์„ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค ({', '.join(encodings)})")
182
+ else:
183
+ encodings = ['utf-8', 'cp949', 'euc-kr', 'latin1']
184
+ for encoding in encodings:
185
+ try:
186
+ with open(file.name, 'r', encoding=encoding) as f:
187
+ content = f.read()
188
+ return content, "text"
189
+ except UnicodeDecodeError:
190
+ continue
191
+ raise UnicodeDecodeError(f"โŒ ์ง€์›๋˜๋Š” ์ธ์ฝ”๋”ฉ์œผ๋กœ ํŒŒ์ผ์„ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค ({', '.join(encodings)})")
192
+ except Exception as e:
193
+ return f"โŒ ํŒŒ์ผ ์ฝ๊ธฐ ์˜ค๋ฅ˜: {str(e)}", "error"
194
+
195
  @spaces.GPU
196
+ def stream_chat(message: str, history: list, uploaded_file, temperature: float, max_new_tokens: int, top_p: float, top_k: int, penalty: float):
197
  print(f'message is - {message}')
198
  print(f'history is - {history}')
199
 
200
+ # ํŒŒ์ผ ์—…๋กœ๋“œ ์ฒ˜๋ฆฌ
201
+ file_context = ""
202
+ if uploaded_file:
203
+ content, file_type = read_uploaded_file(uploaded_file)
204
+ if content:
205
+ file_context = f"\n\n์—…๋กœ๋“œ๋œ ํŒŒ์ผ ๋‚ด์šฉ:\n```\n{content}\n```"
206
+
207
  # ๊ด€๋ จ ์ปจํ…์ŠคํŠธ ์ฐพ๊ธฐ
208
  relevant_contexts = find_relevant_context(message)
209
+ wiki_context = "\n\n๊ด€๋ จ ์œ„ํ‚คํ”ผ๋””์•„ ์ •๋ณด:\n"
210
  for ctx in relevant_contexts:
211
+ wiki_context += f"Q: {ctx['question']}\nA: {ctx['answer']}\n์œ ์‚ฌ๋„: {ctx['similarity']:.3f}\n\n"
212
 
213
  # ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ๊ตฌ์„ฑ
214
  conversation = []
 
217
  {"role": "user", "content": prompt},
218
  {"role": "assistant", "content": answer}
219
  ])
 
220
 
221
+ # ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ ๊ตฌ์„ฑ
222
+ final_message = file_context + wiki_context + "\nํ˜„์žฌ ์งˆ๋ฌธ: " + message
223
  conversation.append({"role": "user", "content": final_message})
224
 
225
  input_ids = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
226
  inputs = tokenizer(input_ids, return_tensors="pt").to(0)
 
227
 
228
  streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
229
 
 
247
  buffer += new_text
248
  yield buffer
249
 
 
 
250
  CSS = """
251
  /* ์ „์ฒด ํŽ˜์ด์ง€ ์Šคํƒ€์ผ๋ง */
252
  body {
 
254
  min-height: 100vh;
255
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
256
  }
257
+ /* ... (์ด์ „์˜ CSS ์Šคํƒ€์ผ ์œ ์ง€) ... */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  """
259
 
260
  with gr.Blocks(css=CSS) as demo:
261
+ with gr.Row():
262
+ with gr.Column(scale=2):
263
+ chatbot = gr.Chatbot(height=500)
264
+
265
+ msg = gr.Textbox(
266
+ label="๋ฉ”์‹œ์ง€ ์ž…๋ ฅ",
267
+ show_label=False,
268
+ placeholder="๋ฌด์—‡์ด๋“  ๋ฌผ์–ด๋ณด์„ธ์š”... ๐Ÿ’ญ",
269
+ container=False
270
+ )
271
+
272
+ with gr.Row():
273
+ clear = gr.ClearButton([msg, chatbot], value="๋Œ€ํ™”๋‚ด์šฉ ์ง€์šฐ๊ธฐ")
274
+ send = gr.Button("๋ณด๋‚ด๊ธฐ ๐Ÿ“ค")
275
+
276
+ with gr.Column(scale=1):
277
+ gr.Markdown("### ํŒŒ์ผ ์—…๋กœ๋“œ ๐Ÿ“")
278
+ file_upload = gr.File(
279
+ label="ํŒŒ์ผ ์„ ํƒ",
280
+ file_types=["text", ".csv", ".parquet"],
281
+ type="filepath"
282
+ )
283
+
284
+ with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ • โš™๏ธ", open=False):
285
+ temperature = gr.Slider(
286
+ minimum=0,
287
+ maximum=1,
288
+ step=0.1,
289
+ value=0.8,
290
+ label="์˜จ๋„",
291
+ )
292
+ max_new_tokens = gr.Slider(
293
+ minimum=128,
294
+ maximum=8000,
295
+ step=1,
296
+ value=4000,
297
+ label="์ตœ๋Œ€ ํ† ํฐ ์ˆ˜",
298
+ )
299
+ top_p = gr.Slider(
300
+ minimum=0.0,
301
+ maximum=1.0,
302
+ step=0.1,
303
+ value=0.8,
304
+ label="์ƒ์œ„ ํ™•๋ฅ ",
305
+ )
306
+ top_k = gr.Slider(
307
+ minimum=1,
308
+ maximum=20,
309
+ step=1,
310
+ value=20,
311
+ label="์ƒ์œ„ K",
312
+ )
313
+ penalty = gr.Slider(
314
+ minimum=0.0,
315
+ maximum=2.0,
316
+ step=0.1,
317
+ value=1.0,
318
+ label="๋ฐ˜๋ณต ํŒจ๋„ํ‹ฐ",
319
+ )
320
+
321
+ # ์˜ˆ์‹œ ์งˆ๋ฌธ
322
+ gr.Examples(
323
  examples=[
324
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ์ ˆ๊ธฐ์™€ 24์ ˆ๊ธฐ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
325
  ["์šฐ๋ฆฌ๋‚˜๋ผ ์ „ํ†ต ์Œ์‹ ์ค‘ ๊ฑด๊ฐ•์— ์ข‹์€ ๋ฐœํšจ์Œ์‹ 5๊ฐ€์ง€๋ฅผ ์ถ”์ฒœํ•˜๊ณ  ๊ทธ ํšจ๋Šฅ์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
 
334
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ์˜๋ณต์ธ ํ•œ๋ณต์˜ ๊ตฌ์กฐ์™€ ํŠน์ง•์„ ๊ณผํ•™์ , ๋ฏธํ•™์  ๊ด€์ ์—์„œ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”."],
335
  ["ํ•œ๊ตญ์˜ ์ „ํ†ต ๊ฐ€์˜ฅ ๊ตฌ์กฐ๋ฅผ ๊ธฐํ›„์™€ ํ™˜๊ฒฝ ๊ด€์ ์—์„œ ๋ถ„์„ํ•˜๊ณ , ํ˜„๋Œ€ ๊ฑด์ถ•์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์š”์†Œ๋ฅผ ์ œ์•ˆํ•ด์ฃผ์„ธ์š”."]
336
  ],
337
+ inputs=msg,
338
+ )
339
+
340
+ # ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
341
+ msg.submit(
342
+ stream_chat,
343
+ inputs=[msg, chatbot, file_upload, temperature, max_new_tokens, top_p, top_k, penalty],
344
+ outputs=[msg, chatbot]
345
+ )
346
+
347
+ send.click(
348
+ stream_chat,
349
+ inputs=[msg, chatbot, file_upload, temperature, max_new_tokens, top_p, top_k, penalty],
350
+ outputs=[msg, chatbot]
351
+ )
352
+
353
+ # ํŒŒ์ผ ์—…๋กœ๋“œ์‹œ ์ž๋™ ๋ถ„์„
354
+ file_upload.change(
355
+ lambda: "ํŒŒ์ผ ๋ถ„์„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค...",
356
+ outputs=msg
357
+ ).then(
358
+ stream_chat,
359
+ inputs=[msg, chatbot, file_upload, temperature, max_new_tokens, top_p, top_k, penalty],
360
+ outputs=[msg, chatbot]
361
  )
362
 
363
  if __name__ == "__main__":
364
+ demo.launch()