Mikecode123 commited on
Commit
c1fa181
·
verified ·
1 Parent(s): d58ff8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -19,33 +19,28 @@ llm = Llama(
19
  )
20
 
21
  # =========================
22
- # CHAT FUNCTION (MODERN FORMAT)
23
  # =========================
24
  def chat(message, history):
25
- # convert Gradio "messages" format safely
26
- messages = []
27
 
28
- for msg in history:
29
- if isinstance(msg, dict):
30
- messages.append(msg)
31
-
32
- messages.append({"role": "user", "content": message})
33
 
34
  output = llm.create_chat_completion(
35
- messages=messages,
36
  max_tokens=300,
37
  temperature=0.7
38
  )
39
 
40
  response = output["choices"][0]["message"]["content"]
41
 
42
- history.append({"role": "user", "content": message})
43
  history.append({"role": "assistant", "content": response})
44
 
45
  return "", history
46
 
47
  # =========================
48
- # GRADIO UI
49
  # =========================
50
  with gr.Blocks() as demo:
51
  gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
@@ -54,8 +49,10 @@ with gr.Blocks() as demo:
54
  msg = gr.Textbox(label="Ask your AI")
55
  clear = gr.Button("Clear")
56
 
 
57
  msg.submit(chat, [msg, chatbot], [msg, chatbot])
58
 
 
59
  clear.click(lambda: [], None, chatbot, queue=False)
60
 
61
  # =========================
 
19
  )
20
 
21
  # =========================
22
+ # CHAT FUNCTION (GRADIO 4 STYLE)
23
  # =========================
24
  def chat(message, history):
25
+ # history is list of dicts in Gradio 4
26
+ history = history or []
27
 
28
+ history.append({"role": "user", "content": message})
 
 
 
 
29
 
30
  output = llm.create_chat_completion(
31
+ messages=history,
32
  max_tokens=300,
33
  temperature=0.7
34
  )
35
 
36
  response = output["choices"][0]["message"]["content"]
37
 
 
38
  history.append({"role": "assistant", "content": response})
39
 
40
  return "", history
41
 
42
  # =========================
43
+ # GRADIO UI (GRADIO 4)
44
  # =========================
45
  with gr.Blocks() as demo:
46
  gr.Markdown("# 🧠 Qwen GGUF AI (Living Legend Build)")
 
49
  msg = gr.Textbox(label="Ask your AI")
50
  clear = gr.Button("Clear")
51
 
52
+ # send message
53
  msg.submit(chat, [msg, chatbot], [msg, chatbot])
54
 
55
+ # clear chat
56
  clear.click(lambda: [], None, chatbot, queue=False)
57
 
58
  # =========================