CatPtain commited on
Commit
cfffea2
·
verified ·
1 Parent(s): a4049b9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,13 +1,23 @@
1
  import gradio as gr
2
  from openbb_platform.openbb import sdk
 
3
 
4
- def query(symbol: str):
 
 
 
 
 
5
  try:
6
- # 示例:获取股票价格,实际接口请根据 OpenBB SDK 文档调整
7
  result = sdk.stocks.price(symbol)
8
  return str(result)
9
  except Exception as e:
10
  return f"Error: {e}"
11
 
12
- iface = gr.Interface(fn=query, inputs="text", outputs="text", title="OpenBB Query")
 
 
 
 
 
13
  iface.launch()
 
1
  import gradio as gr
2
  from openbb_platform.openbb import sdk
3
+ import os
4
 
5
+ API_KEY = os.environ.get("OPENBB_API_KEY", "your_secret_key") # 优先读取环境变量
6
+
7
+ def query(symbol: str, request: gr.Request):
8
+ # 校验密钥
9
+ if request.headers.get("x-api-key") != API_KEY:
10
+ return "Unauthorized: Invalid API Key"
11
  try:
 
12
  result = sdk.stocks.price(symbol)
13
  return str(result)
14
  except Exception as e:
15
  return f"Error: {e}"
16
 
17
+ iface = gr.Interface(
18
+ fn=query,
19
+ inputs="text",
20
+ outputs="text",
21
+ title="OpenBB Query"
22
+ )
23
  iface.launch()