Spaces:
Runtime error
Runtime error
getting a response from vertex
Browse files- README.md +2 -2
- app.py +17 -18
- requirements.txt +1 -3
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title: PDR
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
|
|
|
| 1 |
---
|
| 2 |
+
title: PDR Vertex
|
| 3 |
+
emoji: 📐
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
app.py
CHANGED
|
@@ -13,7 +13,6 @@ from PIL import Image
|
|
| 13 |
|
| 14 |
# gradio / hf / image gen stuff
|
| 15 |
import gradio as gr
|
| 16 |
-
import anthropic
|
| 17 |
from dotenv import load_dotenv
|
| 18 |
|
| 19 |
# stats stuff
|
|
@@ -21,10 +20,17 @@ from pymongo.mongo_client import MongoClient
|
|
| 21 |
from pymongo.server_api import ServerApi
|
| 22 |
import time
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
load_dotenv()
|
| 26 |
|
| 27 |
-
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
|
| 28 |
|
| 29 |
pw_key = os.getenv("PW")
|
| 30 |
|
|
@@ -34,11 +40,6 @@ if pw_key == "<YOUR_PW>":
|
|
| 34 |
if pw_key == "":
|
| 35 |
sys.exit("Please Provide A Password in the Environment Variables")
|
| 36 |
|
| 37 |
-
if ANTHROPIC_API_KEY == "":
|
| 38 |
-
sys.exit("Please Provide Your API Key")
|
| 39 |
-
|
| 40 |
-
client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
|
| 41 |
-
print(client)
|
| 42 |
|
| 43 |
# Connect to MongoDB
|
| 44 |
uri = os.getenv("MONGO_URI")
|
|
@@ -121,7 +122,7 @@ def generate_images(prompts, pw):
|
|
| 121 |
# Split the prompts string into individual prompts based on semicolon separation
|
| 122 |
prompts_list = [prompt for prompt in prompts.split(';') if prompt]
|
| 123 |
|
| 124 |
-
model = "claude-3-opus-20240229"
|
| 125 |
|
| 126 |
for i, entry in enumerate(prompts_list):
|
| 127 |
entry_parts = entry.split('-', 1) # Split by the first dash found
|
|
@@ -137,17 +138,15 @@ def generate_images(prompts, pw):
|
|
| 137 |
prompt_w_challenge = f"{challenge}: {text}"
|
| 138 |
print(prompt_w_challenge)
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
"content": f"Generate an image that depicts the following prompt: {prompt_w_challenge}"
|
| 146 |
-
}
|
| 147 |
-
],
|
| 148 |
-
model=model,
|
| 149 |
)
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
|
| 152 |
|
| 153 |
|
|
|
|
| 13 |
|
| 14 |
# gradio / hf / image gen stuff
|
| 15 |
import gradio as gr
|
|
|
|
| 16 |
from dotenv import load_dotenv
|
| 17 |
|
| 18 |
# stats stuff
|
|
|
|
| 20 |
from pymongo.server_api import ServerApi
|
| 21 |
import time
|
| 22 |
|
| 23 |
+
# countdown stuff
|
| 24 |
+
from datetime import datetime, timedelta
|
| 25 |
+
|
| 26 |
+
from google.cloud import aiplatform
|
| 27 |
+
import vertexai
|
| 28 |
+
# from vertexai.preview.generative_models import GenerativeModel
|
| 29 |
+
from vertexai.preview.vision_models import ImageGenerationModel
|
| 30 |
+
from vertexai import preview
|
| 31 |
|
| 32 |
load_dotenv()
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
pw_key = os.getenv("PW")
|
| 36 |
|
|
|
|
| 40 |
if pw_key == "":
|
| 41 |
sys.exit("Please Provide A Password in the Environment Variables")
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Connect to MongoDB
|
| 45 |
uri = os.getenv("MONGO_URI")
|
|
|
|
| 122 |
# Split the prompts string into individual prompts based on semicolon separation
|
| 123 |
prompts_list = [prompt for prompt in prompts.split(';') if prompt]
|
| 124 |
|
| 125 |
+
# model = "claude-3-opus-20240229"
|
| 126 |
|
| 127 |
for i, entry in enumerate(prompts_list):
|
| 128 |
entry_parts = entry.split('-', 1) # Split by the first dash found
|
|
|
|
| 138 |
prompt_w_challenge = f"{challenge}: {text}"
|
| 139 |
print(prompt_w_challenge)
|
| 140 |
|
| 141 |
+
#how to get model?
|
| 142 |
+
model = ImageGenerationModel.from_pretrained("imagegeneration@002")
|
| 143 |
+
response = model.generate_images(
|
| 144 |
+
prompt=prompt_w_challenge,
|
| 145 |
+
number_of_images=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
)
|
| 147 |
+
|
| 148 |
+
print(response[0])
|
| 149 |
+
response[0].show()
|
| 150 |
|
| 151 |
|
| 152 |
|
requirements.txt
CHANGED
|
@@ -2,6 +2,4 @@ gradio==4.2.0
|
|
| 2 |
openai==1.2.3
|
| 3 |
python-dotenv==1.0.0
|
| 4 |
pymongo
|
| 5 |
-
|
| 6 |
-
anthropic==0.18.1
|
| 7 |
-
tokenizers==0.15.2
|
|
|
|
| 2 |
openai==1.2.3
|
| 3 |
python-dotenv==1.0.0
|
| 4 |
pymongo
|
| 5 |
+
google-cloud-aiplatform>=1.38
|
|
|
|
|
|