Update app.py
Browse files
app.py
CHANGED
@@ -6,22 +6,24 @@ import random
|
|
6 |
import logging
|
7 |
import sys
|
8 |
import re
|
9 |
-
from logging.handlers import
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
# 配置日志
|
14 |
class RequestFormatter(logging.Formatter):
|
15 |
def format(self, record):
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
formatter = RequestFormatter(
|
21 |
-
'%(asctime)s - %(remote_addr)s - %(url)s - %(
|
22 |
)
|
23 |
|
24 |
-
handler =
|
25 |
handler.setFormatter(formatter)
|
26 |
handler.setLevel(logging.INFO)
|
27 |
|
@@ -110,27 +112,48 @@ def extract_params_from_prompt(prompt):
|
|
110 |
@app.route('/')
|
111 |
def index():
|
112 |
usage = """
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
|
133 |
-
|
|
|
|
|
134 |
"""
|
135 |
return usage, 200
|
136 |
|
|
|
6 |
import logging
|
7 |
import sys
|
8 |
import re
|
9 |
+
from logging.handlers import TimedRotatingFileHandler
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
# 配置日志
|
14 |
class RequestFormatter(logging.Formatter):
|
15 |
def format(self, record):
|
16 |
+
if request.method == 'POST':
|
17 |
+
record.url = request.url
|
18 |
+
record.remote_addr = request.remote_addr
|
19 |
+
return super().format(record)
|
20 |
+
return None
|
21 |
|
22 |
formatter = RequestFormatter(
|
23 |
+
'%(asctime)s - %(remote_addr)s - %(url)s - %(message)s'
|
24 |
)
|
25 |
|
26 |
+
handler = TimedRotatingFileHandler('app.log', when="midnight", interval=1, backupCount=30)
|
27 |
handler.setFormatter(formatter)
|
28 |
handler.setLevel(logging.INFO)
|
29 |
|
|
|
112 |
@app.route('/')
|
113 |
def index():
|
114 |
usage = """
|
115 |
+
<html>
|
116 |
+
<head>
|
117 |
+
<title>Text-to-Image API with SiliconFlow</title>
|
118 |
+
<style>
|
119 |
+
body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; max-width: 800px; margin: 0 auto; }
|
120 |
+
h1 { color: #333; }
|
121 |
+
h2 { color: #666; }
|
122 |
+
pre { background-color: #f4f4f4; padding: 10px; border-radius: 5px; }
|
123 |
+
code { font-family: Consolas, monospace; }
|
124 |
+
</style>
|
125 |
+
</head>
|
126 |
+
<body>
|
127 |
+
<h1>Welcome to the Text-to-Image API with SiliconFlow!</h1>
|
128 |
+
|
129 |
+
<h2>Usage:</h2>
|
130 |
+
<ol>
|
131 |
+
<li>Send a POST request to <code>/ai/v1/chat/completions</code></li>
|
132 |
+
<li>Include your prompt in the 'content' field of the last message</li>
|
133 |
+
<li>Optional parameters:
|
134 |
+
<ul>
|
135 |
+
<li><code>-s <ratio></code>: Set image size ratio (e.g., -s 1:1, -s 16:9)</li>
|
136 |
+
<li><code>-o</code>: Use original prompt without enhancement</li>
|
137 |
+
</ul>
|
138 |
+
</li>
|
139 |
+
</ol>
|
140 |
|
141 |
+
<h2>Example Request:</h2>
|
142 |
+
<pre><code>
|
143 |
+
{
|
144 |
+
"model": "flux",
|
145 |
+
"messages": [
|
146 |
+
{
|
147 |
+
"role": "user",
|
148 |
+
"content": "A beautiful landscape -s 16:9"
|
149 |
+
}
|
150 |
+
]
|
151 |
+
}
|
152 |
+
</code></pre>
|
153 |
|
154 |
+
<p>For more details, please refer to the API documentation.</p>
|
155 |
+
</body>
|
156 |
+
</html>
|
157 |
"""
|
158 |
return usage, 200
|
159 |
|