Spaces:
Runtime error
Runtime error
from asyncio import constants | |
import gradio as gr | |
import requests | |
import os | |
import re | |
import random | |
from words import * | |
from base64 import b64decode | |
from PIL import Image | |
import io | |
import numpy as np | |
def desc_to_image(desc): | |
print("*****Inside desc_to_image") | |
desc = " ".join(desc.split('\n')) | |
desc = desc + ", character art, concept art, artstation" | |
steps, width, height, images, diversity = '50','256','256','1',15 | |
iface = gr.Interface.load("spaces/multimodalart/latentdiffusion") | |
print("about to die",iface,dir(iface)) | |
prompt = re.sub(r'[^a-zA-Z0-9 ,.]', '', desc) | |
print("about to die",prompt) | |
img=iface(desc, steps, width, height, images, diversity)[0] | |
return img | |
def upscale_img(img): | |
iface = gr.Interface.load("spaces/akhaliq/Real-ESRGAN") | |
model='base' | |
uimg=iface(img,models) | |
return uimg | |
demo = gr.Blocks() | |
with demo: | |
gr.Markdown("<h1><center>NPC Generator</center></h1>") | |
gr.Markdown( | |
"<div>Run <a href='https://huggingface.co/spaces/multimodalart/latentdiffusion'>Latent Diffusion</a> first to generate an image</div>" | |
"<div>Then upscale with <a href='https://huggingface.co/spaces/akhaliq/Real-ESRGAN/blob/main/app.py'>ESRGAN</a></div>" | |
) | |
with gr.Row(): | |
b0 = gr.Button("generate") | |
b1 = gr.Button("upscale") | |
with gr.Row(): | |
desc = gr.Textbox(label="description",placeholder="an impressionist painting of a white vase") | |
with gr.Row(): | |
intermediate_image = gr.Image(label="portrait",type="filepath", shape=(256,256)) | |
output_image = gr.Image(label="portrait",type="filepath", shape=(256,256)) | |
b0.click(desc_to_image,inputs=[desc],outputs=[intermediate_image]) | |
b1.click(upscale_img, inputs=[ intermediate_image], outputs=output_image) | |
#examples=examples | |
demo.launch(enable_queue=True, debug=True) |