i want to upload image from s3 and show them in good structure html befor processing it…
- User
i want to upload image from s3 and show them in good structure html befor processing it after "@app.get("/", response_class=HTMLResponse) async def home(request: Request): try: available_model_names = MODELS.keys() # Get model names from MODELS dictionary print(f"Available Models: {available_model_names}") # It's good practice not to print output directly in production. Use a logger instead.
available_images = [] response = requests.get(wordpress_url_post) if response.status_code == 200: print(response.json()) json_data = response.json() for item in json_data: if item.get("Status") and item["Status"]["status"] == "Unprocessed": image_url = item.get("Image URL") and item["Image URL"]["Image_url"] if image_url: available_images.append(image_url) return templates.TemplateResponse("upload_form.html", {"request": request, "model_names": available_model_names, "images": available_images}) except Exception as e: # Handle errors return templates.TemplateResponse("error_template.html", {"request": request, "error_message": str(e)}) - Assistant
- User
use this like function "def download_image_from_space(image_name): try: # Download the image from the specified space response = client.get_object(Bucket=space_name, Key=image_name) image_data = response['Body'].read() return image_data except Exception as e: print(f"Error downloading image: {e}") return None
- Assistant
- User
how to add button to post the image to this "@app.post("/process_images", response_class=HTMLResponse) async def process_images(request: Request, image_urls: List[str]):
- Assistant
- User
if you see in the script the image is not dict "# Dictionary to store the cached image data image_cache = {}
@app.get("/", response_class=HTMLResponse) async def home(request: Request): available_model_names = MODELS.keys() # Get model names from MODELS dictionary print(f"Available Models: {available_model_names}") # It's good practice not to print output directly in production. Use a logger instead.
available_images = [] response = requests.get(wordpress_url_post) if response.status_code == 200: print(response.json()) json_data = response.json() for item in json_data: if item.get("Status") and item["Status"]["status"] == "Unprocessed": image_url = item.get("Image URL") and item["Image URL"]["Image_url"] if image_url: parts= image_url.split("/") image_name = "/".join(parts[-1:]) # Check if image data is already in the cache if image_name not in image_cache: # If not, download the image from DigitalOcean Spaces image_data = download_image_from_space(image_name) if image_data: # Store the image data in the cache image_cache[image_name] = image_data available_images.append(image_url) # Add the image data to the list return templates.TemplateResponse("upload_form.html", {"request": request, "model_names": available_model_names, "images": available_images}) - Assistant