bobocup commited on
Commit
2280bd6
·
verified ·
1 Parent(s): f3f19b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ def proxy_request(path=""):
5
+ try:
6
+ # 构建目标 URL
7
+ target_url = f"http://beibeioo.top/{path}"
8
+
9
+ # 发送请求
10
+ response = requests.get(target_url)
11
+
12
+ # 返回响应内容
13
+ return response.json()
14
+ except Exception as e:
15
+ return {"error": str(e)}
16
+
17
+ # 创建 Gradio 接口
18
+ app = gr.Interface(
19
+ fn=proxy_request,
20
+ inputs=gr.Textbox(label="Path"),
21
+ outputs=gr.JSON(),
22
+ title="API Proxy"
23
+ )
24
+
25
+ # 添加自定义路由处理
26
+ @app.queue()
27
+ def proxy_all(request: gr.Request):
28
+ path = request.path
29
+ if path.startswith("/"):
30
+ path = path[1:]
31
+ return proxy_request(path)
32
+
33
+ if __name__ == "__main__":
34
+ app.launch()