bennyguo commited on
Commit
b98ab62
·
1 Parent(s): f58f6bd

add prompt confidence

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -154,7 +154,7 @@ def get_random_seed():
154
 
155
  # Apply decorator conditionally
156
  @spaces.GPU() if ENABLE_ZEROGPU else lambda func: func
157
- def generate_3d(scribble_image_dict, prompt, scribble_confidence, seed): # Added seed parameter back
158
  print("Generating 3D model...")
159
  # Extract the composite image from the ImageEditor dictionary
160
  if scribble_image_dict is None or scribble_image_dict.get("composite") is None:
@@ -177,7 +177,7 @@ def generate_3d(scribble_image_dict, prompt, scribble_confidence, seed): # Added
177
  print("Image preprocessed.")
178
 
179
  # Define fixed parameters
180
- attn_scale_text = 1.0 # As per the example run.py
181
 
182
  # Set the generator with the provided seed
183
  generator = torch.Generator(device='cuda').manual_seed(current_seed)
@@ -187,11 +187,11 @@ def generate_3d(scribble_image_dict, prompt, scribble_confidence, seed): # Added
187
  out = pipe(
188
  processed_image,
189
  prompt=prompt,
190
- num_tokens=512,
191
- guidance_scale=0,
192
- num_inference_steps=16,
193
  attention_kwargs={
194
- "cross_attention_scale": attn_scale_text,
195
  "cross_attention_2_scale": scribble_confidence
196
  },
197
  generator=generator,
@@ -229,6 +229,7 @@ with gr.Blocks() as demo:
229
  )
230
  prompt_input = gr.Textbox(label="Prompt", placeholder="e.g., a cute cat wearing a hat")
231
  confidence_input = gr.Slider(minimum=0.0, maximum=1.0, value=0.4, step=0.05, label="Scribble Confidence")
 
232
  seed_input = gr.Number(label="Seed", value=0, precision=0) # Added Seed input back
233
  with gr.Row():
234
  submit_button = gr.Button("Generate 3D Model", variant="primary", scale=1)
@@ -237,16 +238,16 @@ with gr.Blocks() as demo:
237
  model_output = gr.Model3D(label="Generated 3D Model", interactive=False)
238
 
239
  # Define the inputs for the main generation function
240
- gen_inputs = [image_input, prompt_input, confidence_input, seed_input]
241
 
242
  submit_button.click(
243
  fn=generate_3d,
244
- inputs=gen_inputs, # Include seed_input
245
  outputs=model_output
246
  )
247
 
248
  # Define inputs for the lucky button (same as main button for the final call)
249
- lucky_gen_inputs = [image_input, prompt_input, confidence_input, seed_input]
250
 
251
  lucky_button.click(
252
  fn=get_random_seed, # First, get a random seed
 
154
 
155
  # Apply decorator conditionally
156
  @spaces.GPU() if ENABLE_ZEROGPU else lambda func: func
157
+ def generate_3d(scribble_image_dict, prompt, scribble_confidence, prompt_confidence, seed): # Added text_confidence parameter
158
  print("Generating 3D model...")
159
  # Extract the composite image from the ImageEditor dictionary
160
  if scribble_image_dict is None or scribble_image_dict.get("composite") is None:
 
177
  print("Image preprocessed.")
178
 
179
  # Define fixed parameters
180
+ # attn_scale_text = 1.0 # Replaced by text_confidence input
181
 
182
  # Set the generator with the provided seed
183
  generator = torch.Generator(device='cuda').manual_seed(current_seed)
 
187
  out = pipe(
188
  processed_image,
189
  prompt=prompt,
190
+ num_tokens=512, # Default value from example
191
+ guidance_scale=0, # Default value from example
192
+ num_inference_steps=16, # Default value from example
193
  attention_kwargs={
194
+ "cross_attention_scale": prompt_confidence, # Use input parameter
195
  "cross_attention_2_scale": scribble_confidence
196
  },
197
  generator=generator,
 
229
  )
230
  prompt_input = gr.Textbox(label="Prompt", placeholder="e.g., a cute cat wearing a hat")
231
  confidence_input = gr.Slider(minimum=0.0, maximum=1.0, value=0.4, step=0.05, label="Scribble Confidence")
232
+ prompt_confidence_input = gr.Slider(minimum=0.0, maximum=1.0, value=1.0, step=0.05, label="Prompt Confidence") # Added slider
233
  seed_input = gr.Number(label="Seed", value=0, precision=0) # Added Seed input back
234
  with gr.Row():
235
  submit_button = gr.Button("Generate 3D Model", variant="primary", scale=1)
 
238
  model_output = gr.Model3D(label="Generated 3D Model", interactive=False)
239
 
240
  # Define the inputs for the main generation function
241
+ gen_inputs = [image_input, prompt_input, confidence_input, prompt_confidence_input, seed_input] # Added text_confidence_input
242
 
243
  submit_button.click(
244
  fn=generate_3d,
245
+ inputs=gen_inputs, # Include seed_input and text_confidence_input
246
  outputs=model_output
247
  )
248
 
249
  # Define inputs for the lucky button (same as main button for the final call)
250
+ lucky_gen_inputs = [image_input, prompt_input, confidence_input, prompt_confidence_input, seed_input] # Added text_confidence_input
251
 
252
  lucky_button.click(
253
  fn=get_random_seed, # First, get a random seed