Spaces:
Runtime error
Runtime error
Himanshu-AT commited on
Commit ·
e08bb94
1
Parent(s): fceb263
add sam
Browse files- app.py +18 -6
- lora_models.json +2 -1
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import os
|
| 4 |
-
import spaces
|
| 5 |
import random
|
| 6 |
import json
|
| 7 |
-
# from image_gen_aux import DepthPreprocessor
|
| 8 |
from PIL import Image
|
| 9 |
import torch
|
| 10 |
from torchvision import transforms
|
| 11 |
|
| 12 |
from diffusers import FluxFillPipeline, AutoencoderKL
|
| 13 |
from PIL import Image
|
| 14 |
-
|
| 15 |
|
| 16 |
MAX_SEED = np.iinfo(np.int32).max
|
| 17 |
MAX_IMAGE_SIZE = 2048
|
| 18 |
|
|
|
|
|
|
|
| 19 |
pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
|
| 20 |
-
# pipe.load_lora_weights("Himanshu806/testLora")
|
| 21 |
-
# pipe.enable_lora()
|
| 22 |
|
| 23 |
with open("lora_models.json", "r") as f:
|
| 24 |
lora_models = json.load(f)
|
|
@@ -119,6 +119,11 @@ def download_image(image):
|
|
| 119 |
def set_image_as_inpaint(image):
|
| 120 |
return image
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
examples = [
|
| 123 |
"photography of a young woman, accent lighting, (front view:1.4), "
|
| 124 |
# "a tiny astronaut hatching from an egg on the moon",
|
|
@@ -237,6 +242,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 237 |
outputs=[edit_image]
|
| 238 |
)
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
# demo.launch()
|
| 241 |
PASSWORD = os.getenv("GRADIO_PASSWORD")
|
| 242 |
USERNAME = os.getenv("GRADIO_USERNAME")
|
|
@@ -249,7 +260,8 @@ def authenticate(username, password):
|
|
| 249 |
return False
|
| 250 |
# Launch the app with authentication
|
| 251 |
|
| 252 |
-
demo.launch(auth=authenticate)
|
|
|
|
| 253 |
|
| 254 |
|
| 255 |
# import gradio as gr
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
import os
|
|
|
|
| 6 |
import random
|
| 7 |
import json
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
import torch
|
| 10 |
from torchvision import transforms
|
| 11 |
|
| 12 |
from diffusers import FluxFillPipeline, AutoencoderKL
|
| 13 |
from PIL import Image
|
| 14 |
+
from samgeo.text_sam import LangSAM
|
| 15 |
|
| 16 |
MAX_SEED = np.iinfo(np.int32).max
|
| 17 |
MAX_IMAGE_SIZE = 2048
|
| 18 |
|
| 19 |
+
sam = LangSAM(model_type="sam2-hiera-large")
|
| 20 |
+
|
| 21 |
pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
|
|
|
|
|
|
|
| 22 |
|
| 23 |
with open("lora_models.json", "r") as f:
|
| 24 |
lora_models = json.load(f)
|
|
|
|
| 119 |
def set_image_as_inpaint(image):
|
| 120 |
return image
|
| 121 |
|
| 122 |
+
def generate_mask(image, click_x, click_y):
|
| 123 |
+
text_prompt = "face"
|
| 124 |
+
mask = sam.predict(image, text_prompt, box_threshold=0.24, text_threshold=0.24)
|
| 125 |
+
return mask
|
| 126 |
+
|
| 127 |
examples = [
|
| 128 |
"photography of a young woman, accent lighting, (front view:1.4), "
|
| 129 |
# "a tiny astronaut hatching from an egg on the moon",
|
|
|
|
| 242 |
outputs=[edit_image]
|
| 243 |
)
|
| 244 |
|
| 245 |
+
edit_image.select(
|
| 246 |
+
fn=generate_mask,
|
| 247 |
+
inputs=[edit_image, gr.Number(), gr.Number()],
|
| 248 |
+
outputs=[edit_image]
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
# demo.launch()
|
| 252 |
PASSWORD = os.getenv("GRADIO_PASSWORD")
|
| 253 |
USERNAME = os.getenv("GRADIO_USERNAME")
|
|
|
|
| 260 |
return False
|
| 261 |
# Launch the app with authentication
|
| 262 |
|
| 263 |
+
demo.launch(debug=True, auth=authenticate)
|
| 264 |
+
# demo.launch()
|
| 265 |
|
| 266 |
|
| 267 |
# import gradio as gr
|
lora_models.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"RahulFineTuned (qwertyui)": "Himanshu806/testLora",
|
|
|
|
| 3 |
"KodaRealistic (fmlft style)": "alvdansen/flux-koda",
|
| 4 |
-
"
|
| 5 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"RahulFineTuned (qwertyui)": "Himanshu806/testLora",
|
| 3 |
+
"femaleIndian (indmodelf)": "Himanshu806/ind-f-model",
|
| 4 |
"KodaRealistic (fmlft style)": "alvdansen/flux-koda",
|
| 5 |
+
"superRealism (Super Realism)": "strangerzonehf/Flux-Super-Realism-LoRA"
|
| 6 |
}
|
requirements.txt
CHANGED
|
@@ -8,4 +8,5 @@ peft
|
|
| 8 |
xformers
|
| 9 |
torchvision
|
| 10 |
torch
|
| 11 |
-
opencv-python
|
|
|
|
|
|
| 8 |
xformers
|
| 9 |
torchvision
|
| 10 |
torch
|
| 11 |
+
opencv-python
|
| 12 |
+
segment-geospatial
|