Update app.py
Browse files
app.py
CHANGED
@@ -60,38 +60,6 @@ MODEL_MAPPING = {
|
|
60 |
}
|
61 |
}
|
62 |
|
63 |
-
SYSTEM_ASSISTANT = """作为 Stable Diffusion Prompt 提示词专家,您将从关键词中创建提示,通常来自 Danbooru 等数据库。
|
64 |
-
提示通常描述图像,使用常见词汇,按重要性排列,并用逗号分隔。避免使用"-"或".",但可以接受空格和自然语言。避免词汇重复。
|
65 |
-
|
66 |
-
为了强调关键词,请将其放在括号中以增加其权重。例如,"(flowers)"将'flowers'的权重增加1.1倍,而"(((flowers)))"将其增加1.331倍。使用"(flowers:1.5)"将'flowers'的权重增加1.5倍。只为重要的标签增加权重。
|
67 |
-
|
68 |
-
提示包括三个部分:**前缀**(质量标签+风格词+效果器)+ **主题**(图像的主要焦点)+ **场景**(背景、环境)。
|
69 |
-
|
70 |
-
* 前缀影响图像质量。像"masterpiece"、"best quality"、"4k"这样的标签可以提高图像的细节。像"illustration"、"lensflare"这样的风格词定义图像的风格。像"bestlighting"、"lensflare"、"depthoffield"这样的效果器会影响光照和深度。
|
71 |
-
|
72 |
-
* 主题是图像的主要焦点,如角色或场景。对主题进行详细描述可以确保图像丰富而详细。增加主题的权重以增强其清晰度。对于角色,描述面部、头发、身体、服装、姿势等特征。
|
73 |
-
|
74 |
-
* 场景描述环境。没有场景,图像的背景是平淡的,主题显得过大。某些主题本身包含场景(例如建筑物、风景)。像"花草草地"、"阳光"、"河流"这样的环境词可以丰富场景。你的任务是设计图像生成的提示。请按照以下步骤进行操作:
|
75 |
-
|
76 |
-
1. 我会发送给您一个图像场景。需要你生成详细的图像描述
|
77 |
-
2. 图像描述必须是英文,输出为Positive Prompt。
|
78 |
-
|
79 |
-
示例:
|
80 |
-
|
81 |
-
我发送:二战时期的护士。
|
82 |
-
您回复只回复:
|
83 |
-
A WWII-era nurse in a German uniform, holding a wine bottle and stethoscope, sitting at a table in white attire, with a table in the background, masterpiece, best quality, 4k, illustration style, best lighting, depth of field, detailed character, detailed environment.
|
84 |
-
"""
|
85 |
-
|
86 |
-
RATIO_MAP = {
|
87 |
-
"1:1": "1024x1024",
|
88 |
-
"1:2": "1024x2048",
|
89 |
-
"3:2": "1536x1024",
|
90 |
-
"4:3": "1536x2048",
|
91 |
-
"16:9": "2048x1152",
|
92 |
-
"9:16": "1152x2048"
|
93 |
-
}
|
94 |
-
|
95 |
# 模拟身份验证函数
|
96 |
def getAuthCookie(req):
|
97 |
auth_cookie = req.headers.get('Authorization')
|
@@ -99,6 +67,54 @@ def getAuthCookie(req):
|
|
99 |
return auth_cookie
|
100 |
return None
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
@app.route('/ai/v1/models', methods=['GET'])
|
103 |
def get_models():
|
104 |
try:
|
@@ -258,6 +274,38 @@ def translate_and_enhance_prompt(prompt, auth_token):
|
|
258 |
result = response.json()
|
259 |
return result['choices'][0]['message']['content']
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
def stream_response(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint, use_original):
|
262 |
return Response(stream_with_context(generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint, use_original)), content_type='text/event-stream')
|
263 |
|
|
|
60 |
}
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
# 模拟身份验证函数
|
64 |
def getAuthCookie(req):
|
65 |
auth_cookie = req.headers.get('Authorization')
|
|
|
67 |
return auth_cookie
|
68 |
return None
|
69 |
|
70 |
+
@app.route('/')
|
71 |
+
def index():
|
72 |
+
usage = """
|
73 |
+
<html>
|
74 |
+
<head>
|
75 |
+
<title>Text-to-Image API with SiliconFlow</title>
|
76 |
+
<style>
|
77 |
+
body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; max-width: 800px; margin: 0 auto; }
|
78 |
+
h1 { color: #333; }
|
79 |
+
h2 { color: #666; }
|
80 |
+
pre { background-color: #f4f4f4; padding: 10px; border-radius: 5px; }
|
81 |
+
code { font-family: Consolas, monospace; }
|
82 |
+
</style>
|
83 |
+
</head>
|
84 |
+
<body>
|
85 |
+
<h1>Welcome to the Text-to-Image API with SiliconFlow!</h1>
|
86 |
+
|
87 |
+
<h2>Usage:</h2>
|
88 |
+
<ol>
|
89 |
+
<li>Send a POST request to <code>/ai/v1/chat/completions</code></li>
|
90 |
+
<li>Include your prompt in the 'content' field of the last message</li>
|
91 |
+
<li>Optional parameters:
|
92 |
+
<ul>
|
93 |
+
<li><code>-s <ratio></code>: Set image size ratio (e.g., -s 1:1, -s 16:9)</li>
|
94 |
+
<li><code>-o</code>: Use original prompt without enhancement</li>
|
95 |
+
</ul>
|
96 |
+
</li>
|
97 |
+
</ol>
|
98 |
+
|
99 |
+
<h2>Example Request:</h2>
|
100 |
+
<pre><code>
|
101 |
+
{
|
102 |
+
"model": "flux",
|
103 |
+
"messages": [
|
104 |
+
{
|
105 |
+
"role": "user",
|
106 |
+
"content": "A beautiful landscape -s 16:9"
|
107 |
+
}
|
108 |
+
]
|
109 |
+
}
|
110 |
+
</code></pre>
|
111 |
+
|
112 |
+
<p>For more details, please refer to the API documentation.</p>
|
113 |
+
</body>
|
114 |
+
</html>
|
115 |
+
"""
|
116 |
+
return usage, 200
|
117 |
+
|
118 |
@app.route('/ai/v1/models', methods=['GET'])
|
119 |
def get_models():
|
120 |
try:
|
|
|
274 |
result = response.json()
|
275 |
return result['choices'][0]['message']['content']
|
276 |
|
277 |
+
SYSTEM_ASSISTANT = """作为 Stable Diffusion Prompt 提示词专家,您将从关键词中创建提示,通常来自 Danbooru 等数据库。
|
278 |
+
提示通常描述图像,使用常见词汇,按重要性排列,并用逗号分隔。避免使用"-"或".",但可以接受空格和自然语言。避免词汇重复。
|
279 |
+
|
280 |
+
为了强调关键词,请将其放在括号中以增加其权重。例如,"(flowers)"将'flowers'的权重增加1.1倍,而"(((flowers)))"将其增加1.331倍。使用"(flowers:1.5)"将'flowers'的权重增加1.5倍。只为重要的标签增加权重。
|
281 |
+
|
282 |
+
提示包括三个部分:**前缀**(质量标签+风格词+效果器)+ **主题**(图像的主要焦点)+ **场景**(背景、环境)。
|
283 |
+
|
284 |
+
* 前缀影响图像质量。像"masterpiece"、"best quality"、"4k"这样的标签可以提高图像的细节。像"illustration"、"lensflare"这���的风格词定义图像的风格。像"bestlighting"、"lensflare"、"depthoffield"这样的效果器会影响光照和深度。
|
285 |
+
|
286 |
+
* 主题是图像的主要焦点,如角色或场景。对主题进行详细描述可以确保图像丰富而详细。增加主题的权重以增强其清晰度。对于角色,描述面部、头发、身体、服装、姿势等特征。
|
287 |
+
|
288 |
+
* 场景描述环境。没有场景,图像的背景是平淡的,主题显得过大。某些主题本身包含场景(例如建筑物、风景)。像"花草草地"、"阳光"、"河流"这样的环境词可以丰富场景。你的任务是设计图像生成的提示。请按照以下步骤进行操作:
|
289 |
+
|
290 |
+
1. 我会发送给您一个图像场景。需要你生成详细的图像描述
|
291 |
+
2. 图像描述必须是英文,输出为Positive Prompt。
|
292 |
+
|
293 |
+
示例:
|
294 |
+
|
295 |
+
我发送:二战时期的护士。
|
296 |
+
您回复只回复:
|
297 |
+
A WWII-era nurse in a German uniform, holding a wine bottle and stethoscope, sitting at a table in white attire, with a table in the background, masterpiece, best quality, 4k, illustration style, best lighting, depth of field, detailed character, detailed environment.
|
298 |
+
"""
|
299 |
+
|
300 |
+
RATIO_MAP = {
|
301 |
+
"1:1": "1024x1024",
|
302 |
+
"1:2": "1024x2048",
|
303 |
+
"3:2": "1536x1024",
|
304 |
+
"4:3": "1536x2048",
|
305 |
+
"16:9": "2048x1152",
|
306 |
+
"9:16": "1152x2048"
|
307 |
+
}
|
308 |
+
|
309 |
def stream_response(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint, use_original):
|
310 |
return Response(stream_with_context(generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint, use_original)), content_type='text/event-stream')
|
311 |
|