Skip to content

Commit 0e6169b

Browse files
author
AI Assistant
committed
Initial commit: AI Image Generator project
0 parents  commit 0e6169b

8 files changed

+661
-0
lines changed

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# 配置文件
7+
config.py
8+
9+
# 输出目录
10+
output/
11+
12+
# 日志文件
13+
*.log
14+
15+
# 虚拟环境
16+
venv/
17+
.env/
18+
19+
# IDE配置
20+
.vscode/
21+
.idea/

README.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# AI Image Generator
2+
3+
基于阿里云灵积模型的批量图片生成工具
4+
5+
[English](README_EN.md) | 简体中文
6+
7+
## 功能特点
8+
9+
- 支持批量生成AI图片
10+
- 自定义存储路径和文件夹结构
11+
- 自动保存生成提示词
12+
- 断点续传功能
13+
- 智能请求限制处理
14+
- 详细的错误日志记录
15+
16+
## 环境要求
17+
18+
- Python 3.7+
19+
- aiohttp
20+
- Pillow
21+
- 阿里云灵积API密钥(注册即送500万tokens免费额度)
22+
23+
## 安装
24+
25+
1. 克隆项目到本地:
26+
27+
```bash
28+
git clone https://github.com/yourusername/ai-image-generator.git
29+
cd ai-image-generator
30+
```
31+
32+
2. 安装依赖:
33+
34+
```bash
35+
pip install -r requirements.txt
36+
```
37+
38+
## 配置
39+
40+
1. 复制配置文件模板:
41+
42+
```bash
43+
cp config.example.py config.py
44+
```
45+
46+
2. 在config.py中设置你的API密钥和其他配置:
47+
48+
```python
49+
API_KEY = "your-api-key-here" # 在阿里云百炼平台获取API密钥:https://bailian.console.aliyun.com
50+
API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis"
51+
52+
# 输出配置
53+
OUTPUT_DIR = "output" # 输出目录
54+
IMAGE_FORMAT = "jpg" # 图片格式
55+
```
56+
57+
## 使用方法
58+
59+
1. 准备提示词文件
60+
61+
`prompts.txt`中每行写入一个图片生成提示词:
62+
63+
```text
64+
一个苹果被切开后,果肉内部长出一朵鲜花
65+
一个风扇旋转时,风向扇叶内部吹去
66+
...
67+
```
68+
69+
2. 运行程序
70+
71+
```bash
72+
python generate_images.py
73+
```
74+
75+
程序会自动:
76+
- 创建输出目录
77+
- 读取提示词文件
78+
- 批量生成图片
79+
- 保存图片和提示词
80+
- 记录错误日志
81+
82+
## 输出结构
83+
84+
```
85+
output/
86+
├── 1/
87+
│ ├── image.jpg
88+
│ └── info.txt
89+
├── 2/
90+
│ ├── image.jpg
91+
│ └── info.txt
92+
└── ...
93+
```
94+
95+
## 高级配置
96+
97+
`config.py`中可以自定义更多参数:
98+
99+
```python
100+
# 批处理配置
101+
BATCH_SIZE = 10 # 每批处理数量
102+
BATCH_DELAY = 60 # 批次间延迟(秒)
103+
REQUEST_DELAY = 15 # 请求间延迟(秒)
104+
105+
# 重试配置
106+
MAX_RETRIES = 3 # 最大重试次数
107+
RETRY_DELAY = 5 # 重试延迟(秒)
108+
109+
# 图片配置
110+
IMAGE_SIZE = "1024*1024" # 图片尺寸
111+
IMAGE_COUNT = 1 # 每个提示词生成图片数
112+
```
113+
114+
## 错误处理
115+
116+
- 程序会自动处理API限流
117+
- 失败的生成会记录到error.log
118+
- 支持断点续传,可以从上次中断处继续
119+
120+
## 开发计划
121+
122+
- [ ] 支持更多图片格式
123+
- [ ] 添加Web界面
124+
- [ ] 支持更多AI模型
125+
- [ ] 优化并发处理
126+
127+
## 贡献指南
128+
129+
欢迎提交Issue和Pull Request!
130+
131+
## 许可证
132+
133+
MIT License
134+
135+
## 致谢
136+
137+
- [阿里云灵积平台](https://bailian.console.aliyun.com) - 注册即送500万tokens免费额度
138+
- [Python aiohttp](https://docs.aiohttp.org)
139+
- [Pillow](https://python-pillow.org)

README_EN.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# AI Image Generator
2+
3+
A batch image generation tool based on Alibaba Cloud Tongyi Model
4+
5+
English | [简体中文](README.md)
6+
7+
## Features
8+
9+
- Batch AI image generation
10+
- Customizable storage paths and folder structures
11+
- Automatic prompt text saving
12+
- Resume from breakpoint
13+
- Smart request rate limiting
14+
- Detailed error logging
15+
16+
## Requirements
17+
18+
- Python 3.7+
19+
- aiohttp
20+
- Pillow
21+
- Alibaba Cloud Tongyi API Key
22+
23+
## Installation
24+
25+
1. Clone the repository:
26+
27+
```bash
28+
git clone https://github.com/yourusername/ai-image-generator.git
29+
cd ai-image-generator
30+
```
31+
32+
2. Install dependencies:
33+
34+
```bash
35+
pip install -r requirements.txt
36+
```
37+
38+
## Configuration
39+
40+
1. Copy the configuration template:
41+
42+
```bash
43+
cp config.example.py config.py
44+
```
45+
46+
2. Set your API key and other configurations in config.py:
47+
48+
```python
49+
API_KEY = "your-api-key-here"
50+
API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis"
51+
52+
# Output settings
53+
OUTPUT_DIR = "output" # Output directory
54+
IMAGE_FORMAT = "jpg" # Image format
55+
```
56+
57+
## Usage
58+
59+
1. Prepare the prompts file
60+
61+
Add one prompt per line in `prompts.txt`:
62+
63+
```text
64+
An apple cut open with a flower growing inside
65+
A fan spinning with wind blowing inward
66+
...
67+
```
68+
69+
2. Run the program
70+
71+
```bash
72+
python generate_images.py
73+
```
74+
75+
The program will automatically:
76+
- Create output directory
77+
- Read prompts file
78+
- Generate images in batch
79+
- Save images and prompts
80+
- Log errors
81+
82+
## Output Structure
83+
84+
```
85+
output/
86+
├── 1/
87+
│ ├── image.jpg
88+
│ └── info.txt
89+
├── 2/
90+
│ ├── image.jpg
91+
│ └── info.txt
92+
└── ...
93+
```
94+
95+
## Advanced Configuration
96+
97+
Customize more parameters in `config.py`:
98+
99+
```python
100+
# Batch processing settings
101+
BATCH_SIZE = 10 # Number of items per batch
102+
BATCH_DELAY = 60 # Delay between batches (seconds)
103+
REQUEST_DELAY = 15 # Delay between requests (seconds)
104+
105+
# Retry settings
106+
MAX_RETRIES = 3 # Maximum retry attempts
107+
RETRY_DELAY = 5 # Delay between retries (seconds)
108+
109+
# Image settings
110+
IMAGE_SIZE = "1024*1024" # Image dimensions
111+
IMAGE_COUNT = 1 # Images per prompt
112+
```
113+
114+
## Error Handling
115+
116+
- Automatic API rate limit handling
117+
- Failed generations are logged to error.log
118+
- Supports resuming from last successful generation
119+
120+
## Roadmap
121+
122+
- [ ] Support for more image formats
123+
- [ ] Add Web interface
124+
- [ ] Support for more AI models
125+
- [ ] Optimize concurrent processing
126+
127+
## Contributing
128+
129+
Issues and Pull Requests are welcome!
130+
131+
## License
132+
133+
MIT License
134+
135+
## Acknowledgments
136+
137+
- [Alibaba Cloud Tongyi Platform](https://dashscope.aliyun.com)
138+
- [Python aiohttp](https://docs.aiohttp.org)
139+
- [Pillow](https://python-pillow.org)

config.example.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# API配置
4+
API_KEY = "your-api-key-here" # 在阿里云百炼平台获取API密钥:https://bailian.console.aliyun.com
5+
API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis"
6+
7+
# 模型配置
8+
MODEL = "wanx2.1-t2i-turbo" # 使用的模型名称
9+
10+
# 输出配置
11+
OUTPUT_DIR = "ai" # 输出目录
12+
IMAGE_FORMAT = "jpg" # 图片格式
13+
IMAGE_SIZE = "1024*1024" # 图片尺寸
14+
IMAGE_COUNT = 1 # 每个提示词生成的图片数量
15+
16+
# 批处理配置
17+
BATCH_SIZE = 10 # 每批处理的提示词数量
18+
BATCH_DELAY = 60 # 批次间延迟(秒)
19+
REQUEST_DELAY = 15 # 请求间延迟(秒)
20+
21+
# 重试配置
22+
MAX_RETRIES = 3 # 最大重试次数
23+
RETRY_DELAY = 5 # 重试延迟(秒)
24+
25+
# 日志配置
26+
ERROR_LOG = "error.log" # 错误日志文件
27+
PROMPTS_FILE = "prompts.txt" # 提示词文件

0 commit comments

Comments
 (0)