Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,61 +2,44 @@ from asyncio import constants
|
|
2 |
import gradio as gr
|
3 |
import re
|
4 |
|
5 |
-
|
6 |
-
|
7 |
demo = gr.Blocks()
|
8 |
|
9 |
with demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
desc = " ".join(desc.split('\n'))
|
19 |
-
#desc = desc + ", character art, concept art, artstation"
|
20 |
-
steps, width, height, images, diversity = '50','256','256','1',15
|
21 |
-
print("about to die",ds_iface,dir(ds_iface))
|
22 |
-
|
23 |
-
prompt = re.sub(r'[^a-zA-Z0-9 ,.]', '', desc)
|
24 |
-
print("about to die",prompt)
|
25 |
-
|
26 |
-
|
27 |
-
#img=iface(desc, steps, width, height, images, diversity)[0]
|
28 |
-
img=ds_iface(desc)[0]
|
29 |
-
return img
|
30 |
-
|
31 |
-
|
32 |
-
def upscale_img(img):
|
33 |
-
|
34 |
-
model='base'
|
35 |
-
uimg=es_iface(img,models)
|
36 |
-
return uimg
|
37 |
-
|
38 |
|
|
|
|
|
39 |
|
40 |
-
|
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", width=256,height=256)
|
56 |
-
output_image = gr.Image(label="portrait",type="filepath", width=256,height=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()
|
|
|
2 |
import gradio as gr
|
3 |
import re
|
4 |
|
|
|
|
|
5 |
demo = gr.Blocks()
|
6 |
|
7 |
with demo:
|
8 |
+
ds_iface = gr.Interface.load("spaces/artificialguybr/DREAMSHAPER-XL-FREE-DEMO")
|
9 |
+
es_iface = gr.Interface.load("spaces/akhaliq/Real-ESRGAN")
|
10 |
+
|
11 |
+
print("Interfaces Loaded:", ds_iface, es_iface) # Check if interfaces are loaded correctly
|
12 |
+
|
13 |
+
def desc_to_image(desc):
|
14 |
+
desc = " ".join(desc.split('\n'))
|
15 |
+
prompt = re.sub(r'[^a-zA-Z0-9 ,.]', '', desc)
|
16 |
+
try:
|
17 |
+
img = ds_iface(prompt)[0] # Ensure ds_iface is callable and returns expected result
|
18 |
+
except Exception as e:
|
19 |
+
print("Error in desc_to_image:", e)
|
20 |
+
return None
|
21 |
+
return img
|
22 |
+
|
23 |
+
def upscale_img(img):
|
24 |
+
try:
|
25 |
+
model = 'base'
|
26 |
+
uimg = es_iface(img, model) # Ensure es_iface is callable and returns expected result
|
27 |
+
except Exception as e:
|
28 |
+
print("Error in upscale_img:", e)
|
29 |
+
return None
|
30 |
+
return uimg
|
31 |
|
32 |
+
gr.Markdown("<h1><center>NPC Generator</center></h1>")
|
33 |
+
# Other HTML and Gradio components...
|
34 |
|
35 |
+
desc = gr.Textbox(label="Description", placeholder="Enter a description")
|
36 |
+
intermediate_image = gr.Image(label="Generated Image", type="filepath", width=256, height=256)
|
37 |
+
output_image = gr.Image(label="Upscaled Image", type="filepath", width=256, height=256)
|
38 |
|
39 |
+
b0 = gr.Button("Generate")
|
40 |
+
b1 = gr.Button("Upscale")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
b0.click(desc_to_image, inputs=[desc], outputs=[intermediate_image])
|
43 |
+
b1.click(upscale_img, inputs=[intermediate_image], outputs=output_image)
|
44 |
|
45 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|