{"id":20315815,"url":"https://github.com/ashakoen/replicate-image-gen-python","last_synced_at":"2025-03-04T09:12:53.460Z","repository":{"id":255271650,"uuid":"849075192","full_name":"ashakoen/replicate-image-gen-python","owner":"ashakoen","description":"A simple Python image generation API intended to be deployed to Google Cloud Run. The script uses the Replicate API to generate images using FLUX.1","archived":false,"fork":false,"pushed_at":"2024-08-29T21:48:19.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-14T18:26:16.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashakoen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-28T23:44:57.000Z","updated_at":"2024-08-29T21:48:23.000Z","dependencies_parsed_at":"2024-11-14T18:35:01.991Z","dependency_job_id":null,"html_url":"https://github.com/ashakoen/replicate-image-gen-python","commit_stats":null,"previous_names":["ashakoen/replicate-image-gen-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashakoen%2Freplicate-image-gen-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashakoen%2Freplicate-image-gen-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashakoen%2Freplicate-image-gen-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashakoen%2Freplicate-image-gen-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashakoen","download_url":"https://codeload.github.com/ashakoen/replicate-image-gen-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233895995,"owners_count":18747154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T18:22:05.646Z","updated_at":"2025-01-14T12:47:55.394Z","avatar_url":"https://github.com/ashakoen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Replicate Image Gen\n\nReplicate Image Gen is a Python application that leverages the Replicate API to generate images using the FLUX.1 models based on text prompts. It's the backend of a bigger app I'm building to interact with the Replicate APIs.\n\n## Features\n\n- Generates images from text prompts using FLUX.1 models and LoRAs.\n- Wide customization with environment variables for model parameters.\n- Secure API access with header-based authentication (`x-api-key`).\n- Designed for deployment on Google Cloud Run with Docker support.\n- Environment variable management via `.env` files for easy configuration.\n\n## Installation\n\n### Clone the Repository\nFirst, clone the repository to your local machine:\n\n```\ngit clone https://github.com/ashakoen/replicate-image-gen-python.git\ncd replicate-image-gen-python\n```\n\n### Python Environment\nEnsure you have Python 3.10 or later installed on your system.\n\n### Install Dependencies\nEither install with pip (assuming a virtual environment is set up):\n\n```\npip install -r requirements.txt\n ```\n\nOr if using Docker, you don't need to manually install dependencies; the Dockerfile will handle it.\n\n## Usage\n\n### Running the Docker Container\n\nBuild the Docker image:\n\n```\ndocker build -t flask-image-generator .\n```\n\nRun the Docker container with the `.env` file:\n```\ndocker run -p 8080:8080 --env-file .env flask-image-generator\n```\n\n### Interacting with the API\n\nAfter starting the container, you can interact with the API. The service provides an endpoint to generate images based on the user-provided text prompt.\n\n#### Endpoint: `/generate-images`\n\n- **Method:** POST\n- **Headers:**\n  - `Content-Type: application/json`\n  - `x-api-key: \u003cyour_header_api_key_here\u003e`\n- **Body:** JSON object containing the field:\n  - `prompt`: A string representing the text input for generating images.\n\nExample usage with `curl`:\n```\ncurl -X POST http://localhost:8080/generate-images \\\n-H \"x-api-key: your_header_api_key_here\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\"prompt\": \"A cute photo of a dog\"}'\n```\n\n### Docker Compose\n\nYou can use Docker Compose as well for managing the container:\n```\ndocker-compose up --build\n```\n## Configuration\n\nThe application uses a `.env` file to configure the parameters used by the Replicate API. See below for the complete list of configurable environment variables:\n```\n- REPLICATE_API_KEY: Your API key for Replicate.\n- MODEL: The model to use (e.g., \"dev\").\n- NUM_OUTPUTS: The number of output images (default: 1).\n- GUIDANCE_SCALE: The guidance scale for the generation process.\n- NUM_INFERENCE_STEPS: The number of inference steps.\n- OUTPUT_FORMAT: The format for the output image (e.g., \"png\").\n- OUTPUT_QUALITY: The quality of the output image (e.g., 100).\n- DISABLE_SAFETY_CHECKER: Disables the safety checker (boolean: true/false).\n- LORA_SCALE: Scale for LoRA fine-tuning (default: 1).\n- ASPECT_RATIO: Aspect ratio of output image (e.g., \"9:16\").\n- LORA: The LoRA model to apply during image generation.\n- X_API_KEY: The key required for accessing the API.\n```\n### Google Cloud Run Integration\n\nThis repository can be easily integrated with Google Cloud Run for continuous deployment:\n\n1. **Link Your GitHub Repository:** Use the Google Cloud Console to set up a continuous integration pipeline with your GitHub repository.\n\n2. **Environment Variables:** Ensure the required environment variables are set either in the Google Cloud Run console or by using Google Cloud's Secret Manager for secure storage.\n\n3. **GitHub Deployment:**\n   - Push your changes to GitHub.\n   - Google Cloud Run will automatically build and deploy your service.\n\n## The Story Behind Flask Image Generator\n\nThe Flask Image Generator was developed to simplify the process of generating high-quality images based on detailed text prompts. With the rise of AI models capable of creating images from textual descriptions, this project aimed to provide a simple, yet powerful, platform for testing and integrating such features into various applications.\n\nBy using the Replicate API, the project reduces the complexity of model management and leverages pre-trained models for quick deployment and testing. It’s designed to be easily customizable and ready to be integrated into cloud environments, making it ideal for prototyping and production use alike.\n\n## File Structure\n\n- app.py: The main Flask application for processing image generation requests.\n- requirements.txt: Python dependencies.\n- Dockerfile: Instructions for building the Docker image.\n- docker-compose.yml: Simplifies local container management.\n- .env: Environment variable configurations (not included in repository).\n- .dockerignore: Excludes unnecessary files from the Docker context.\n- README.md: This file, providing information about the project.\n\n## Dependencies\n\nThis project uses several Python libraries detailed in the `requirements.txt` file:\n\n- Flask: Micro web framework for routing and handling API requests.\n- Flask-CORS: Handles cross-origin requests.\n- Loguru: Logging library for structured logs.\n- Replicate: Python client for integrating with the Replicate API.\n- python-dotenv: Loads environment variables from a `.env` file.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to open an issue or submit a pull request with any improvements or bug fixes.\n\n## Contact\n\nFor any questions or suggestions, open a Github issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashakoen%2Freplicate-image-gen-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashakoen%2Freplicate-image-gen-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashakoen%2Freplicate-image-gen-python/lists"}