updated requirements, print progress

This commit is contained in:
2023-04-02 21:28:24 +02:00
parent a02eefbfea
commit b63593560d
4 changed files with 12 additions and 28 deletions

View File

@@ -6,7 +6,6 @@ import time
import openai
import pyperclip
from rich.pretty import pprint
from .save import save_images_from_openai, upload_to_s3, save_output
@@ -46,15 +45,19 @@ def generate_images(prompt: str, num_images: int, save_path: pl.Path = SAVE_PATH
if num_images > 10:
raise ValueError("num_images must be <= 10")
start = time.time()
print("Generating images...")
res = openai.Image.create(prompt=prompt, n=num_images) # type: ignore
print("Saving images...")
file_paths = save_images_from_openai(prompt, res, save_path) # type: ignore
if save_to_s3:
if S3_BUCKET is None:
raise NoBucket("Please provide AI_GETTER_S3_BUCKET in .env")
for fp in file_paths:
print("Uploading images to S3...")
for idx, fp in enumerate(file_paths):
print(idx)
upload_to_s3(bucket_name=S3_BUCKET, file_path=fp, key=fp, prompt=prompt, typ="image", vendor="openai")
print(f"Time taken: {time.time() - start} seconds")
print(f"Cost: {OPENAI_DALE_COST_PER_IMAGE_IN_TENTHS_OF_A_CENT * num_images * 10} cents")
print(f"Cost: {OPENAI_DALE_COST_PER_IMAGE_IN_TENTHS_OF_A_CENT * num_images / 10} cents")
return res # type: ignore

View File

@@ -39,7 +39,7 @@ def make_fp_from_prompt(
prompt_fn = f"{prompt_fn}{index}"
prompt_fn = f"{prompt_fn}-{dt.datetime.now()}"
prompt_fn = f"{prompt_fn}.{ext}"
return save_path / prompt_fn
return save_path / prompt_fn.replace(" ", "")
def save_images_from_openai(
@@ -90,7 +90,9 @@ def download_images(prompt: str, res: dict, save_path: pl.Path) -> list[str]:
fns = []
for idx, image_dict in enumerate(res["data"]):
fn = make_fp_from_prompt(prompt, save_path, index=idx, ext="jpg")
download(image_dict["url"], fn)
url = image_dict["url"]
print(f"Downloading image from {url} to {fn}")
download(url, fn)
fns.append(fn)
return fns

View File

@@ -1,43 +1,22 @@
-e git+https://github.com/zevaverbach/ai_getter@43be074db903f6b8e91198a0efee3a71d5f95b85#egg=ai_getter
aiohttp==3.8.4
aiosignal==1.3.1
asttokens==2.2.1
async-timeout==4.0.2
attrs==22.2.0
backcall==0.2.0
boto3==1.26.104
botocore==1.29.104
certifi==2022.12.7
charset-normalizer==3.1.0
decorator==5.1.1
executing==1.2.0
frozenlist==1.3.3
idna==3.4
ipython==8.12.0
jedi==0.18.2
jmespath==1.0.1
markdown-it-py==2.2.0
matplotlib-inline==0.1.6
mdurl==0.1.2
multidict==6.0.4
openai==0.27.2
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.38
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.14.0
pyperclip==1.8.2
python-dateutil==2.8.2
requests==2.28.2
rich==13.3.3
s3transfer==0.6.0
six==1.16.0
stack-data==0.6.2
tqdm==4.65.0
traitlets==5.9.0
trans==2.1.0
urllib3==1.26.15
wcwidth==0.2.6
yarl==1.8.2

View File

@@ -3,7 +3,7 @@ from setuptools import setup
setup(
name="ai_getter",
version="0.0.1",
version="0.0.2",
description="A CLI for publishing sites to Netlify and assigning custom domains to them.",
author="Zev Averbach",
author_email="zev@averba.ch",
@@ -21,7 +21,7 @@ setup(
],
packages=["ai_getter"],
include_package_data=True,
install_requires=["requests", "openai", "requests"],
install_requires=["requests", "openai", "pyperclip", "trans", "boto3"],
python_requires=">=3.10", # only because we're using | instead of typing.Union; otherwise >= 3.9
url="https://github.com/zevaverbach/ai_getter",
entry_points={"console_scripts": ["aig=ai_getter.main:main"]},