ginipick commited on
Commit
2013128
·
verified ·
1 Parent(s): 95a32d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -34
app.py CHANGED
@@ -59,7 +59,6 @@ def respond(
59
  elif message.lower() == "test.parquet 실행":
60
  # 현재 Parquet 내용은 상태 변수에서 가져와야 함
61
  # 여기서는 예시로 'parquet_content'가 history에 있다고 가정
62
- # 실제 구현에서는 별도의 상태 관리를 통해 Parquet 데이터를 참조해야 함
63
  parquet_content = ""
64
  for item in history:
65
  if isinstance(item, tuple) and item[0].startswith("Parquet"):
@@ -150,22 +149,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
150
 
151
  with gr.Tab("챗봇"):
152
  gr.Markdown("### LLM과 대화하기")
153
- chat = gr.ChatInterface(
154
- fn=respond,
155
- examples=[
156
- ["패션 코드 실행"],
157
- ["UHD 이미지 코드 실행"],
158
- ["MixGEN 코드 실행"],
159
- ["test.parquet 실행"],
160
- ["상세한 사용 방법을 마치 화면을 보면서 설명하듯이 4000 토큰 이상 자세히 설명하라"],
161
- ["FAQ 20건을 상세하게 작성하라. 4000토큰 이상 사용하라."],
162
- ["사용 방법과 차별점, 특징, 강점을 중심으로 4000 토큰 이상 유튜브 영상 스크립트 형태로 작성하라"],
163
- ["본 서비스를 SEO 최적화하여 블로그 포스트(배경 및 필요성, 기존 유사 서비스와 비교하여 특장점, 활용처, 가치, 기대효과, 결론을 포함)로 4000 토큰 이상 작성하라"],
164
- ["특허 출원에 활용할 기술 및 비즈니스모델 측면을 포함하여 특허 출원서 구성에 맞게 혁신적인 창의 발명 내용을 중심으로 4000 토큰 이상 작성하라."],
165
- ["계속 이어서 답변하라"],
166
- ],
167
- theme="default", # 원하는 테마로 변경 가능
168
- )
169
 
170
  with gr.Accordion("시스템 프롬프트 및 옵션 설정", open=False):
171
  system_message = gr.Textbox(label="System Message", value="너는 AI 조언자 역할이다.")
@@ -173,6 +159,28 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
173
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
174
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  with gr.Tab("데이터 변환"):
177
  gr.Markdown("### CSV 파일 업로드 및 Parquet 변환")
178
  with gr.Row():
@@ -181,7 +189,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
181
  upload_button = gr.Button("업로드 및 변환")
182
  upload_status = gr.Textbox(label="업로드 상태", interactive=False)
183
  parquet_preview = gr.Markdown(label="Parquet 파일 미리보기")
184
- download_button = gr.File(label="Parquet 파일 다운로드", file=None, interactive=False)
185
 
186
  # 업로드 버튼 클릭 시 실행할 함수
187
  def handle_csv_upload(file):
@@ -190,7 +198,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
190
  # 파일을 다운로드할 수 있도록 경로 설정
191
  with open(parquet_filename, "rb") as f:
192
  data = f.read()
193
- return message, load_parquet(parquet_filename), (parquet_filename, data)
194
  else:
195
  return message, "", None
196
 
@@ -228,21 +236,30 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
228
  )
229
 
230
  gr.Markdown("### LLM과 대화하기")
231
- chat_interface = gr.ChatInterface(
232
- fn=respond,
233
- examples=[
234
- ["패션 코드 실행"],
235
- ["UHD 이미지 코드 실행"],
236
- ["MixGEN 코드 실행"],
237
- ["test.parquet 실행"],
238
- ["상세한 사용 방법을 마치 화면을 보면서 설명하듯이 4000 토큰 이상 자세히 설명하라"],
239
- ["FAQ 20건을 상세하게 작성하라. 4000토큰 이상 사용하라."],
240
- ["사용 방법과 차별점, 특징, 강점을 중심으로 4000 토큰 이상 유튜브 영상 스크립트 형태로 작성하라"],
241
- ["본 서비스를 SEO 최적화하여 블로그 포스트(배경 및 필요성, 기존 유사 서비스와 비교하여 특장점, 활용처, 가치, 기대효과, 결론을 포함)로 4000 토큰 이상 작성하라"],
242
- ["특허 출원에 활용할 기술 및 비즈니스모델 측면을 포함하여 특허 출원서 구성에 맞게 혁신적인 창의 발명 내용을 중심으로 4000 토큰 이상 작성하라."],
243
- ["계속 이어서 답변하라"],
244
- ],
245
- theme="default", # 원하는 테마로 변경 가능
 
 
 
 
 
 
 
 
 
246
  )
247
 
248
  gr.Markdown("## 주의 사항")
 
59
  elif message.lower() == "test.parquet 실행":
60
  # 현재 Parquet 내용은 상태 변수에서 가져와야 함
61
  # 여기서는 예시로 'parquet_content'가 history에 있다고 가정
 
62
  parquet_content = ""
63
  for item in history:
64
  if isinstance(item, tuple) and item[0].startswith("Parquet"):
 
149
 
150
  with gr.Tab("챗봇"):
151
  gr.Markdown("### LLM과 대화하기")
152
+ chatbot = gr.Chatbot(label="챗봇")
153
+ msg = gr.Textbox(label="메시지 입력")
154
+ send = gr.Button("전송")
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  with gr.Accordion("시스템 프롬프트 및 옵션 설정", open=False):
157
  system_message = gr.Textbox(label="System Message", value="너는 AI 조언자 역할이다.")
 
159
  temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
160
  top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
161
 
162
+ # 챗봇 메시지 처리 함수
163
+ def handle_message(message, history, system_message, max_tokens, temperature, top_p):
164
+ # Update history with user message
165
+ history = history or []
166
+ history.append((message, None))
167
+ # Generate response
168
+ response = ""
169
+ try:
170
+ for token in respond(message, history, system_message, max_tokens, temperature, top_p):
171
+ response = token
172
+ # Update history with assistant response
173
+ history[-1] = (message, response)
174
+ except Exception as e:
175
+ history[-1] = (message, f"추론 중 오류가 발생했습니다: {str(e)}")
176
+ return history, ""
177
+
178
+ send.click(
179
+ handle_message,
180
+ inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
181
+ outputs=[chatbot, msg]
182
+ )
183
+
184
  with gr.Tab("데이터 변환"):
185
  gr.Markdown("### CSV 파일 업로드 및 Parquet 변환")
186
  with gr.Row():
 
189
  upload_button = gr.Button("업로드 및 변환")
190
  upload_status = gr.Textbox(label="업로드 상태", interactive=False)
191
  parquet_preview = gr.Markdown(label="Parquet 파일 미리보기")
192
+ download_button = gr.File(label="Parquet 파일 다운로드", type="binary", interactive=False)
193
 
194
  # 업로드 버튼 클릭 시 실행할 함수
195
  def handle_csv_upload(file):
 
198
  # 파일을 다운로드할 수 있도록 경로 설정
199
  with open(parquet_filename, "rb") as f:
200
  data = f.read()
201
+ return message, load_parquet(parquet_filename), data
202
  else:
203
  return message, "", None
204
 
 
236
  )
237
 
238
  gr.Markdown("### LLM과 대화하기")
239
+ chatbot_data_upload = gr.Chatbot(label="챗봇 데이터 업로드")
240
+ msg_data_upload = gr.Textbox(label="메시지 입력")
241
+ send_data_upload = gr.Button("전송")
242
+
243
+ # 챗봇 메시지 처리 함수 (데이터 업로드 버전)
244
+ def handle_message_data_upload(message, history, system_message, max_tokens, temperature, top_p, parquet_data):
245
+ # Update history with user message
246
+ history = history or []
247
+ history.append((message, None))
248
+ # Generate response
249
+ response = ""
250
+ try:
251
+ for token in respond(message, history, system_message, max_tokens, temperature, top_p):
252
+ response = token
253
+ # Update history with assistant response
254
+ history[-1] = (message, response)
255
+ except Exception as e:
256
+ history[-1] = (message, f"추론 중 오류가 발생했습니다: {str(e)}")
257
+ return history, ""
258
+
259
+ send_data_upload.click(
260
+ handle_message_data_upload,
261
+ inputs=[msg_data_upload, chatbot_data_upload, system_message, max_tokens, temperature, top_p, parquet_data_state],
262
+ outputs=[chatbot_data_upload, msg_data_upload]
263
  )
264
 
265
  gr.Markdown("## 주의 사항")