zaikaman commited on
Commit
76abe8c
·
verified ·
1 Parent(s): e3f3e4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -9,8 +9,8 @@ import shutil
9
  from gradio_client import Client, handle_file
10
 
11
  # Function to load Stable Diffusion Inpainting model
12
- def load_inpainting_model():
13
- model_path = "uberRealisticPornMerge_v13Inpainting.safetensors"
14
  device = "cuda" if torch.cuda.is_available() else "cpu"
15
  pipe = StableDiffusionInpaintPipeline.from_single_file(
16
  model_path,
@@ -60,8 +60,8 @@ def inpaint_image(input_image, mask_image, inpaint_pipeline):
60
  inpainted_image = upscale_image(inpainted_image)
61
  return inpainted_image
62
 
63
- # Function to process input image and mask
64
- def process_image(input_image):
65
  # Save the input image temporarily to process with Replicate
66
  input_image_path = "temp_input_image.png"
67
  input_image.save(input_image_path)
@@ -73,8 +73,8 @@ def process_image(input_image):
73
  mask_image_path = "generated_mask.png"
74
  save_mask(mask_local_path, save_path=mask_image_path)
75
 
76
- # Step 3: Load the inpainting model
77
- inpaint_pipeline = load_inpainting_model()
78
 
79
  # Step 4: Open the mask image and perform inpainting
80
  mask_image = Image.open(mask_image_path)
@@ -94,12 +94,22 @@ with gr.Blocks() as demo:
94
  input_image = gr.Image(label="Upload Input Image", type="pil")
95
  output_image = gr.Image(type="pil", label="Output Image")
96
 
 
 
 
 
 
 
 
 
 
 
97
  # Button to trigger the process
98
  with gr.Row():
99
  btn = gr.Button("Run Inpainting")
100
 
101
  # Function to run when button is clicked
102
- btn.click(fn=process_image, inputs=input_image, outputs=output_image)
103
 
104
  # Launch the Gradio app with share=True to allow public access
105
  demo.launch(share=True)
 
9
  from gradio_client import Client, handle_file
10
 
11
  # Function to load Stable Diffusion Inpainting model
12
+ def load_inpainting_model(model_name):
13
+ model_path = model_name
14
  device = "cuda" if torch.cuda.is_available() else "cpu"
15
  pipe = StableDiffusionInpaintPipeline.from_single_file(
16
  model_path,
 
60
  inpainted_image = upscale_image(inpainted_image)
61
  return inpainted_image
62
 
63
+ # Function to process input image and mask with the selected model
64
+ def process_image(input_image, model_choice):
65
  # Save the input image temporarily to process with Replicate
66
  input_image_path = "temp_input_image.png"
67
  input_image.save(input_image_path)
 
73
  mask_image_path = "generated_mask.png"
74
  save_mask(mask_local_path, save_path=mask_image_path)
75
 
76
+ # Step 3: Load the selected inpainting model
77
+ inpaint_pipeline = load_inpainting_model(model_choice)
78
 
79
  # Step 4: Open the mask image and perform inpainting
80
  mask_image = Image.open(mask_image_path)
 
94
  input_image = gr.Image(label="Upload Input Image", type="pil")
95
  output_image = gr.Image(type="pil", label="Output Image")
96
 
97
+ # Dropdown for selecting the model checkpoint
98
+ model_choice = gr.Dropdown(
99
+ choices=[
100
+ "uberRealisticPornMerge_v13Inpainting.safetensors",
101
+ "realvisxlV50_v50LightningBakedvae.safetensors"
102
+ ],
103
+ label="Choose Inpainting Model",
104
+ value="uberRealisticPornMerge_v13Inpainting.safetensors" # Default model
105
+ )
106
+
107
  # Button to trigger the process
108
  with gr.Row():
109
  btn = gr.Button("Run Inpainting")
110
 
111
  # Function to run when button is clicked
112
+ btn.click(fn=process_image, inputs=[input_image, model_choice], outputs=output_image)
113
 
114
  # Launch the Gradio app with share=True to allow public access
115
  demo.launch(share=True)