uruguayai commited on
Commit
5af0a6f
·
verified ·
1 Parent(s): c92f81a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -11,12 +11,15 @@ try:
11
  inpaint_model = DiffusionPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1").to(device)
12
  except Exception as e:
13
  print(f"Error initializing model: {e}")
 
14
 
15
  def process_image(prompt, image, style, upscale_factor, inpaint):
16
  try:
17
  # Ensure the image is in the correct format
18
  if image is not None:
19
  image = image.convert("RGB")
 
 
20
 
21
  # Log the input parameters
22
  print(f"Prompt: {prompt}")
@@ -26,11 +29,11 @@ def process_image(prompt, image, style, upscale_factor, inpaint):
26
 
27
  # Example placeholder logic for using the pipeline
28
  # Replace with actual pipeline logic based on selected style
29
- if inpaint:
30
  result = inpaint_model(prompt=prompt, image=image, guidance_scale=7.5)
31
  else:
32
- result = inpaint_model(prompt=prompt, guidance_scale=7.5)
33
-
34
  # Check if the result is valid
35
  if result and hasattr(result, 'images') and len(result.images) > 0:
36
  return result.images[0]
@@ -38,7 +41,9 @@ def process_image(prompt, image, style, upscale_factor, inpaint):
38
  return "Error: No image returned from model."
39
 
40
  except Exception as e:
41
- return f"Error in process_image function: {e}"
 
 
42
 
43
  # Define the Gradio interface
44
  with gr.Blocks() as demo:
 
11
  inpaint_model = DiffusionPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1").to(device)
12
  except Exception as e:
13
  print(f"Error initializing model: {e}")
14
+ inpaint_model = None
15
 
16
  def process_image(prompt, image, style, upscale_factor, inpaint):
17
  try:
18
  # Ensure the image is in the correct format
19
  if image is not None:
20
  image = image.convert("RGB")
21
+ else:
22
+ image = None
23
 
24
  # Log the input parameters
25
  print(f"Prompt: {prompt}")
 
29
 
30
  # Example placeholder logic for using the pipeline
31
  # Replace with actual pipeline logic based on selected style
32
+ if inpaint and inpaint_model:
33
  result = inpaint_model(prompt=prompt, image=image, guidance_scale=7.5)
34
  else:
35
+ result = inpaint_model(prompt=prompt, guidance_scale=7.5) if inpaint_model else None
36
+
37
  # Check if the result is valid
38
  if result and hasattr(result, 'images') and len(result.images) > 0:
39
  return result.images[0]
 
41
  return "Error: No image returned from model."
42
 
43
  except Exception as e:
44
+ error_message = f"Error in process_image function: {e}"
45
+ print(error_message)
46
+ return error_message
47
 
48
  # Define the Gradio interface
49
  with gr.Blocks() as demo: