Spaces:
Runtime error
Runtime error
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() | |