Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def generate_from_latents(prompt, apply_edge_loss=False):
|
| 4 |
+
# ... [All your processing, including the loop]
|
| 5 |
+
|
| 6 |
+
# Generate image without edge loss
|
| 7 |
+
image_without_loss = latents_to_pil(latents)[0]
|
| 8 |
+
|
| 9 |
+
if apply_edge_loss:
|
| 10 |
+
# Apply the edge (Laplacian) loss and regenerate the image
|
| 11 |
+
# [Your logic for applying the edge loss and regenerating the image goes here]
|
| 12 |
+
# You might run another loop similar to the one you have but with the edge loss applied.
|
| 13 |
+
image_with_loss = latents_to_pil(latents_with_loss)[0]
|
| 14 |
+
else:
|
| 15 |
+
image_with_loss = image_without_loss # Or keep it the same if not applying edge loss
|
| 16 |
+
|
| 17 |
+
return image_without_loss, image_with_loss
|
| 18 |
+
|
| 19 |
+
# Define the Gradio interface
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=generate_from_latents,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.inputs.Textbox(default="Canvas showing moonlight in night", label="Input Prompt"),
|
| 24 |
+
gr.inputs.Checkbox(label="Apply Edge Loss")
|
| 25 |
+
],
|
| 26 |
+
outputs=[
|
| 27 |
+
gr.outputs.Image(plot=True, label="Without Edge Loss"),
|
| 28 |
+
gr.outputs.Image(plot=True, label="With Edge Loss")
|
| 29 |
+
]
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch()
|