Spaces:
Sleeping
Sleeping
Junhui Ji
commited on
Commit
·
99d5d45
1
Parent(s):
b1a6df1
delete client ip
Browse files- main.py +25 -25
- static/script.js +3 -8
main.py
CHANGED
@@ -205,37 +205,37 @@ async def analyze_feedback(request: AnalysisRequest):
|
|
205 |
@app.post("/api/optimize-design")
|
206 |
async def optimize_design(request: OptimizationRequest, client_ip: str = None):
|
207 |
try:
|
208 |
-
#
|
209 |
-
if client_ip is None or client_ip not in white_list:
|
210 |
print(f'user_ip {client_ip} not in whitelist')
|
211 |
raise HTTPException(
|
212 |
status_code=503,
|
213 |
detail="当前用户无生图权限,请点击'想使用自己的OpenAI API Key?'输入您的OpenAI API Key或联系@wangyue161添加白名单后重试。"
|
214 |
)
|
215 |
|
216 |
-
user_rate_limit = white_list[client_ip]
|
217 |
-
|
218 |
-
current_time = time.time()
|
219 |
-
|
220 |
-
# 检查是否需要重置计数器(超过24小时)
|
221 |
-
if current_time - optimize_design_timestamps[client_ip] > 3600*24:
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
# 如果是首次请求,记录时间戳
|
226 |
-
if optimize_design_requests[client_ip] == 0:
|
227 |
-
|
228 |
-
|
229 |
-
# 检查是否超过限制
|
230 |
-
print(f'user_ip {client_ip}, total requests in routine: {optimize_design_requests[client_ip]}, rate limit: {user_rate_limit}')
|
231 |
-
if optimize_design_requests[client_ip] >= user_rate_limit:
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
# 增加请求计数
|
238 |
-
optimize_design_requests[client_ip] += 1
|
239 |
|
240 |
# 提取设计类型
|
241 |
design_type = f"设计类型:{request.text.split()[0]}\n" if len(request.text.split()) > 1 else ""
|
|
|
205 |
@app.post("/api/optimize-design")
|
206 |
async def optimize_design(request: OptimizationRequest, client_ip: str = None):
|
207 |
try:
|
208 |
+
# 查看客户是否提供了openai_key,获取客户端IP(如果未提供,使用默认值)
|
209 |
+
if not request.openai_key or client_ip is None or client_ip not in white_list:
|
210 |
print(f'user_ip {client_ip} not in whitelist')
|
211 |
raise HTTPException(
|
212 |
status_code=503,
|
213 |
detail="当前用户无生图权限,请点击'想使用自己的OpenAI API Key?'输入您的OpenAI API Key或联系@wangyue161添加白名单后重试。"
|
214 |
)
|
215 |
|
216 |
+
# user_rate_limit = white_list[client_ip]
|
217 |
+
#
|
218 |
+
# current_time = time.time()
|
219 |
+
#
|
220 |
+
# # 检查是否需要重置计数器(超过24小时)
|
221 |
+
# if current_time - optimize_design_timestamps[client_ip] > 3600*24:
|
222 |
+
# optimize_design_requests[client_ip] = 0
|
223 |
+
# optimize_design_timestamps[client_ip] = current_time
|
224 |
+
#
|
225 |
+
# # 如果是首次请求,记录时间戳
|
226 |
+
# if optimize_design_requests[client_ip] == 0:
|
227 |
+
# optimize_design_timestamps[client_ip] = current_time
|
228 |
+
#
|
229 |
+
# # 检查是否超过限制
|
230 |
+
# print(f'user_ip {client_ip}, total requests in routine: {optimize_design_requests[client_ip]}, rate limit: {user_rate_limit}')
|
231 |
+
# if optimize_design_requests[client_ip] >= user_rate_limit:
|
232 |
+
# raise HTTPException(
|
233 |
+
# status_code=503,
|
234 |
+
# detail="用户当日改图接口访问已达上限,请24小时后重试"
|
235 |
+
# )
|
236 |
+
#
|
237 |
+
# # 增加请求计数
|
238 |
+
# optimize_design_requests[client_ip] += 1
|
239 |
|
240 |
# 提取设计类型
|
241 |
design_type = f"设计类型:{request.text.split()[0]}\n" if len(request.text.split()) > 1 else ""
|
static/script.js
CHANGED
@@ -301,7 +301,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
301 |
});
|
302 |
}
|
303 |
|
304 |
-
|
305 |
// 分析用户输入和图片的函数
|
306 |
async function analyzeUserInput(text, imageData) {
|
307 |
try {
|
@@ -707,8 +706,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
707 |
const response = await fetch(`${BASE_URL}api/optimize-design`, {
|
708 |
method: 'POST',
|
709 |
headers: {
|
710 |
-
'Content-Type': 'application/json'
|
711 |
-
'X-Forwarded-For': window.location.hostname
|
712 |
},
|
713 |
body: JSON.stringify({
|
714 |
text: uploadedText,
|
@@ -716,7 +714,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
716 |
suggestions: suggestions,
|
717 |
request_model_id: 'gpt-image-1',
|
718 |
openai_key: sessionStorage.getItem('userOpenaiKey') || '',
|
719 |
-
client_ip: window.location.hostname
|
720 |
})
|
721 |
});
|
722 |
|
@@ -781,16 +778,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
781 |
const response = await fetch(`${BASE_URL}api/optimize-design`, {
|
782 |
method: 'POST',
|
783 |
headers: {
|
784 |
-
'Content-Type': 'application/json'
|
785 |
-
'X-Forwarded-For': window.location.hostname
|
786 |
},
|
787 |
body: JSON.stringify({
|
788 |
text: uploadedText,
|
789 |
image_data: uploadedImage,
|
790 |
suggestions: suggestions,
|
791 |
request_model_id: 'dall-e-2',
|
792 |
-
openai_key: sessionStorage.getItem('userOpenaiKey') || ''
|
793 |
-
client_ip: window.location.hostname
|
794 |
})
|
795 |
});
|
796 |
if (response.status === 503) {
|
|
|
301 |
});
|
302 |
}
|
303 |
|
|
|
304 |
// 分析用户输入和图片的函数
|
305 |
async function analyzeUserInput(text, imageData) {
|
306 |
try {
|
|
|
706 |
const response = await fetch(`${BASE_URL}api/optimize-design`, {
|
707 |
method: 'POST',
|
708 |
headers: {
|
709 |
+
'Content-Type': 'application/json'
|
|
|
710 |
},
|
711 |
body: JSON.stringify({
|
712 |
text: uploadedText,
|
|
|
714 |
suggestions: suggestions,
|
715 |
request_model_id: 'gpt-image-1',
|
716 |
openai_key: sessionStorage.getItem('userOpenaiKey') || '',
|
|
|
717 |
})
|
718 |
});
|
719 |
|
|
|
778 |
const response = await fetch(`${BASE_URL}api/optimize-design`, {
|
779 |
method: 'POST',
|
780 |
headers: {
|
781 |
+
'Content-Type': 'application/json'
|
|
|
782 |
},
|
783 |
body: JSON.stringify({
|
784 |
text: uploadedText,
|
785 |
image_data: uploadedImage,
|
786 |
suggestions: suggestions,
|
787 |
request_model_id: 'dall-e-2',
|
788 |
+
openai_key: sessionStorage.getItem('userOpenaiKey') || ''
|
|
|
789 |
})
|
790 |
});
|
791 |
if (response.status === 503) {
|