temp handle it turns request
#27
by ismailhakki37 - opened
3 unmodified lines456789293 unmodified lines30330430530630730830931031131233 unmodified lines3463473483493503513523533 unmodified linesimport numpy as npimport hashlibimport jsonimport requestsfrom PIL import Imagefrom io import BytesIO293 unmodified lines# Process image for modeltry:image_tensor = process_images([image], our_chatbot.image_processor, our_chatbot.model.config)[0]image_tensor = image_tensor.half().to(our_chatbot.model.device)image_tensor = image_tensor.unsqueeze(0)except Exception as e:return {"error": f"Image processing failed: {str(e)}"}# Prepare conversation33 unmodified lines)# Decode responseresponse = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)our_chatbot.conversation.messages[-1][-1] = response# Log conversationhistory = [(message_text, response)]3 unmodified lines45678910293 unmodified lines30430530630730830931031131231331431531631731831932032132233 unmodified lines3563573583593603613623633643653663673683693703713723733743753763773783793803813823 unmodified linesimport numpy as npimport hashlibimport jsonimport base64import requestsfrom PIL import Imagefrom io import BytesIO293 unmodified lines# Process image for modeltry:print(f"[DEBUG] Processing image for model...")processed_images = process_images([image], our_chatbot.image_processor, our_chatbot.model.config)print(f"[DEBUG] Processed images length: {len(processed_images)}")if len(processed_images) == 0:return {"error": "Image processing returned empty list"}image_tensor = processed_images[0]image_tensor = image_tensor.half().to(our_chatbot.model.device)image_tensor = image_tensor.unsqueeze(0)print(f"[DEBUG] Image tensor shape: {image_tensor.shape}")except Exception as e:print(f"[DEBUG] Image processing error: {str(e)}")return {"error": f"Image processing failed: {str(e)}"}# Prepare conversation33 unmodified lines)# Decode responsetry:print(f"[DEBUG] Outputs shape: {outputs.shape if hasattr(outputs, 'shape') else 'No shape attr'}")print(f"[DEBUG] Outputs length: {len(outputs) if hasattr(outputs, '__len__') else 'No length'}")print(f"[DEBUG] Input IDs shape: {input_ids.shape}")if len(outputs) == 0:return {"error": "Model generated empty output"}response = our_chatbot.tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)print(f"[DEBUG] Conversation messages length: {len(our_chatbot.conversation.messages)}")if len(our_chatbot.conversation.messages) > 0:print(f"[DEBUG] Last message length: {len(our_chatbot.conversation.messages[-1])}")our_chatbot.conversation.messages[-1][-1] = responseelse:print("[DEBUG] No conversation messages found")print(f"[DEBUG] Generated response length: {len(response)}")except Exception as e:print(f"[DEBUG] Response decoding error: {str(e)}")return {"error": f"Response decoding failed: {str(e)}"}# Log conversationhistory = [(message_text, response)]
handler.py+32-3