smgc commited on
Commit
e1b2102
·
verified ·
1 Parent(s): 61edc08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -25
app.py CHANGED
@@ -6,22 +6,24 @@ import random
6
  import logging
7
  import sys
8
  import re
9
- from logging.handlers import RotatingFileHandler
10
 
11
  app = Flask(__name__)
12
 
13
  # 配置日志
14
  class RequestFormatter(logging.Formatter):
15
  def format(self, record):
16
- record.url = request.url
17
- record.remote_addr = request.remote_addr
18
- return super().format(record)
 
 
19
 
20
  formatter = RequestFormatter(
21
- '%(asctime)s - %(remote_addr)s - %(url)s - %(levelname)s - %(message)s'
22
  )
23
 
24
- handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=3)
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
- Welcome to the text-to-image API with siliconflow!
114
-
115
- Usage:
116
- 1. Send a POST request to /ai/v1/chat/completions
117
- 2. Include your prompt in the 'content' field of the last message
118
- 3. Optional parameters:
119
- -s <ratio>: Set image size ratio (e.g., -s 1:1, -s 16:9)
120
- -o: Use original prompt without enhancement
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
- Example:
123
- {
124
- "model": "flux",
125
- "messages": [
126
- {
127
- "role": "user",
128
- "content": "A beautiful landscape -s 16:9"
129
- }
130
- ]
131
- }
 
 
132
 
133
- For more details, please refer to the API documentation.
 
 
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 &lt;ratio&gt;</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