Spaces:
Runtime error
Runtime error
"""See https://huggingface.co/spaces/Gradio-Blocks/Story-to-video/blob/main/app.py.""" | |
import gradio as gr | |
import base64 | |
import io | |
from PIL import Image # opencv-python | |
# from PIL import Image | |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline | |
# import requests | |
# import torch | |
image_gen = gr.Interface.load("spaces/multimodalart/latentdiffusion") | |
def generate_images(phrase: str): | |
generated_text = phrase | |
steps = 125 | |
width = 256 | |
height = 256 | |
num_images = 4 | |
num_images = 1 | |
diversity = 6 | |
image_bytes = image_gen(generated_text, steps, width, height, num_images, diversity) | |
# Algo from spaces/Gradio-Blocks/latent_gpt2_story/blob/main/app.py | |
# generated_images = [] | |
img = None | |
for image in image_bytes[1]: | |
image_str = image[0] | |
try: | |
image_str = image_str.replace("data:image/png;base64,", "") | |
except Exception as exc: | |
logger.error(exc) | |
return None | |
decoded_bytes = base64.decodebytes(bytes(image_str, "utf-8")) | |
img = Image.open(io.BytesIO(decoded_bytes)) | |
# generated_images.append(img) | |
# return generated_images | |
return img | |
examples = ["an apple", "Donald Trump"] | |
iface = gr.Interface( | |
generate_images, | |
"text", | |
"image", | |
examples=examples, | |
) | |
iface.launch() | |