Update app.py
Browse files
app.py
CHANGED
@@ -30,26 +30,11 @@ def remove_background_rembg(input_path):
|
|
30 |
img = Image.open(io.BytesIO(output_image)).convert("RGBA")
|
31 |
return img
|
32 |
|
33 |
-
# Initialize the pipeline globally for bria
|
34 |
-
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True, device=0)
|
35 |
-
|
36 |
def remove_background_bria(input_path):
|
37 |
print(f"Removing background using bria for image: {input_path}")
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# Proses penghapusan latar belakang
|
43 |
-
result = pipe(image) # Pastikan pipe menerima objek PIL
|
44 |
-
|
45 |
-
# Pastikan Anda memeriksa struktur hasilnya
|
46 |
-
if isinstance(result, list) and len(result) > 0:
|
47 |
-
# Mengambil gambar dari hasil
|
48 |
-
output_image = result[0]['segmentation'] # Atur sesuai dengan struktur hasil dari pipeline
|
49 |
-
output_image = Image.fromarray(output_image) # Konversi kembali ke PIL
|
50 |
-
return output_image
|
51 |
-
else:
|
52 |
-
raise ValueError("Invalid output from bria pipeline")
|
53 |
|
54 |
# Fungsi untuk memproses gambar menggunakan prompt
|
55 |
def text_to_image(prompt):
|
|
|
30 |
img = Image.open(io.BytesIO(output_image)).convert("RGBA")
|
31 |
return img
|
32 |
|
|
|
|
|
|
|
33 |
def remove_background_bria(input_path):
|
34 |
print(f"Removing background using bria for image: {input_path}")
|
35 |
+
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True, device=0)
|
36 |
+
pillow_image = pipe(input_path)
|
37 |
+
return pillow_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Fungsi untuk memproses gambar menggunakan prompt
|
40 |
def text_to_image(prompt):
|