Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,10 @@ import boto3
|
|
| 13 |
from botocore.exceptions import ClientError
|
| 14 |
from PIL import Image
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
torch.set_grad_enabled(False)
|
| 17 |
|
| 18 |
pipeline = PuLIDPipeline()
|
|
@@ -98,6 +102,33 @@ def run(bucket_folder, person_name, req_id, gender='male'):
|
|
| 98 |
|
| 99 |
id_image = image_paths[0]
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
if image_paths is not None:
|
| 102 |
id_image = resize_numpy_image_long(np.array(Image.open(image_paths[0])), 1024)
|
| 103 |
id_embeddings = pipeline.get_id_embedding(id_image)
|
|
@@ -111,7 +142,6 @@ def run(bucket_folder, person_name, req_id, gender='male'):
|
|
| 111 |
id_embeddings = None
|
| 112 |
|
| 113 |
seed_everything(seed)
|
| 114 |
-
ims = []
|
| 115 |
for _ in range(n_samples):
|
| 116 |
img = pipeline.inference(prompt, (1, H, W), neg_prompt, id_embeddings, id_scale, scale, steps)[0]
|
| 117 |
ims.append(np.array(img))
|
|
|
|
| 13 |
from botocore.exceptions import ClientError
|
| 14 |
from PIL import Image
|
| 15 |
|
| 16 |
+
from google import genai
|
| 17 |
+
from google.genai import types
|
| 18 |
+
from io import BytesIO
|
| 19 |
+
|
| 20 |
torch.set_grad_enabled(False)
|
| 21 |
|
| 22 |
pipeline = PuLIDPipeline()
|
|
|
|
| 102 |
|
| 103 |
id_image = image_paths[0]
|
| 104 |
|
| 105 |
+
ims = []
|
| 106 |
+
|
| 107 |
+
#--------------Google Gemini---------------#
|
| 108 |
+
|
| 109 |
+
client = genai.Client(api_key='AIzaSyC5UG7dpBbik4ULenbf-xPYvfObnFv0i8E')
|
| 110 |
+
|
| 111 |
+
image = Image.open(id_image)
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
response = client.models.generate_content(
|
| 115 |
+
model="gemini-2.5-flash-image-preview",
|
| 116 |
+
contents=[prompt, image],
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
for part in response.candidates[0].content.parts:
|
| 120 |
+
if part.text is not None:
|
| 121 |
+
print(part.text)
|
| 122 |
+
elif part.inline_data is not None:
|
| 123 |
+
image = Image.open(BytesIO(part.inline_data.data))
|
| 124 |
+
ims.append(image)
|
| 125 |
+
except:
|
| 126 |
+
print('Error while calling GEMINI')
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
#----------------------------------------#
|
| 130 |
+
|
| 131 |
+
|
| 132 |
if image_paths is not None:
|
| 133 |
id_image = resize_numpy_image_long(np.array(Image.open(image_paths[0])), 1024)
|
| 134 |
id_embeddings = pipeline.get_id_embedding(id_image)
|
|
|
|
| 142 |
id_embeddings = None
|
| 143 |
|
| 144 |
seed_everything(seed)
|
|
|
|
| 145 |
for _ in range(n_samples):
|
| 146 |
img = pipeline.inference(prompt, (1, H, W), neg_prompt, id_embeddings, id_scale, scale, steps)[0]
|
| 147 |
ims.append(np.array(img))
|