Spaces:
Runtime error
Runtime error
Update app.py
Browse files21 unmodified lines222324252627282929 unmodified lines596061626364656667686921 unmodified linesdef update_bot(text, chatbot):response_json = interpreter.chat(text, stream=True, display=False)formatted_response = json_to_markdown(response_json)chatbot.append((text, formatted_response))return chatbot, ""29 unmodified linesdef json_to_markdown(json_data):full_message = []for item in json_data:if item['role'] == 'assistant' and item['type'] == 'message':content = item.get('content', " ")full_message.append(content) # Append the content to the listreturn "**Assistant:**\n" + " ".join(full_message) # Join all parts into one string and format as a single messagewith gr.Blocks() as demo:21 unmodified lines22232425262728293031323329 unmodified lines636465666768697071727374757677787980818283848521 unmodified linesdef update_bot(text, chatbot):response_json = interpreter.chat(text, stream=True, display=False)formatted_response, images = json_to_markdown(response_json)message = " ".join(formatted_response)if message:chatbot.append(("Assistant", message))for img_path in images:chatbot.append(("Assistant", img_path)) # Append image paths directlyreturn chatbot, ""29 unmodified linesdef json_to_markdown(json_data):full_message = []images = []# Regex to detect URLs; this is a simple version and might need to be adaptedurl_pattern = r'(http[s]?://\S+|sandbox:/\S+)'for item in json_data:if item['role'] == 'assistant' and item['type'] == 'message':content = item.get('content', " ")# Find all URLs in the contenturls = re.findall(url_pattern, content)# Append any detected URLs to the images listimages.extend(urls)# Remove URLs from the contentcontent = re.sub(url_pattern, "", content).strip()if content:full_message.append(content)return full_message, imageswith gr.Blocks() as demo:
app.py+20-4