Logan Zoellner commited on
Commit
4e2d163
1 Parent(s): 087c646

initial commit

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from asyncio import constants
2
+ import gradio as gr
3
+ import requests
4
+ import os
5
+ import re
6
+ import random
7
+ from words import *
8
+ from base64 import b64decode
9
+ from PIL import Image
10
+ import io
11
+ import numpy as np
12
+
13
+
14
+ def desc_to_image(desc):
15
+ print("*****Inside desc_to_image")
16
+ desc = " ".join(desc.split('\n'))
17
+ desc = desc + ", character art, concept art, artstation"
18
+ steps, width, height, images, diversity = '50','256','256','1',15
19
+ iface = gr.Interface.load("spaces/multimodalart/latentdiffusion")
20
+ print("about to die",iface,dir(iface))
21
+
22
+ prompt = re.sub(r'[^a-zA-Z0-9 ,.]', '', desc)
23
+ print("about to die",prompt)
24
+
25
+
26
+ img=iface(desc, steps, width, height, images, diversity)[0]
27
+ return img
28
+
29
+
30
+ def upscale_img(img):
31
+ iface = gr.Interface.load("spaces/akhaliq/Real-ESRGAN")
32
+ model='base'
33
+ uimg=iface(img,models)
34
+ return uimg
35
+
36
+
37
+
38
+ demo = gr.Blocks()
39
+
40
+ with demo:
41
+ gr.Markdown("<h1><center>NPC Generator</center></h1>")
42
+ gr.Markdown(
43
+ "<div>Run <a href='https://huggingface.co/spaces/multimodalart/latentdiffusion'>Latent Diffusion</a> first to generate an image</div>"
44
+ "<div>Then upscale with <a href='https://huggingface.co/spaces/akhaliq/Real-ESRGAN/blob/main/app.py'>ESRGAN</a></div>"
45
+ )
46
+
47
+ with gr.Row():
48
+ b0 = gr.Button("generate")
49
+ b1 = gr.Button("upscale")
50
+
51
+ with gr.Row():
52
+ desc = gr.Textbox(label="description",placeholder="an impressionist painting of a white vase")
53
+
54
+ with gr.Row():
55
+ intermediate_image = gr.Image(label="portrait",type="filepath", shape=(256,256))
56
+ output_image = gr.Image(label="portrait",type="filepath", shape=(256,256))
57
+
58
+ b0.click(desc_to_image,inputs=[desc],outputs=[intermediate_image])
59
+ b1.click(upscale_img, inputs=[ intermediate_image], outputs=output_image)
60
+ #examples=examples
61
+
62
+ demo.launch(enable_queue=True, debug=True)