Techbitforge commited on
Commit
97fb843
Β·
verified Β·
1 Parent(s): e1e2d43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -30
app.py CHANGED
@@ -1,45 +1,88 @@
1
  import os
2
  import subprocess
3
  import threading
 
4
  import gradio as gr
 
 
 
5
 
6
- def install_pufferpanel():
7
- if not os.path.exists("/usr/sbin/pufferpanel"):
8
- # Download amd64 deb package
 
 
 
 
 
 
 
 
 
 
 
 
9
  subprocess.run(
10
- "wget https://github.com/pufferpanel/pufferpanel/releases/download/v3.0.0-rc.14/pufferpanel_3.0.0-rc.14_amd64.deb -O pufferpanel.deb",
11
- shell=True, check=True
 
 
 
 
 
12
  )
13
- # Install dependencies and package
14
- subprocess.run("apt-get update && apt-get install -y ./pufferpanel.deb", shell=True, check=True)
15
- # Enable PufferPanel
16
- subprocess.run("pufferpanel user add admin --password admin123", shell=True, check=True)
 
 
 
17
 
18
- def run_pufferpanel():
19
- subprocess.run("pufferpanel run", shell=True)
20
 
21
- install_pufferpanel()
22
- threading.Thread(target=run_pufferpanel, daemon=True).start()
 
 
23
 
24
- def launch_info():
25
- return """
26
- ## πŸš€ PufferPanel v3.0.0-rc.14
27
 
28
- Running inside Hugging Face Space.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- **Login Credentials:**
31
- - **User:** `admin`
32
- - **Pass:** `admin123`
 
 
 
 
33
 
34
- """
35
 
36
- with gr.Blocks(title="PufferPanel on Hugging Face") as demo:
37
- gr.Markdown(launch_info)
38
- gr.HTML("""
39
- <iframe src="http://localhost:8080"
40
- style="width:100%; height:800px; border:none;">
41
- </iframe>
42
- """)
43
 
44
- if __name__ == "__main__":
45
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
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="/")