Upload app.py
Browse files
app.py
CHANGED
@@ -36,15 +36,15 @@ app.logger.setLevel(logging.INFO)
|
|
36 |
MODEL_MAPPING = {
|
37 |
"flux.1-schnell": {
|
38 |
"provider": "black-forest-labs",
|
39 |
-
"mapping": "black-forest-labs/FLUX.1-schnell"
|
40 |
},
|
41 |
-
"
|
42 |
-
"provider": "
|
43 |
-
"mapping": "
|
44 |
},
|
45 |
-
"
|
46 |
"provider": "stabilityai",
|
47 |
-
"mapping": "stabilityai/
|
48 |
},
|
49 |
"stable-diffusion-2-1": {
|
50 |
"provider": "stabilityai",
|
@@ -182,27 +182,29 @@ def handle_request():
|
|
182 |
else:
|
183 |
enhanced_prompt = translate_and_enhance_prompt(clean_prompt, random_token)
|
184 |
|
185 |
-
new_url =
|
186 |
new_request_body = {
|
|
|
187 |
"prompt": enhanced_prompt,
|
|
|
188 |
"image_size": image_size,
|
189 |
"batch_size": 1,
|
190 |
-
"
|
191 |
-
"
|
|
|
192 |
}
|
193 |
|
194 |
headers = {
|
195 |
-
'
|
196 |
-
'
|
197 |
-
'Authorization': f'Bearer {random_token}'
|
198 |
}
|
199 |
-
|
200 |
response = requests.post(new_url, headers=headers, json=new_request_body, timeout=60)
|
201 |
response.raise_for_status()
|
202 |
response_body = response.json()
|
203 |
-
|
204 |
-
if '
|
205 |
-
image_url = response_body['
|
206 |
else:
|
207 |
raise ValueError("Unexpected response structure from image generation API")
|
208 |
|
|
|
36 |
MODEL_MAPPING = {
|
37 |
"flux.1-schnell": {
|
38 |
"provider": "black-forest-labs",
|
39 |
+
"mapping": "Pro/black-forest-labs/FLUX.1-schnell"
|
40 |
},
|
41 |
+
"flux.1-dev": {
|
42 |
+
"provider": "black-forest-labs",
|
43 |
+
"mapping": "black-forest-labs/FLUX.1-dev"
|
44 |
},
|
45 |
+
"stable-diffusion-3-5-large": {
|
46 |
"provider": "stabilityai",
|
47 |
+
"mapping": "stabilityai/stable-diffusion-3-5-large"
|
48 |
},
|
49 |
"stable-diffusion-2-1": {
|
50 |
"provider": "stabilityai",
|
|
|
182 |
else:
|
183 |
enhanced_prompt = translate_and_enhance_prompt(clean_prompt, random_token)
|
184 |
|
185 |
+
new_url = 'https://api.siliconflow.cn/v1/images/generations'
|
186 |
new_request_body = {
|
187 |
+
"model": mapped_model, # 使用映射后的模型名称
|
188 |
"prompt": enhanced_prompt,
|
189 |
+
"negative_prompt": "", # 如果不需要负提示词,可以留空
|
190 |
"image_size": image_size,
|
191 |
"batch_size": 1,
|
192 |
+
"seed": random.randint(0, 4999999999), # 随机生成一个种子值
|
193 |
+
"num_inference_steps": 20,
|
194 |
+
"guidance_scale": 7.5
|
195 |
}
|
196 |
|
197 |
headers = {
|
198 |
+
'Authorization': f'Bearer {random_token}',
|
199 |
+
'Content-Type': 'application/json'
|
|
|
200 |
}
|
201 |
+
|
202 |
response = requests.post(new_url, headers=headers, json=new_request_body, timeout=60)
|
203 |
response.raise_for_status()
|
204 |
response_body = response.json()
|
205 |
+
|
206 |
+
if 'data' in response_body and response_body['data'] and 'url' in response_body['data'][0]:
|
207 |
+
image_url = response_body['data'][0]['url']
|
208 |
else:
|
209 |
raise ValueError("Unexpected response structure from image generation API")
|
210 |
|