Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files34 unmodified lines3536373839404142434445464748495051525354555657585960616242 unmodified lines10510610710810911011134 unmodified lines@spaces.GPUdef bot_streaming(message, history):print(message)image = None# Check if there's an image in the current messageif message["files"]:# message["files"][-1] could be a dictionary or a stringif isinstance(message["files"][-1], dict):image = message["files"][-1]["path"]else:image = message["files"][-1]else:# If no image in the current message, look in the history for the last imagefor hist in history:if isinstance(hist[0], tuple):image = hist[0][0]# Error handling if no image is foundif image is None:raise gr.Error("You need to upload an image for LLaVA to work.")# Load the image if it's a path, otherwise use the existing PIL imageif isinstance(image, str):image = Image.open(image).convert('RGB')# Generate the prompt for the modelprompt = message['text']42 unmodified linesfn=bot_streaming,title="FinLLaVA",examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},{"text": "How to make this pastry?", "files": ["./baklava.png"]}],stop_btn="Stop Generation",multimodal=True,textbox=chat_input,34 unmodified lines3536373839404142434445464748495051525354555657585960616242 unmodified lines10510610710810911011111234 unmodified lines@spaces.GPUdef bot_streaming(message, history):print(message)image_path = None# Check if there's an image in the current messageif message["files"]:# message["files"][-1] could be a dictionary or a stringif isinstance(message["files"][-1], dict):image_path = message["files"][-1]["path"]else:image_path = message["files"][-1]else:# If no image in the current message, look in the history for the last image pathfor hist in history:if isinstance(hist[0], tuple):image_path = hist[0][0]# Error handling if no image path is foundif image_path is None:raise gr.Error("You need to upload an image for LLaVA to work.")# If the image_path is a string, no need to load it into a PIL image# Just use the path directly in the next stepsprint(f"\033[91m{image_path}, {type(image_path)}\033[0m")# Generate the prompt for the modelprompt = message['text']42 unmodified linesfn=bot_streaming,title="FinLLaVA",examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},{"text": "How to make this pastry?", "files": ["./baklava.png"]},{"text":"What is this?","files":["http://images.cocodataset.org/val2017/000000039769.jpg"]}],stop_btn="Stop Generation",multimodal=True,textbox=chat_input,
app.py+12-11