CatPtain commited on
Commit
fb296e1
·
verified ·
1 Parent(s): 1861c60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -14,7 +14,8 @@ CORS(app, origins=[
14
  "https://play.cybercity.top",
15
  "https://play.x-raremeta.com",
16
  "https://www.x-raremeta.com",
17
- "https://www.cybercity.top"])
 
18
 
19
  # 你的配置信息
20
  CLIENT_ID = "1243934778935"
@@ -50,42 +51,31 @@ def get_access_token(jwt_token):
50
  response = requests.post(url, json=data, headers=headers)
51
  return response.json()
52
 
 
 
53
  def get_token_from_flask():
54
  auth_header = request.headers.get('Authorization')
55
  if auth_header != VALIDATION_TOKEN:
56
  return jsonify({"error": "Invalid authorization token"}), 401
 
57
  try:
58
  with open(PRIVATE_KEY_FILE_PATH, "r") as f:
59
  private_key = f.read()
 
60
  jwt_token = generate_jwt(CLIENT_ID, private_key, KID)
61
  response = get_access_token(jwt_token)
 
62
  if "access_token" in response:
63
  return jsonify({
64
  "access_token": response["access_token"],
65
  "expires_in": response["expires_in"]
66
  })
67
  else:
68
- return jsonify({"error": "Failed to get access token"}), 500
69
  except Exception as e:
70
  return jsonify({"error": str(e)}), 500
71
 
72
- # --- Gradio 集成 ---
73
- import gradio as gr
74
-
75
- def get_token_for_gradio():
76
- # 调用 Flask 应用逻辑获取 token
77
- response, status_code = get_token_from_flask()
78
- if status_code == 200:
79
- return response.json
80
- else:
81
- return {"error": "Failed to get access token"}
82
-
83
- iface = gr.Interface(
84
- fn=get_token_for_gradio,
85
- inputs=None,
86
- outputs="json",
87
- title="OAuth Access Token Generator"
88
- )
89
-
90
  if __name__ == '__main__':
91
- iface.launch(server_name="0.0.0.0", server_port=5555)
 
14
  "https://play.cybercity.top",
15
  "https://play.x-raremeta.com",
16
  "https://www.x-raremeta.com",
17
+ "https://www.cybercity.top"
18
+ ])
19
 
20
  # 你的配置信息
21
  CLIENT_ID = "1243934778935"
 
51
  response = requests.post(url, json=data, headers=headers)
52
  return response.json()
53
 
54
+ # 添加路由
55
+ @app.route('/get_token', methods=['GET'])
56
  def get_token_from_flask():
57
  auth_header = request.headers.get('Authorization')
58
  if auth_header != VALIDATION_TOKEN:
59
  return jsonify({"error": "Invalid authorization token"}), 401
60
+
61
  try:
62
  with open(PRIVATE_KEY_FILE_PATH, "r") as f:
63
  private_key = f.read()
64
+
65
  jwt_token = generate_jwt(CLIENT_ID, private_key, KID)
66
  response = get_access_token(jwt_token)
67
+
68
  if "access_token" in response:
69
  return jsonify({
70
  "access_token": response["access_token"],
71
  "expires_in": response["expires_in"]
72
  })
73
  else:
74
+ return jsonify({"error": "Failed to get access token", "details": response}), 500
75
  except Exception as e:
76
  return jsonify({"error": str(e)}), 500
77
 
78
+ # 选择一种服务器运行方式:Flask Gradio
79
+ # 方式1: 仅Flask
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  if __name__ == '__main__':
81
+ app.run(host="0.0.0.0", port=5555)