image_test / model.py
Ma7mouD-7's picture
Upload 2 files
19c33ef
import numpy as np
from PIL import Image
import io
import base64
def generate_image(text):
# Generate a random image
image = np.random.randint(0, 256, size=(1028, 1028, 3), dtype=np.uint8)
image = Image.fromarray(image)
# Save the image to a byte buffer
buffer = io.BytesIO()
image.save(buffer, format="JPEG")
image_bytes = buffer.getvalue()
# Convert the image bytes to a base64-encoded string
image_string = base64.b64encode(image_bytes).decode("utf-8")
return image_string
# # Assume that `image_string` is the base64-encoded image string returned by `generate_image`
# image_bytes = base64.b64decode(generate_image(""))
# image = Image.open(io.BytesIO(image_bytes))
# image.show() # Show the image in a new window