Spaces:
Runtime error
Runtime error
refactor: Update generate_image function to accept subject, style, color_scheme, angle, lighting_type, and additional_details as parameters
Browse files
app.py
CHANGED
@@ -64,6 +64,28 @@ def preprocess(input_image):
|
|
64 |
return input_image
|
65 |
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
@spaces.GPU
|
68 |
def generate_mvs(input_image, sample_steps, sample_seed):
|
69 |
seed_everything(sample_seed)
|
@@ -124,21 +146,6 @@ def make3d(images):
|
|
124 |
return mesh_fpath, mesh_glb_fpath
|
125 |
|
126 |
|
127 |
-
@spaces.GPU
|
128 |
-
def generate_image(prompt):
|
129 |
-
checkpoint = "sdxl_lightning_8step_unet.safetensors"
|
130 |
-
num_inference_steps = 8
|
131 |
-
|
132 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(
|
133 |
-
pipe.scheduler.config, timestep_spacing="trailing")
|
134 |
-
pipe.unet.load_state_dict(
|
135 |
-
load_file(hf_hub_download(repo, checkpoint), device="cuda"))
|
136 |
-
|
137 |
-
results = pipe(
|
138 |
-
prompt, num_inference_steps=num_inference_steps, guidance_scale=0)
|
139 |
-
return results.images[0]
|
140 |
-
|
141 |
-
|
142 |
# Configuration
|
143 |
cuda_path = find_cuda()
|
144 |
config_path = 'configs/instant-mesh-large.yaml'
|
@@ -193,8 +200,13 @@ with gr.Blocks() as demo:
|
|
193 |
with gr.Group():
|
194 |
with gr.Tab("Generate Image and Remove Background"):
|
195 |
with gr.Row():
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
submit_prompt = gr.Button(
|
199 |
'Generate Image', scale=1, variant='primary')
|
200 |
|
@@ -267,7 +279,7 @@ with gr.Blocks() as demo:
|
|
267 |
|
268 |
mv_images = gr.State()
|
269 |
|
270 |
-
submit_prompt.click(fn=generate_image, inputs=[
|
271 |
fn=preprocess, inputs=[input_image], outputs=[processed_image]
|
272 |
)
|
273 |
submit_process.click(fn=check_input_image, inputs=[input_image]).success(
|
|
|
64 |
return input_image
|
65 |
|
66 |
|
67 |
+
def generate_prompt(subject, style, color_scheme, angle, lighting_type, additional_details):
|
68 |
+
prompt = f"A 3D cartoon render of {subject}, featuring the entire body and shape, on a transparent background. The style should be {style}, with {color_scheme} colors, emphasizing the essential features and lines. The pose should clearly showcase the full form of the {subject} from a {angle} perspective. Lighting is {lighting_type}, highlighting the volume and depth of the subject. {additional_details}. Output as a high-resolution PNG with no background."
|
69 |
+
return prompt
|
70 |
+
|
71 |
+
|
72 |
+
@spaces.GPU
|
73 |
+
def generate_image(subject, style, color_scheme, angle, lighting_type, additional_details):
|
74 |
+
checkpoint = "sdxl_lightning_8step_unet.safetensors"
|
75 |
+
num_inference_steps = 8
|
76 |
+
|
77 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(
|
78 |
+
pipe.scheduler.config, timestep_spacing="trailing")
|
79 |
+
pipe.unet.load_state_dict(
|
80 |
+
load_file(hf_hub_download(repo, checkpoint), device="cuda"))
|
81 |
+
|
82 |
+
prompt = generate_prompt(subject, style, color_scheme,
|
83 |
+
angle, lighting_type, additional_details)
|
84 |
+
results = pipe(
|
85 |
+
prompt, num_inference_steps=num_inference_steps, guidance_scale=0)
|
86 |
+
return results.images[0]
|
87 |
+
|
88 |
+
|
89 |
@spaces.GPU
|
90 |
def generate_mvs(input_image, sample_steps, sample_seed):
|
91 |
seed_everything(sample_seed)
|
|
|
146 |
return mesh_fpath, mesh_glb_fpath
|
147 |
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
# Configuration
|
150 |
cuda_path = find_cuda()
|
151 |
config_path = 'configs/instant-mesh-large.yaml'
|
|
|
200 |
with gr.Group():
|
201 |
with gr.Tab("Generate Image and Remove Background"):
|
202 |
with gr.Row():
|
203 |
+
subject = gr.Textbox(label='Subject', scale=2)
|
204 |
+
style = gr.Textbox(label='Style', scale=2)
|
205 |
+
color_scheme = gr.Textbox(label='Color Scheme', scale=2)
|
206 |
+
angle = gr.Textbox(label='Angle', scale=2)
|
207 |
+
lighting_type = gr.Textbox(label='Lighting Type', scale=2)
|
208 |
+
additional_details = gr.Textbox(
|
209 |
+
label='Additional Details', scale=2)
|
210 |
submit_prompt = gr.Button(
|
211 |
'Generate Image', scale=1, variant='primary')
|
212 |
|
|
|
279 |
|
280 |
mv_images = gr.State()
|
281 |
|
282 |
+
submit_prompt.click(fn=generate_image, inputs=[subject, style, color_scheme, angle, lighting_type, additional_details], outputs=input_image).success(
|
283 |
fn=preprocess, inputs=[input_image], outputs=[processed_image]
|
284 |
)
|
285 |
submit_process.click(fn=check_input_image, inputs=[input_image]).success(
|