Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,88 @@
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
import threading
|
|
|
4 |
import gradio as gr
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
subprocess.run(
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
)
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
def run_pufferpanel():
|
19 |
-
subprocess.run("pufferpanel run", shell=True)
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
def launch_info():
|
25 |
-
return """
|
26 |
-
## π PufferPanel v3.0.0-rc.14
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
"""
|
35 |
|
36 |
-
with gr.Blocks(
|
37 |
-
gr.Markdown(
|
38 |
-
gr.HTML(
|
39 |
-
<iframe src="http://localhost:8080"
|
40 |
-
style="width:100%; height:800px; border:none;">
|
41 |
-
</iframe>
|
42 |
-
""")
|
43 |
|
44 |
-
|
45 |
-
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
import threading
|
4 |
+
import requests
|
5 |
import gradio as gr
|
6 |
+
from fastapi import FastAPI, Request
|
7 |
+
from fastapi.responses import Response
|
8 |
+
import uvicorn
|
9 |
|
10 |
+
# ==========================
|
11 |
+
# CONFIG
|
12 |
+
# ==========================
|
13 |
+
PUFFER_URL = "http://127.0.0.1:8080" # Internal PufferPanel address
|
14 |
+
PUFFER_USER = "admin"
|
15 |
+
PUFFER_PASS = "admin123"
|
16 |
+
|
17 |
+
|
18 |
+
# ==========================
|
19 |
+
# Start PufferPanel
|
20 |
+
# ==========================
|
21 |
+
def start_pufferpanel():
|
22 |
+
# Make sure pufferpanel binary exists
|
23 |
+
if not os.path.exists("pufferpanel"):
|
24 |
+
print("Downloading and building PufferPanel...")
|
25 |
subprocess.run(
|
26 |
+
[
|
27 |
+
"wget",
|
28 |
+
"https://github.com/pufferpanel/pufferpanel/releases/download/v3.0.0-rc.14/pufferpanel_3.0.0-rc.14_linux_amd64.tar.gz",
|
29 |
+
"-O",
|
30 |
+
"pufferpanel.tar.gz",
|
31 |
+
],
|
32 |
+
check=True,
|
33 |
)
|
34 |
+
subprocess.run(["tar", "xvzf", "pufferpanel.tar.gz"], check=True)
|
35 |
+
|
36 |
+
# Run pufferpanel
|
37 |
+
subprocess.Popen(["./pufferpanel"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
38 |
+
|
39 |
+
|
40 |
+
threading.Thread(target=start_pufferpanel, daemon=True).start()
|
41 |
|
|
|
|
|
42 |
|
43 |
+
# ==========================
|
44 |
+
# FastAPI Reverse Proxy
|
45 |
+
# ==========================
|
46 |
+
app = FastAPI()
|
47 |
|
|
|
|
|
|
|
48 |
|
49 |
+
@app.api_route("/proxy/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
50 |
+
async def proxy(request: Request, path: str):
|
51 |
+
"""Reverse proxy to PufferPanel backend"""
|
52 |
+
url = f"{PUFFER_URL}/{path}"
|
53 |
+
headers = dict(request.headers)
|
54 |
+
body = await request.body()
|
55 |
+
|
56 |
+
try:
|
57 |
+
resp = requests.request(
|
58 |
+
method=request.method,
|
59 |
+
url=url,
|
60 |
+
headers=headers,
|
61 |
+
data=body,
|
62 |
+
cookies=request.cookies,
|
63 |
+
allow_redirects=False,
|
64 |
+
)
|
65 |
+
return Response(
|
66 |
+
content=resp.content,
|
67 |
+
status_code=resp.status_code,
|
68 |
+
headers=dict(resp.headers),
|
69 |
+
)
|
70 |
+
except Exception as e:
|
71 |
+
return Response(content=f"Proxy error: {e}", status_code=500)
|
72 |
+
|
73 |
|
74 |
+
# ==========================
|
75 |
+
# Gradio UI
|
76 |
+
# ==========================
|
77 |
+
def launch_panel():
|
78 |
+
return f"""
|
79 |
+
<iframe src="/proxy/" style="width: 100%; height: 700px; border: none;"></iframe>
|
80 |
+
"""
|
81 |
|
|
|
82 |
|
83 |
+
with gr.Blocks() as demo:
|
84 |
+
gr.Markdown("# π PufferPanel on Hugging Face\nLogin with your credentials below.")
|
85 |
+
gr.HTML(value=launch_panel())
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
# Mount FastAPI inside Gradio
|
88 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, root_path="/")
|