ginipick commited on
Commit
7c4abe8
ยท
verified ยท
1 Parent(s): eadc038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -30
app.py CHANGED
@@ -216,20 +216,12 @@ def predict(message, history):
216
  {"role": "system", "content": system_prompt}
217
  ]
218
 
219
- # Append history (List of {'role': 'user'/'assistant', 'content': '...'})
220
- if isinstance(history, list): # Check if history is a list
221
- for turn in history:
222
- # Validate turn format
223
- if isinstance(turn, dict) and "role" in turn and "content" in turn:
224
- chat_history_formatted.append(turn)
225
- # Handle potential older tuple format
226
- elif isinstance(turn, (list, tuple)) and len(turn) == 2:
227
- print(f"Warning: Received history item in tuple format: {turn}. Converting to messages format.")
228
- chat_history_formatted.append({"role": "user", "content": turn[0]})
229
- if turn[1]: # Ensure assistant message exists
230
- chat_history_formatted.append({"role": "assistant", "content": turn[1]})
231
- else:
232
- print(f"Warning: Skipping unexpected history format item: {turn}")
233
 
234
  # Append the latest user message
235
  chat_history_formatted.append({"role": "user", "content": message})
@@ -301,9 +293,11 @@ def predict(message, history):
301
 
302
  return response
303
 
304
- # --- Additional UI components ---
305
- def create_welcome_markdown():
306
- return """
 
 
307
  # ๐Ÿ‡ฐ๐Ÿ‡ท ๋„ค์ด๋ฒ„ HyperCLOVA X SEED
308
 
309
  ํ•œ๊ตญ์˜ ๊ธฐ์ˆ ๋ ฅ์œผ๋กœ ๊ฐœ๋ฐœ๋œ ๋„ค์ด๋ฒ„์˜ ์ดˆ๊ฑฐ๋Œ€ AI ์–ธ์–ด๋ชจ๋ธ 'HyperCLOVA X'๋ฅผ ๊ฒฝํ—˜ํ•ด๋ณด์„ธ์š”.
@@ -313,18 +307,11 @@ def create_welcome_markdown():
313
  - ์•„๋ž˜ ์ฑ„ํŒ…์ฐฝ์— ์งˆ๋ฌธ์ด๋‚˜ ์š”์ฒญ์„ ์ž…๋ ฅํ•˜์„ธ์š”
314
  - ํ•œ๊ตญ์–ด๋กœ ๋‹ค์–‘ํ•œ ์ฃผ์ œ์— ๋Œ€ํ•œ ๋Œ€ํ™”๋ฅผ ๋‚˜๋ˆ ๋ณด์„ธ์š”
315
  - ์˜ˆ์‹œ ์งˆ๋ฌธ์„ ํด๋ฆญํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค
316
- """
317
-
318
- # --- Gradio Interface Setup ---
319
- print("--- Setting up Gradio Interface ---")
320
-
321
- with gr.Blocks(css=custom_css) as demo:
322
- gr.Markdown(create_welcome_markdown(), elem_id="intro-message")
323
 
 
324
  chatbot = gr.ChatInterface(
325
  fn=predict,
326
- title="",
327
- description="",
328
  examples=[
329
  ["๋„ค์ด๋ฒ„ ํด๋กœ๋ฐ”X๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?"],
330
  ["์Šˆ๋ขฐ๋”ฉ๊ฑฐ ๋ฐฉ์ •์‹๊ณผ ์–‘์ž์—ญํ•™์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
@@ -334,10 +321,6 @@ with gr.Blocks(css=custom_css) as demo:
334
  ["์ธ๊ณต์ง€๋Šฅ ์œค๋ฆฌ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
335
  ],
336
  cache_examples=False,
337
- submit_btn="๋ณด๋‚ด๊ธฐ",
338
- retry_btn="๋‹ค์‹œ ์‹œ๋„",
339
- undo_btn="์ทจ์†Œ",
340
- clear_btn="์ƒˆ๋กœ์šด ๋Œ€ํ™”",
341
  )
342
 
343
  with gr.Accordion("๋ชจ๋ธ ์ •๋ณด", open=False):
 
216
  {"role": "system", "content": system_prompt}
217
  ]
218
 
219
+ # Process history based on Gradio ChatInterface format (list of tuples)
220
+ if isinstance(history, list):
221
+ for user_msg, assistant_msg in history:
222
+ chat_history_formatted.append({"role": "user", "content": user_msg})
223
+ if assistant_msg: # Check if not None or empty
224
+ chat_history_formatted.append({"role": "assistant", "content": assistant_msg})
 
 
 
 
 
 
 
 
225
 
226
  # Append the latest user message
227
  chat_history_formatted.append({"role": "user", "content": message})
 
293
 
294
  return response
295
 
296
+ # --- Gradio Interface Setup ---
297
+ print("--- Setting up Gradio Interface ---")
298
+
299
+ with gr.Blocks(css=custom_css) as demo:
300
+ gr.Markdown("""
301
  # ๐Ÿ‡ฐ๐Ÿ‡ท ๋„ค์ด๋ฒ„ HyperCLOVA X SEED
302
 
303
  ํ•œ๊ตญ์˜ ๊ธฐ์ˆ ๋ ฅ์œผ๋กœ ๊ฐœ๋ฐœ๋œ ๋„ค์ด๋ฒ„์˜ ์ดˆ๊ฑฐ๋Œ€ AI ์–ธ์–ด๋ชจ๋ธ 'HyperCLOVA X'๋ฅผ ๊ฒฝํ—˜ํ•ด๋ณด์„ธ์š”.
 
307
  - ์•„๋ž˜ ์ฑ„ํŒ…์ฐฝ์— ์งˆ๋ฌธ์ด๋‚˜ ์š”์ฒญ์„ ์ž…๋ ฅํ•˜์„ธ์š”
308
  - ํ•œ๊ตญ์–ด๋กœ ๋‹ค์–‘ํ•œ ์ฃผ์ œ์— ๋Œ€ํ•œ ๋Œ€ํ™”๋ฅผ ๋‚˜๋ˆ ๋ณด์„ธ์š”
309
  - ์˜ˆ์‹œ ์งˆ๋ฌธ์„ ํด๋ฆญํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค
310
+ """, elem_id="intro-message")
 
 
 
 
 
 
311
 
312
+ # Using standard ChatInterface (compatible with all Gradio versions)
313
  chatbot = gr.ChatInterface(
314
  fn=predict,
 
 
315
  examples=[
316
  ["๋„ค์ด๋ฒ„ ํด๋กœ๋ฐ”X๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?"],
317
  ["์Šˆ๋ขฐ๋”ฉ๊ฑฐ ๋ฐฉ์ •์‹๊ณผ ์–‘์ž์—ญํ•™์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
 
321
  ["์ธ๊ณต์ง€๋Šฅ ์œค๋ฆฌ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."],
322
  ],
323
  cache_examples=False,
 
 
 
 
324
  )
325
 
326
  with gr.Accordion("๋ชจ๋ธ ์ •๋ณด", open=False):