Spaces:
Runtime error
Runtime error
File size: 1,342 Bytes
9a87834 9bbba8c 094f795 75ece5a 9a87834 75ece5a 9a87834 75ece5a 094f795 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
"""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()
|