Update app.py
Browse files
app.py
CHANGED
|
@@ -216,20 +216,12 @@ def predict(message, history):
|
|
| 216 |
{"role": "system", "content": system_prompt}
|
| 217 |
]
|
| 218 |
|
| 219 |
-
#
|
| 220 |
-
if isinstance(history, list):
|
| 221 |
-
for
|
| 222 |
-
|
| 223 |
-
if
|
| 224 |
-
|
| 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 |
-
# ---
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
| 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):
|