This project implements an AI image generator API using the Diffusion Model 3. It allows users to generate images based on text prompts and negative prompts. The API is built with FastAPI and leverages Cloudinary for image storage and Pyngrok for public access during development.
To run this project, you will need:
transformers==4.28.0 safetensors==0.3.1 accelerate==0.27.2 diffusers==0.26.3 gradio==4.20.0 invisible-watermark==0.2.0 spaces==0.24.0 omegaconf==2.3.0 timm==0.9.10 fastapi==0.95.2 uvicorn==0.22.0 cloudinary==1.30.0 pyngrok==5.2.0 Pillow==9.5.0 nest_asyncio==1.5.6 torch==2.0.1+cu118 # Specify the appropriate CUDA version
You can install the necessary dependencies with:
pip install -r requirements.txt
git clone https://github.com/codex-ML/image-generator-api.git cd ai-image-generator-api
Configure your Cloudinary and Ngrok credentials. You can set them in your environment or directly in the code (not recommended for production).
cloudinary_config(
cloud_name="your_cloud_name",
api_key="your_api_key",
api_secret="your_api_secret"
)
Replace the values with your actual Cloudinary credentials.
python main.py
This will start the FastAPI server and provide a public URL via Ngrok.
To generate an image, send a POST request to the /generate endpoint with the following JSON body:
{
"prompt": "A beautiful sunset over a mountain range.",
"negative_prompt": "No people, no buildings."
}
curlcurl -X POST "http://localhost:8000/generate" -H "Content-Type: application/json" -d '{"prompt": "A beautiful sunset over a mountain range.", "negative_prompt": "No people, no buildings."}'
The API will return a JSON response containing the image URL, time taken for generation, and the prompts used:
{
"image_url": "https://your_cloudinary_url.png",
"time_taken": 2.34,
"prompt": "A beautiful sunset over a mountain range.",
"negative_prompt": "No people, no buildings."
}
prompt: The text prompt for image generation (string).negative_prompt: The text prompt to avoid certain features (string).image_url: URL of the generated image.time_taken: Time taken to generate the image (float).prompt: The prompt used.negative_prompt: The negative prompt used.Contributions are welcome! If you have suggestions or improvements, please fork the repository and create a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
9 commits
Python
100.0%
This project implements an AI image generator API using the Diffusion Model 3. It allows users to generate images based on text prompts and negative prompts. The API is built with FastAPI and leverages Cloudinary for image storage and Pyngrok for public access during development.
To run this project, you will need:
transformers==4.28.0 safetensors==0.3.1 accelerate==0.27.2 diffusers==0.26.3 gradio==4.20.0 invisible-watermark==0.2.0 spaces==0.24.0 omegaconf==2.3.0 timm==0.9.10 fastapi==0.95.2 uvicorn==0.22.0 cloudinary==1.30.0 pyngrok==5.2.0 Pillow==9.5.0 nest_asyncio==1.5.6 torch==2.0.1+cu118 # Specify the appropriate CUDA version
You can install the necessary dependencies with:
pip install -r requirements.txt
git clone https://github.com/codex-ML/image-generator-api.git cd ai-image-generator-api
Configure your Cloudinary and Ngrok credentials. You can set them in your environment or directly in the code (not recommended for production).
cloudinary_config(
cloud_name="your_cloud_name",
api_key="your_api_key",
api_secret="your_api_secret"
)
Replace the values with your actual Cloudinary credentials.
python main.py
This will start the FastAPI server and provide a public URL via Ngrok.
To generate an image, send a POST request to the /generate endpoint with the following JSON body:
{
"prompt": "A beautiful sunset over a mountain range.",
"negative_prompt": "No people, no buildings."
}
curlcurl -X POST "http://localhost:8000/generate" -H "Content-Type: application/json" -d '{"prompt": "A beautiful sunset over a mountain range.", "negative_prompt": "No people, no buildings."}'
The API will return a JSON response containing the image URL, time taken for generation, and the prompts used:
{
"image_url": "https://your_cloudinary_url.png",
"time_taken": 2.34,
"prompt": "A beautiful sunset over a mountain range.",
"negative_prompt": "No people, no buildings."
}
prompt: The text prompt for image generation (string).negative_prompt: The text prompt to avoid certain features (string).image_url: URL of the generated image.time_taken: Time taken to generate the image (float).prompt: The prompt used.negative_prompt: The negative prompt used.Contributions are welcome! If you have suggestions or improvements, please fork the repository and create a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
9 commits
Python
100.0%