Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from daggr import GradioNode, Graph
|
| 6 |
+
|
| 7 |
+
glm_image = GradioNode(
|
| 8 |
+
"hf-applications/Z-Image-Turbo",
|
| 9 |
+
api_name="/generate_image",
|
| 10 |
+
inputs={
|
| 11 |
+
"prompt": gr.Textbox( # An input node is created for the prompt
|
| 12 |
+
label="Prompt",
|
| 13 |
+
value="A cheetah the grassy savanna.",
|
| 14 |
+
lines=3,
|
| 15 |
+
),
|
| 16 |
+
"height": 1024, # Fixed value (does not appear in the canvas)
|
| 17 |
+
"width": 1024, # Fixed value (does not appear in the canvas)
|
| 18 |
+
"seed": random.random, # Functions are rerun every time the workflow is run (not shown in the canvas)
|
| 19 |
+
},
|
| 20 |
+
outputs={
|
| 21 |
+
"image": gr.Image(
|
| 22 |
+
label="Image" # Display in an Image component
|
| 23 |
+
),
|
| 24 |
+
},
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
background_remover = GradioNode(
|
| 28 |
+
"hf-applications/background-removal",
|
| 29 |
+
api_name="/image",
|
| 30 |
+
inputs={
|
| 31 |
+
"image": glm_image.image, # Connect the output of the GLM Image node to the input of the background remover node
|
| 32 |
+
},
|
| 33 |
+
outputs={
|
| 34 |
+
"original_image": None, # Original image is returned but not displayed
|
| 35 |
+
"final_image": gr.Image(
|
| 36 |
+
label="Final Image"
|
| 37 |
+
), # Transparent bg image is displayed
|
| 38 |
+
},
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
graph = Graph(
|
| 42 |
+
name="Transparent Background Image Generator", nodes=[glm_image, background_remover]
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
graph.launch()
|