import requests import re import base64 import os from transformers import AutoModelForCausalLM, AutoTokenizer from PIL import Image from flask import Flask, render_template, request, redirect, url_for, flash app = Flask(__name__) # Load the Hugging Face model and tokenizer model_id = "meta-llama/llama-3-2-90b-vision-instruct" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id) def input_image_setup(uploaded_file): """ Encodes the uploaded image file into a base64 string to be used with AI models. Parameters: - uploaded_file: File-like object uploaded via a file uploader Returns: - encoded_image (str): Base64 encoded string of the image data """ if uploaded_file is not None: bytes_data = uploaded_file.read() encoded_image = base64.b64encode(bytes_data).decode("utf-8") return encoded_image else: raise FileNotFoundError("No file uploaded") def format_response(response_text): """ Formats the model response to display each item on a new line as a list. Converts numbered items into HTML `