Spaces:
Running
Running
Merge pull request #1 from PrunaAI/nils-flux-dev
Browse filesFiles changed (5)
- README.md+11-2
- api/__init__.py+3
- api/aws.pyAdded+73
- benchmark/metrics/__init__.py+2-2
- nils_installs.txtAdded+177
5 unmodified lines6789105 unmodified linesconda env create -f environment.ymlCreate .env file with all the files you will need.python sample.py replicate draw_bench genai_bench geneval hps parti5 unmodified lines6789101112131415161718195 unmodified linesconda env create -f environment.ymlCreate .env file with all the credentials you will need.This is how you can generate the images.```python sample.py replicate draw_bench genai_bench geneval hps parti```This is how you would evaluate the benchmarks once you have all images:```python evaluate.py replicate draw_bench genai_bench geneval hps parti```
7 unmodified lines891011121319 unmodified lines33343536373813 unmodified lines5253545556577 unmodified linesfrom api.replicate import ReplicateAPIfrom api.together import TogetherAPIfrom api.fal import FalAPI__all__ = ['create_api',19 unmodified lines- "replicate"- "together"- "fal"Returns:FluxAPI: An instance of the requested API implementation13 unmodified lines"replicate": ReplicateAPI,"together": TogetherAPI,"fal": FalAPI,}if api_type not in api_map:7 unmodified lines89101112131419 unmodified lines3435363738394013 unmodified lines545556575859607 unmodified linesfrom api.replicate import ReplicateAPIfrom api.together import TogetherAPIfrom api.fal import FalAPIfrom api.aws import AWSBedrockAPI__all__ = ['create_api',19 unmodified lines- "replicate"- "together"- "fal"- "aws"Returns:FluxAPI: An instance of the requested API implementation13 unmodified lines"replicate": ReplicateAPI,"together": TogetherAPI,"fal": FalAPI,"aws": AWSBedrockAPI,}if api_type not in api_map:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import osimport timeimport base64import jsonfrom pathlib import Pathfrom typing import Any
import boto3from dotenv import load_dotenv
from api.flux import FluxAPI
class AWSBedrockAPI(FluxAPI): def __init__(self): load_dotenv() # AWS credentials should be set via environment variables # AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN os.environ["AWS_ACCESS_KEY_ID"] = "" os.environ["AWS_SECRET_ACCESS_KEY"] = "" os.environ["AWS_SESSION_TOKEN"] = "" os.environ["AWS_REGION"] = "us-east-1" self._client = boto3.client("bedrock-runtime") self._model_id = "amazon.nova-canvas-v1:0"
@property def name(self) -> str: return "aws_nova_canvas"
def generate_image(self, prompt: str, save_path: Path) -> float: start_time = time.time() # Format the request payload native_request = { "taskType": "TEXT_IMAGE", "textToImageParams": {"text": prompt}, "imageGenerationConfig": { "seed": 0, "quality": "standard", "height": 1024, "width": 1024, "numberOfImages": 1, }, }
try: # Convert request to JSON and invoke the model request = json.dumps(native_request) response = self._client.invoke_model( modelId=self._model_id, body=request ) # Process the response model_response = json.loads(response["body"].read()) if not model_response.get("images"): raise Exception("No images returned from AWS Bedrock API") # Save the image base64_image_data = model_response["images"][0] self._save_image_from_base64(base64_image_data, save_path) except Exception as e: raise Exception(f"Error generating image with AWS Bedrock: {str(e)}") end_time = time.time() return end_time - start_time
def _save_image_from_base64(self, base64_data: str, save_path: Path): """Save a base64 encoded image to the specified path.""" save_path.parent.mkdir(parents=True, exist_ok=True) image_data = base64.b64decode(base64_data) with open(save_path, "wb") as f: f.write(image_data) 5 unmodified lines678910111221 unmodified lines343536373839405 unmodified linesfrom benchmark.metrics.image_reward import ImageRewardMetricfrom benchmark.metrics.sharpness import SharpnessMetricfrom benchmark.metrics.vqa import VQAMetricfrom benchmark.metrics.hps import HPSMetricdef create_metric(metric_type: str) -> Type[ARNIQAMetric | CLIPMetric | CLIPIQAMetric | ImageRewardMetric | SharpnessMetric | VQAMetric]:"""21 unmodified lines"image_reward": ImageRewardMetric,"sharpness": SharpnessMetric,"vqa": VQAMetric,"hps": HPSMetric,}if metric_type not in metric_map:5 unmodified lines678910111221 unmodified lines343536373839405 unmodified linesfrom benchmark.metrics.image_reward import ImageRewardMetricfrom benchmark.metrics.sharpness import SharpnessMetricfrom benchmark.metrics.vqa import VQAMetric#from benchmark.metrics.hps import HPSMetricdef create_metric(metric_type: str) -> Type[ARNIQAMetric | CLIPMetric | CLIPIQAMetric | ImageRewardMetric | SharpnessMetric | VQAMetric]:"""21 unmodified lines"image_reward": ImageRewardMetric,"sharpness": SharpnessMetric,"vqa": VQAMetric,#"hps": HPSMetric,}if metric_type not in metric_map:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177accelerate==1.7.0aiohappyeyeballs==2.6.1aiohttp==3.12.12aiosignal==1.3.2annotated-types==0.7.0antlr4-python3-runtime==4.9.3anyio==4.9.0args==0.1.0asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1733250440834/workattrs==25.3.0beautifulsoup4==4.13.4boto3==1.38.33botocore==1.38.33braceexpand==0.1.7Brotli @ file:///home/conda/feedstock_root/build_artifacts/brotli-split_1749229842835/workcertifi @ file:///home/conda/feedstock_root/build_artifacts/certifi_1746569525376/work/certificffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1725560558132/workcharset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1746214863626/workclick==8.1.8clint==0.5.1clip==0.2.0colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1733218098505/workcomm @ file:///home/conda/feedstock_root/build_artifacts/comm_1733502965406/workcontourpy==1.3.2cycler==0.12.1datasets==3.6.0debugpy @ file:///home/conda/feedstock_root/build_artifacts/debugpy_1744321241074/workdecorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1740384970518/workdiffusers==0.31.0dill==0.3.8distro==1.9.0einops==0.8.1eval_type_backport==0.2.2exceptiongroup @ file:///home/conda/feedstock_root/build_artifacts/exceptiongroup_1746947292760/workexecuting @ file:///home/conda/feedstock_root/build_artifacts/executing_1745502089858/workfairscale==0.4.13fal_client==0.7.0filelock==3.18.0fire==0.4.0fonttools==4.58.2frozenlist==1.7.0fsspec==2025.3.0ftfy==6.3.1gdown==5.2.0h11==0.16.0h2 @ file:///home/conda/feedstock_root/build_artifacts/h2_1738578511449/workhf-xet==1.1.3hpack @ file:///home/conda/feedstock_root/build_artifacts/hpack_1737618293087/workhpsv2==1.2.0httpcore==1.0.9httpx==0.28.1httpx-sse==0.4.0huggingface-hub==0.32.5hyperframe @ file:///home/conda/feedstock_root/build_artifacts/hyperframe_1737618333194/workidna @ file:///home/conda/feedstock_root/build_artifacts/idna_1733211830134/workimage-reward==1.5importlib_metadata==8.7.0iniconfig==2.1.0iopath==0.1.10ipykernel @ file:///home/conda/feedstock_root/build_artifacts/ipykernel_1719845459717/workipython @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_ipython_1748713870/workipython_pygments_lexers @ file:///home/conda/feedstock_root/build_artifacts/ipython_pygments_lexers_1737123620466/workjedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1733300866624/workJinja2==3.1.6jiter==0.10.0jmespath==1.0.1joblib==1.5.1jupyter_client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1733440914442/workjupyter_core @ file:///home/conda/feedstock_root/build_artifacts/jupyter_core_1748333051527/workkiwisolver==1.4.8lightning-utilities==0.14.3markdown-it-py==3.0.0MarkupSafe==3.0.2matplotlib==3.10.3matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1733416936468/workmdurl==0.1.2mpmath==1.3.0multidict==6.4.4multiprocess==0.70.16nest_asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1733325553580/worknetworkx==3.5numpy @ file:///home/conda/feedstock_root/build_artifacts/numpy_1749430504934/work/dist/numpy-2.3.0-cp312-cp312-linux_x86_64.whl#sha256=3c4437a0cbe50dbae872ad4cd8dc5316009165bce459c4ffe2c46cd30aba13d4nvidia-cublas-cu12==12.6.4.1nvidia-cuda-cupti-cu12==12.6.80nvidia-cuda-nvrtc-cu12==12.6.77nvidia-cuda-runtime-cu12==12.6.77nvidia-cudnn-cu12==9.5.1.17nvidia-cufft-cu12==11.3.0.4nvidia-cufile-cu12==1.11.1.6nvidia-curand-cu12==10.3.7.77nvidia-cusolver-cu12==11.7.1.2nvidia-cusparse-cu12==12.5.4.2nvidia-cusparselt-cu12==0.6.3nvidia-nccl-cu12==2.26.2nvidia-nvjitlink-cu12==12.6.85nvidia-nvtx-cu12==12.6.77omegaconf==2.3.0open_clip_torch==2.32.0openai==1.85.0opencv-python==4.11.0opencv-python-headless==4.11.0packaging==25.0pandas==2.3.0parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1733271261340/workpexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1733301927746/workpickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1733327343728/workpillow @ file:///home/conda/feedstock_root/build_artifacts/pillow_1746646208260/workpiq==0.8.0platformdirs @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_platformdirs_1746710438/workpluggy==1.6.0portalocker==3.1.1prompt_toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1744724089886/workpropcache==0.3.2protobuf==3.20.3psutil==7.0.0ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1733302279685/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl#sha256=92c32ff62b5fd8cf325bec5ab90d7be3d2a8ca8c8a3813ff487a8d2002630d1fpure_eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1733569405015/workpyarrow==20.0.0pycocoevalcap==1.2pycocotools==2.0.10pycparser @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_pycparser_1733195786/workpydantic==2.11.5pydantic_core==2.33.2Pygments==2.19.1pyparsing==3.2.3PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1733217236728/workpytest==7.2.0pytest-split==0.8.0python-dateutil==2.9.0.post0python-dotenv @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_python-dotenv_1742948348/workpytz==2025.2PyYAML==6.0.2pyzmq @ file:///home/conda/feedstock_root/build_artifacts/pyzmq_1743831245863/workregex==2024.11.6replicate==1.0.7requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1749498106507/workrich==14.0.0s3transfer==0.13.0safetensors==0.5.3scikit-learn==1.7.0scipy==1.15.3sentencepiece==0.2.0setuptools==80.9.0shellingham==1.5.4six==1.17.0sniffio==1.3.1soupsieve==2.7stack_data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1733569443808/worksympy==1.14.0t2v_metrics==1.2tabulate==0.9.0termcolor==3.1.0threadpoolctl==3.6.0tiktoken==0.9.0timm==0.6.13together==1.5.11tokenizers==0.15.2torch==2.7.1torchmetrics==1.7.2torchvision==0.22.1tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1748003300911/worktqdm @ file:///home/conda/feedstock_root/build_artifacts/tqdm_1735661334605/worktraitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1733367359838/worktransformers==4.36.1triton==3.3.1typer==0.15.4typing-inspection==0.4.1typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_typing_extensions_1748959427/worktzdata==2025.2urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1744323578849/workwcwidth==0.2.13webdataset==0.2.111wheel==0.45.1xxhash==3.5.0yarl==1.20.1zipp==3.23.0zstandard==0.23.0README.md+11-2
api/__init__.py+3
api/aws.pyAdded+73
benchmark/metrics/__init__.py+2-2
nils_installs.txtAdded+177