Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,14 +20,10 @@ vision_model = MllamaForConditionalGeneration.from_pretrained(
|
|
20 |
)
|
21 |
processor = AutoProcessor.from_pretrained(llama_vision_model_id, token=hf_token)
|
22 |
|
23 |
-
# Set up
|
24 |
-
segment_model_id = "
|
25 |
-
|
26 |
-
|
27 |
-
model=segment_model_id,
|
28 |
-
device=0, # Force usage of GPU
|
29 |
-
token=hf_token # Updated to use 'token' instead of 'use_auth_token'
|
30 |
-
)
|
31 |
|
32 |
# Set up Stable Diffusion Lite model
|
33 |
stable_diffusion_model_id = "runwayml/stable-diffusion-v1-5"
|
@@ -45,9 +41,10 @@ def process_image(image):
|
|
45 |
output = vision_model.generate(**inputs, max_new_tokens=50)
|
46 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
47 |
|
48 |
-
# Step 2: Segment important parts of the image
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
# Step 3: Modify segmented image using Diffusion model
|
53 |
# Here, we modify based on the caption result and segmented area
|
|
|
20 |
)
|
21 |
processor = AutoProcessor.from_pretrained(llama_vision_model_id, token=hf_token)
|
22 |
|
23 |
+
# Set up segmentation model using Segment Anything 2 (sam2_hiera_small.pt)
|
24 |
+
segment_model_id = "camenduru/segment-anything-2"
|
25 |
+
segment_model_path = "sam2_hiera_small.pt"
|
26 |
+
segment_pipe = torch.load(segment_model_path, map_location="cuda") # Load segmentation model on GPU
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Set up Stable Diffusion Lite model
|
29 |
stable_diffusion_model_id = "runwayml/stable-diffusion-v1-5"
|
|
|
41 |
output = vision_model.generate(**inputs, max_new_tokens=50)
|
42 |
caption = processor.decode(output[0], skip_special_tokens=True)
|
43 |
|
44 |
+
# Step 2: Segment important parts of the image using Segment Anything 2
|
45 |
+
# Use the loaded segment model to perform segmentation
|
46 |
+
segmented_result = segment_pipe(image=image) # Assuming a callable model or appropriate method
|
47 |
+
segments = segmented_result
|
48 |
|
49 |
# Step 3: Modify segmented image using Diffusion model
|
50 |
# Here, we modify based on the caption result and segmented area
|