Jn-Huang commited on
Commit
38dedc7
·
1 Parent(s): 4cc1531

Make code compatible with Gradio 6.0 structured content format

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -112,12 +112,30 @@ def chat_fn(message, history, system_prompt, max_new_tokens, temperature, top_p)
112
  system_prompt = "You are Be.FM, a helpful and knowledgeable AI assistant. Provide clear, accurate, and concise responses."
113
  messages.append({"role": "system", "content": system_prompt})
114
 
115
- # History is already in dict format: [{"role": "user", "content": "..."}, ...]
 
116
  for msg in (history or []):
117
- messages.append(msg)
 
 
 
 
 
 
 
 
 
 
118
 
119
  if message:
120
- messages.append({"role": "user", "content": message})
 
 
 
 
 
 
 
121
 
122
  reply = generate_response(
123
  messages,
 
112
  system_prompt = "You are Be.FM, a helpful and knowledgeable AI assistant. Provide clear, accurate, and concise responses."
113
  messages.append({"role": "system", "content": system_prompt})
114
 
115
+ # Handle Gradio 6.0 history format
116
+ # History format: [{"role": "user", "content": [{"type": "text", "text": "..."}]}, ...]
117
  for msg in (history or []):
118
+ role = msg.get("role", "user")
119
+ content = msg.get("content", "")
120
+
121
+ # Extract text from structured content
122
+ if isinstance(content, list):
123
+ # Gradio 6.0 format: content is a list of dicts
124
+ text_parts = [c.get("text", "") for c in content if c.get("type") == "text"]
125
+ content = " ".join(text_parts)
126
+
127
+ if content:
128
+ messages.append({"role": role, "content": content})
129
 
130
  if message:
131
+ # Handle message (could be string or dict in Gradio 6.0)
132
+ if isinstance(message, dict):
133
+ text = message.get("text", "")
134
+ else:
135
+ text = message
136
+
137
+ if text:
138
+ messages.append({"role": "user", "content": text})
139
 
140
  reply = generate_response(
141
  messages,