Spaces:
Paused
Paused
Fix: Refactor image handling and improve table styling
Browse filesThis commit refactors the `handle_image_response` method in `MessageProcessor` to be a static method and uses class name to call it. This improves code clarity and maintainability.
Additionally, this commit enhances the styling of the available tokens table in `index.html` and `style.css` for better readability and visual appeal. Changes include adjusting table width, padding, background colors, and text alignment.
- src/core/message_processor.py +3 -2
- static/style.css +10 -4
- templates/index.html +1 -1
src/core/message_processor.py
CHANGED
|
@@ -84,6 +84,7 @@ class MessageProcessor:
|
|
| 84 |
|
| 85 |
return result
|
| 86 |
|
|
|
|
| 87 |
def handle_image_response(image_url):
|
| 88 |
max_retries = 2
|
| 89 |
retry_count = 0
|
|
@@ -190,7 +191,7 @@ class MessageProcessor:
|
|
| 190 |
full_response += result["token"]
|
| 191 |
if result["imageUrl"]:
|
| 192 |
CONFIG["IS_IMG_GEN2"] = True
|
| 193 |
-
return handle_image_response(result["imageUrl"])
|
| 194 |
|
| 195 |
except json.JSONDecodeError:
|
| 196 |
continue
|
|
@@ -231,7 +232,7 @@ class MessageProcessor:
|
|
| 231 |
yield f"data: {json.dumps(MessageProcessor.create_chat_response(result['token'], model, True))}\n\n"
|
| 232 |
if result["imageUrl"]:
|
| 233 |
CONFIG["IS_IMG_GEN2"] = True
|
| 234 |
-
image_data = handle_image_response(result["imageUrl"])
|
| 235 |
yield f"data: {json.dumps(MessageProcessor.create_chat_response(image_data, model, True))}\n\n"
|
| 236 |
|
| 237 |
except json.JSONDecodeError:
|
|
|
|
| 84 |
|
| 85 |
return result
|
| 86 |
|
| 87 |
+
@staticmethod # 将方法改为静态方法
|
| 88 |
def handle_image_response(image_url):
|
| 89 |
max_retries = 2
|
| 90 |
retry_count = 0
|
|
|
|
| 191 |
full_response += result["token"]
|
| 192 |
if result["imageUrl"]:
|
| 193 |
CONFIG["IS_IMG_GEN2"] = True
|
| 194 |
+
return MessageProcessor.handle_image_response(result["imageUrl"]) # 使用类名调用静态方法
|
| 195 |
|
| 196 |
except json.JSONDecodeError:
|
| 197 |
continue
|
|
|
|
| 232 |
yield f"data: {json.dumps(MessageProcessor.create_chat_response(result['token'], model, True))}\n\n"
|
| 233 |
if result["imageUrl"]:
|
| 234 |
CONFIG["IS_IMG_GEN2"] = True
|
| 235 |
+
image_data = MessageProcessor.handle_image_response(result["imageUrl"]) # 使用类名调用静态方法
|
| 236 |
yield f"data: {json.dumps(MessageProcessor.create_chat_response(image_data, model, True))}\n\n"
|
| 237 |
|
| 238 |
except json.JSONDecodeError:
|
static/style.css
CHANGED
|
@@ -66,21 +66,23 @@ h1 {
|
|
| 66 |
|
| 67 |
/* 表格样式 */
|
| 68 |
#available-tokens-table {
|
| 69 |
-
width:
|
| 70 |
border-collapse: collapse; /* 合并边框 */
|
| 71 |
margin-top: 10px;
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
#available-tokens-table th,
|
| 75 |
#available-tokens-table td {
|
| 76 |
border: 1px solid #ddd; /* 添加边框 */
|
| 77 |
-
padding: 8px; /* 增加内边距 */
|
| 78 |
text-align: left; /* 左对齐文本 */
|
| 79 |
}
|
| 80 |
|
| 81 |
#available-tokens-table th {
|
| 82 |
-
background-color: #
|
| 83 |
font-weight: bold;
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
#available-tokens-table tbody tr:nth-child(even) {
|
|
@@ -88,5 +90,9 @@ h1 {
|
|
| 88 |
}
|
| 89 |
|
| 90 |
#available-tokens-table tbody tr:hover {
|
| 91 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
|
|
|
| 66 |
|
| 67 |
/* 表格样式 */
|
| 68 |
#available-tokens-table {
|
| 69 |
+
width: auto; /* 调整宽度为内容自适应 */
|
| 70 |
border-collapse: collapse; /* 合并边框 */
|
| 71 |
margin-top: 10px;
|
| 72 |
+
margin-bottom: 10px; /* 增加底部外边距 */
|
| 73 |
}
|
| 74 |
|
| 75 |
#available-tokens-table th,
|
| 76 |
#available-tokens-table td {
|
| 77 |
border: 1px solid #ddd; /* 添加边框 */
|
| 78 |
+
padding: 8px 12px; /* 增加内边距,左右稍大 */
|
| 79 |
text-align: left; /* 左对齐文本 */
|
| 80 |
}
|
| 81 |
|
| 82 |
#available-tokens-table th {
|
| 83 |
+
background-color: #e9e9e9; /* 表头背景色 */
|
| 84 |
font-weight: bold;
|
| 85 |
+
color: #555; /* 表头文字颜色 */
|
| 86 |
}
|
| 87 |
|
| 88 |
#available-tokens-table tbody tr:nth-child(even) {
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
#available-tokens-table tbody tr:hover {
|
| 93 |
+
background-color: #e0e0e0; /* 鼠标悬停背景色 */
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
#available-tokens-table td:last-child {
|
| 97 |
+
text-align: center; /* 可用数量列居中对齐 */
|
| 98 |
}
|
templates/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Grok API System Status</title>
|
| 7 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='style.css', v='1.
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container">
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Grok API System Status</title>
|
| 7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css', v='1.2') }}"> {# 更新版本参数防止缓存 #}
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="container">
|