bobocup commited on
Commit
5a3c4df
·
verified ·
1 Parent(s): 8909fcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -1,32 +1,29 @@
1
  import gradio as gr
2
- from fastapi import FastAPI
3
  import requests
4
 
5
- app = FastAPI()
6
-
7
- @app.get("/")
8
- def root():
9
- try:
10
- response = requests.get("http://beibeioo.top")
11
- return response.content
12
- except Exception as e:
13
- return {"error": str(e)}
14
-
15
- @app.get("/api/{path:path}")
16
- def api_proxy(path: str):
17
  try:
18
- response = requests.get(f"http://beibeioo.top/{path}")
19
- return response.content
 
 
 
 
 
 
 
 
20
  except Exception as e:
21
- return {"error": str(e)}
22
 
23
- # 创建一个简单的 Gradio 界面
24
- interface = gr.Interface(
25
- fn=lambda x: x,
26
- inputs=gr.Textbox(visible=False),
27
- outputs=gr.Textbox(visible=False),
28
- title="API Proxy"
 
29
  )
30
 
31
- # 挂载应用
32
- app = gr.mount_gradio_app(app, interface, path="/ui")
 
1
  import gradio as gr
 
2
  import requests
3
 
4
+ def proxy_request(path=""):
 
 
 
 
 
 
 
 
 
 
 
5
  try:
6
+ if path.startswith("/api/"):
7
+ # 如果路径以 /api/ 开头,去掉 /api/ 后转发
8
+ actual_path = path[5:] # 跳过 "/api/"
9
+ url = f"http://beibeioo.top/{actual_path}"
10
+ else:
11
+ # 否则直接访问根路径
12
+ url = "http://beibeioo.top"
13
+
14
+ response = requests.get(url)
15
+ return response.text
16
  except Exception as e:
17
+ return f"Error: {str(e)}"
18
 
19
+ # 创建 Gradio 接口
20
+ demo = gr.Interface(
21
+ fn=proxy_request,
22
+ inputs=gr.Textbox(label="Path (leave empty for root, or use /api/v1 for API)"),
23
+ outputs=gr.Textbox(),
24
+ title="API Proxy",
25
+ description="Access beibeioo.top through this proxy"
26
  )
27
 
28
+ if __name__ == "__main__":
29
+ demo.launch()