Laksh99 commited on
Commit
7fb1f9c
·
verified ·
1 Parent(s): 07f896a

Remove type="messages" from ChatInterface - use compatible Gradio API

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -29,18 +29,16 @@ def load_model():
29
  def respond(message, history, system_message, max_new_tokens, temperature, top_p, enable_thinking):
30
  load_model()
31
 
32
- # Build messages list
33
- # history is a list of {"role": ..., "content": ...} dicts in gr.ChatInterface
34
  messages = [{"role": "system", "content": system_message}]
35
  for item in history:
36
  if isinstance(item, dict):
37
  messages.append({"role": item["role"], "content": item["content"]})
38
- else:
39
- # fallback for tuple format
40
  if item[0]:
41
- messages.append({"role": "user", "content": item[0]})
42
  if item[1]:
43
- messages.append({"role": "assistant", "content": item[1]})
44
  messages.append({"role": "user", "content": message})
45
 
46
  text = tokenizer.apply_chat_template(
@@ -89,7 +87,7 @@ def respond(message, history, system_message, max_new_tokens, temperature, top_p
89
  demo = gr.ChatInterface(
90
  fn=respond,
91
  title="Qwen3.5-35B-A3B AWQ Chat",
92
- description="Powered by ZeroGPU (H200) | 4-bit AWQ quantized | 25.5 GB\n\n> **Note:** First inference takes ~2 min to load the model. Subsequent ones are faster.",
93
  additional_inputs=[
94
  gr.Textbox(
95
  value="You are a helpful, smart, and concise AI assistant.",
@@ -107,7 +105,6 @@ demo = gr.ChatInterface(
107
  ["Explain quantum entanglement in simple terms."],
108
  ["Translate 'Hello, how are you?' into French, Spanish, and Japanese."],
109
  ],
110
- type="messages",
111
  )
112
 
113
  demo.launch()
 
29
  def respond(message, history, system_message, max_new_tokens, temperature, top_p, enable_thinking):
30
  load_model()
31
 
32
+ # Build messages list - handle both tuple and dict history formats
 
33
  messages = [{"role": "system", "content": system_message}]
34
  for item in history:
35
  if isinstance(item, dict):
36
  messages.append({"role": item["role"], "content": item["content"]})
37
+ elif isinstance(item, (list, tuple)) and len(item) == 2:
 
38
  if item[0]:
39
+ messages.append({"role": "user", "content": str(item[0])})
40
  if item[1]:
41
+ messages.append({"role": "assistant", "content": str(item[1])})
42
  messages.append({"role": "user", "content": message})
43
 
44
  text = tokenizer.apply_chat_template(
 
87
  demo = gr.ChatInterface(
88
  fn=respond,
89
  title="Qwen3.5-35B-A3B AWQ Chat",
90
+ description="Powered by ZeroGPU (H200) | 4-bit AWQ quantized | 25.5 GB\n\n**Note:** First inference takes ~2 min to load the model. Subsequent ones are faster.",
91
  additional_inputs=[
92
  gr.Textbox(
93
  value="You are a helpful, smart, and concise AI assistant.",
 
105
  ["Explain quantum entanglement in simple terms."],
106
  ["Translate 'Hello, how are you?' into French, Spanish, and Japanese."],
107
  ],
 
108
  )
109
 
110
  demo.launch()