chrisjayden commited on
Commit
09759e3
·
verified ·
1 Parent(s): 7e9bd57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -12,13 +12,12 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
12
  pipe = pipe.to(device)
13
 
14
  # Define the inference function
15
- def ghibli_transform(input_image, prompt="ghibli style", strength=0.75, guidance_scale=7.5):
16
  if input_image is None:
17
  raise gr.Error("No image uploaded! Please upload an image before clicking Transform.")
18
 
19
  # Process the input image (keep it as PIL Image)
20
  try:
21
- # Ensure the image is in RGB and resized
22
  init_image = input_image.convert("RGB").resize((768, 768))
23
  except Exception as e:
24
  raise gr.Error(f"Failed to process image: {str(e)}")
@@ -27,10 +26,10 @@ def ghibli_transform(input_image, prompt="ghibli style", strength=0.75, guidance
27
  try:
28
  output = pipe(
29
  prompt=prompt,
30
- image=init_image, # Pass PIL Image directly
31
  strength=strength,
32
  guidance_scale=guidance_scale,
33
- num_inference_steps=50
34
  ).images[0]
35
  except Exception as e:
36
  raise gr.Error(f"Pipeline error: {str(e)}")
@@ -48,6 +47,7 @@ with gr.Blocks(title="Ghibli Diffusion Image Transformer") as demo:
48
  prompt = gr.Textbox(label="Prompt", value="ghibli style")
49
  strength = gr.Slider(0, 1, value=0.75, step=0.05, label="Strength (How much to transform)")
50
  guidance = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
 
51
  submit_btn = gr.Button("Transform")
52
  with gr.Column():
53
  output_img = gr.Image(label="Ghibli-Style Output")
@@ -55,7 +55,7 @@ with gr.Blocks(title="Ghibli Diffusion Image Transformer") as demo:
55
  # Connect the button to the function
56
  submit_btn.click(
57
  fn=ghibli_transform,
58
- inputs=[input_img, prompt, strength, guidance],
59
  outputs=output_img
60
  )
61
 
 
12
  pipe = pipe.to(device)
13
 
14
  # Define the inference function
15
+ def ghibli_transform(input_image, prompt="ghibli style", strength=0.75, guidance_scale=7.5, num_steps=50):
16
  if input_image is None:
17
  raise gr.Error("No image uploaded! Please upload an image before clicking Transform.")
18
 
19
  # Process the input image (keep it as PIL Image)
20
  try:
 
21
  init_image = input_image.convert("RGB").resize((768, 768))
22
  except Exception as e:
23
  raise gr.Error(f"Failed to process image: {str(e)}")
 
26
  try:
27
  output = pipe(
28
  prompt=prompt,
29
+ image=init_image,
30
  strength=strength,
31
  guidance_scale=guidance_scale,
32
+ num_inference_steps=num_steps # Use the UI-provided value
33
  ).images[0]
34
  except Exception as e:
35
  raise gr.Error(f"Pipeline error: {str(e)}")
 
47
  prompt = gr.Textbox(label="Prompt", value="ghibli style")
48
  strength = gr.Slider(0, 1, value=0.75, step=0.05, label="Strength (How much to transform)")
49
  guidance = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
50
+ num_steps = gr.Slider(10, 100, value=50, step=5, label="Inference Steps (Higher = Better Quality, Slower)")
51
  submit_btn = gr.Button("Transform")
52
  with gr.Column():
53
  output_img = gr.Image(label="Ghibli-Style Output")
 
55
  # Connect the button to the function
56
  submit_btn.click(
57
  fn=ghibli_transform,
58
+ inputs=[input_img, prompt, strength, guidance, num_steps],
59
  outputs=output_img
60
  )
61