File size: 1,981 Bytes
410074c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0e8178
 
 
 
e8d24b2
f0e8178
e8d24b2
e53f977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0e8178
e53f977
 
e7e1126
e53f977
 
 
f0e8178
e53f977
 
f0e8178
e53f977
 
f0e8178
e53f977
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
57
58
59
60
61
62
63
64
65
import gradio as gr

# Replace 'your_space' with the actual names of your Hugging Face spaces
ds_space = "artificialguybr/DREAMSHAPER-XL-FREE-DEMO"
es_space = "akhaliq/Real-ESRGAN"

try:
    ds_iface = gr.Interface.load(ds_space)
    print("Loaded Dreamshaper Interface:", ds_iface)
except Exception as e:
    print("Failed to load Dreamshaper Interface:", str(e))

try:
    es_iface = gr.Interface.load(es_space)
    print("Loaded ESRGAN Interface:", es_iface)
except Exception as e:
    print("Failed to load ESRGAN Interface:", str(e))





from asyncio import constants
import gradio as gr
import re

demo = gr.Blocks()

with demo:
    print("Interfaces Loaded:", ds_iface, es_iface)  # Check if interfaces are loaded correctly

    def desc_to_image(desc):
        desc = " ".join(desc.split('\n'))
        prompt = re.sub(r'[^a-zA-Z0-9 ,.]', '', desc)
        try:
            img = ds_iface(prompt)[0]  # Ensure ds_iface is callable and returns expected result
        except Exception as e:
            print("Error in desc_to_image:", e)
            return None
        return img
    
    def upscale_img(img):
        try:
            model = 'base'
            uimg = es_iface(img, model)  # Ensure es_iface is callable and returns expected result
        except Exception as e:
            print("Error in upscale_img:", e)
            return None
        return uimg

    gr.Markdown("<h1><center>NPC Generator</center></h1>")
    # Other HTML and Gradio components...

    desc = gr.Textbox(label="Description", placeholder="Enter a description")
    intermediate_image = gr.Image(label="Generated Image", type="filepath", width=256, height=256)
    output_image = gr.Image(label="Upscaled Image", type="filepath", width=256, height=256)

    b0 = gr.Button("Generate")
    b1 = gr.Button("Upscale")

    b0.click(desc_to_image, inputs=[desc], outputs=[intermediate_image])
    b1.click(upscale_img, inputs=[intermediate_image], outputs=output_image)

demo.launch()