Mikecode123 commited on
Commit
af5cc7c
·
verified ·
1 Parent(s): 3a4f0ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -28
app.py CHANGED
@@ -19,28 +19,18 @@ llm = Llama(
19
  )
20
 
21
  # =========================
22
- # SAFE CHAT FUNCTION (NO MIXING)
23
  # =========================
24
- def chat(message, history):
25
  history = history or []
26
-
27
  messages = []
28
 
29
- # STRICT: only dict format allowed
30
- for msg in history:
31
- if isinstance(msg, dict):
32
- messages.append({
33
- "role": msg.get("role", "user"),
34
- "content": str(msg.get("content", ""))
35
- })
36
 
37
- # add new user message
38
- messages.append({
39
- "role": "user",
40
- "content": str(message)
41
- })
42
 
43
- # run model
44
  output = llm.create_chat_completion(
45
  messages=messages,
46
  max_tokens=300,
@@ -49,27 +39,22 @@ def chat(message, history):
49
 
50
  response = output["choices"][0]["message"]["content"]
51
 
52
- # append assistant reply
53
- messages.append({
54
- "role": "assistant",
55
- "content": response
56
- })
57
 
58
- return "", messages
59
 
60
  # =========================
61
- # UI (GRADIO 4 SAFE MODE)
62
  # =========================
63
  with gr.Blocks() as demo:
64
- gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Stable Build)")
65
 
66
- chatbot = gr.Chatbot(type="messages")
67
- msg = gr.Textbox(label="Ask your AI")
68
  clear = gr.Button("Clear")
69
 
70
  msg.submit(chat, [msg, chatbot], [msg, chatbot])
71
-
72
- clear.click(lambda: [], None, chatbot, queue=False)
73
 
74
  # =========================
75
  # LAUNCH
 
19
  )
20
 
21
  # =========================
22
+ # CHAT FUNCTION (GRADIO 3 SAFE)
23
  # =========================
24
+ def chat(prompt, history):
25
  history = history or []
 
26
  messages = []
27
 
28
+ for user_msg, bot_msg in history:
29
+ messages.append({"role": "user", "content": str(user_msg)})
30
+ messages.append({"role": "assistant", "content": str(bot_msg)})
 
 
 
 
31
 
32
+ messages.append({"role": "user", "content": str(prompt)})
 
 
 
 
33
 
 
34
  output = llm.create_chat_completion(
35
  messages=messages,
36
  max_tokens=300,
 
39
 
40
  response = output["choices"][0]["message"]["content"]
41
 
42
+ history.append((prompt, response))
 
 
 
 
43
 
44
+ return "", history
45
 
46
  # =========================
47
+ # UI (NO TYPE PARAMETER)
48
  # =========================
49
  with gr.Blocks() as demo:
50
+ gr.Markdown("# 🧠 Living Legend AI Chatbot")
51
 
52
+ chatbot = gr.Chatbot() # 🔥 FIXED (NO type="messages")
53
+ msg = gr.Textbox()
54
  clear = gr.Button("Clear")
55
 
56
  msg.submit(chat, [msg, chatbot], [msg, chatbot])
57
+ clear.click(lambda: [], None, chatbot)
 
58
 
59
  # =========================
60
  # LAUNCH