openfree commited on
Commit
3b27a7d
ยท
verified ยท
1 Parent(s): 4d3b110

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -55,15 +55,20 @@ def chat_streaming(message: str, user_email: str, session_id: str,
55
  web_search: bool, self_learning: bool, history: list) -> Generator:
56
  """์ŠคํŠธ๋ฆฌ๋ฐ ์ฑ„ํŒ…"""
57
  if not user_email:
58
- yield history + [{"role": "assistant", "content": "โŒ ์ด๋ฉ”์ผ์„ ๋จผ์ € ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."}]
 
 
59
  return
60
 
61
  if not session_id:
62
- yield history + [{"role": "assistant", "content": "โŒ ์„ธ์…˜์„ ๋จผ์ € ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."}]
 
 
63
  return
64
 
65
  # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€ ์ถ”๊ฐ€
66
- history = history + [{"role": "user", "content": message}]
 
67
  yield history
68
 
69
  # ์ŠคํŠธ๋ฆฌ๋ฐ ์‘๋‹ต
@@ -90,14 +95,13 @@ def chat_streaming(message: str, user_email: str, session_id: str,
90
  chunk = json.loads(data)
91
  content = chunk.get("content", "")
92
  full_response += content
93
- yield history[:-1] + [
94
- {"role": "user", "content": message},
95
- {"role": "assistant", "content": full_response}
96
- ]
97
  except json.JSONDecodeError:
98
  continue
99
  except Exception as e:
100
- yield history + [{"role": "assistant", "content": f"โŒ ์˜ค๋ฅ˜: {str(e)}"}]
 
101
 
102
 
103
  async def get_health_current(user_email: str) -> str:
@@ -181,7 +185,7 @@ async def delete_memory(memory_id: int, user_email: str) -> str:
181
  try:
182
  async with httpx.AsyncClient(timeout=30.0) as client:
183
  response = await client.delete(
184
- f"{API_BASE_URL}/memory/{memory_id}",
185
  params={"user_email": user_email}
186
  )
187
  result = response.json()
@@ -257,7 +261,7 @@ async def upload_file(file, session_id: str, user_email: str) -> str:
257
 
258
 
259
  # Gradio UI ๊ตฌ์„ฑ
260
- with gr.Blocks(title="KT API ํ…Œ์ŠคํŠธ", theme=gr.themes.Soft()) as demo:
261
  gr.Markdown("# ๐Ÿงช KT ์‹œ๋‹ˆ์–ด AI ๋น„์„œ API ํ…Œ์ŠคํŠธ")
262
  gr.Markdown(f"**API URL:** `{API_BASE_URL}`")
263
 
@@ -279,7 +283,7 @@ with gr.Blocks(title="KT API ํ…Œ์ŠคํŠธ", theme=gr.themes.Soft()) as demo:
279
  self_learning_check = gr.Checkbox(label="์ž๊ฐ€ ํ•™์Šต ํ™œ์„ฑํ™”", value=True)
280
 
281
  with gr.Column(scale=2):
282
- chatbot = gr.Chatbot(label="๋Œ€ํ™”", height=400, type="messages")
283
  msg_input = gr.Textbox(label="๋ฉ”์‹œ์ง€ ์ž…๋ ฅ", placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
284
  send_btn = gr.Button("์ „์†ก", variant="primary")
285
 
 
55
  web_search: bool, self_learning: bool, history: list) -> Generator:
56
  """์ŠคํŠธ๋ฆฌ๋ฐ ์ฑ„ํŒ…"""
57
  if not user_email:
58
+ history = history or []
59
+ history.append(["", "โŒ ์ด๋ฉ”์ผ์„ ๋จผ์ € ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."])
60
+ yield history
61
  return
62
 
63
  if not session_id:
64
+ history = history or []
65
+ history.append(["", "โŒ ์„ธ์…˜์„ ๋จผ์ € ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."])
66
+ yield history
67
  return
68
 
69
  # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€ ์ถ”๊ฐ€
70
+ history = history or []
71
+ history.append([message, ""])
72
  yield history
73
 
74
  # ์ŠคํŠธ๋ฆฌ๋ฐ ์‘๋‹ต
 
95
  chunk = json.loads(data)
96
  content = chunk.get("content", "")
97
  full_response += content
98
+ history[-1][1] = full_response
99
+ yield history
 
 
100
  except json.JSONDecodeError:
101
  continue
102
  except Exception as e:
103
+ history[-1][1] = f"โŒ ์˜ค๋ฅ˜: {str(e)}"
104
+ yield history
105
 
106
 
107
  async def get_health_current(user_email: str) -> str:
 
185
  try:
186
  async with httpx.AsyncClient(timeout=30.0) as client:
187
  response = await client.delete(
188
+ f"{API_BASE_URL}/memory/{int(memory_id)}",
189
  params={"user_email": user_email}
190
  )
191
  result = response.json()
 
261
 
262
 
263
  # Gradio UI ๊ตฌ์„ฑ
264
+ with gr.Blocks(title="KT API ํ…Œ์ŠคํŠธ") as demo:
265
  gr.Markdown("# ๐Ÿงช KT ์‹œ๋‹ˆ์–ด AI ๋น„์„œ API ํ…Œ์ŠคํŠธ")
266
  gr.Markdown(f"**API URL:** `{API_BASE_URL}`")
267
 
 
283
  self_learning_check = gr.Checkbox(label="์ž๊ฐ€ ํ•™์Šต ํ™œ์„ฑํ™”", value=True)
284
 
285
  with gr.Column(scale=2):
286
+ chatbot = gr.Chatbot(label="๋Œ€ํ™”", height=400)
287
  msg_input = gr.Textbox(label="๋ฉ”์‹œ์ง€ ์ž…๋ ฅ", placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
288
  send_btn = gr.Button("์ „์†ก", variant="primary")
289