Spaces:
Runtime error
Runtime error
Commit ·
49bbcba
1
Parent(s): a414223
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,21 +92,31 @@ def diffuse(text: str):
|
|
| 92 |
# add image to Cloud Storage
|
| 93 |
im = out.images[0]
|
| 94 |
im.save(f'{_id}.png', format='png')
|
|
|
|
| 95 |
# push to storage
|
| 96 |
try:
|
| 97 |
blob = bucket.blob(f'images/{_id}.png')
|
| 98 |
blob.upload_from_filename(f'{_id}.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
-
print("New image not uploaded due to error
|
| 101 |
# delete local file
|
| 102 |
os.remove(f'{_id}.png')
|
| 103 |
-
# add embedding and metadata to Pinecone
|
| 104 |
-
embeds = encode_text(text)
|
| 105 |
-
meta = {
|
| 106 |
-
'prompt': text,
|
| 107 |
-
'image_url': f'images/{_id}.png'
|
| 108 |
-
}
|
| 109 |
-
index.upsert([(_id, embeds, meta)])
|
| 110 |
return out.images[0]
|
| 111 |
|
| 112 |
def get_image(url: str):
|
|
|
|
| 92 |
# add image to Cloud Storage
|
| 93 |
im = out.images[0]
|
| 94 |
im.save(f'{_id}.png', format='png')
|
| 95 |
+
added_gcp = False
|
| 96 |
# push to storage
|
| 97 |
try:
|
| 98 |
blob = bucket.blob(f'images/{_id}.png')
|
| 99 |
blob.upload_from_filename(f'{_id}.png')
|
| 100 |
+
added_gcp = True
|
| 101 |
+
# add embedding and metadata to Pinecone
|
| 102 |
+
embeds = encode_text(text)
|
| 103 |
+
meta = {
|
| 104 |
+
'prompt': text,
|
| 105 |
+
'image_url': f'images/{_id}.png'
|
| 106 |
+
}
|
| 107 |
+
try:
|
| 108 |
+
index.upsert([(_id, embeds, meta)])
|
| 109 |
+
except Exception as e:
|
| 110 |
+
try:
|
| 111 |
+
pinecone.init(api_key=PINECONE_KEY, environment='us-west1-gcp')
|
| 112 |
+
index2 = pinecone.Index(index_id)
|
| 113 |
+
index2.upsert([(_id, embeds, meta)])
|
| 114 |
+
except Exception as e:
|
| 115 |
+
print(f"PINECONE_ERROR: {e}")
|
| 116 |
except Exception as e:
|
| 117 |
+
print(f"ERROR: New image not uploaded due to error with {'Pinecone' if added_gcp else 'Cloud Storage'}")
|
| 118 |
# delete local file
|
| 119 |
os.remove(f'{_id}.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
return out.images[0]
|
| 121 |
|
| 122 |
def get_image(url: str):
|