Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,23 +5,18 @@ 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",
|
@@ -33,7 +28,6 @@ def start_pufferpanel():
|
|
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 |
|
@@ -48,11 +42,9 @@ app = FastAPI()
|
|
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,
|
@@ -72,17 +64,16 @@ async def proxy(request: Request, path: str):
|
|
72 |
|
73 |
|
74 |
# ==========================
|
75 |
-
# Gradio UI
|
76 |
# ==========================
|
77 |
def launch_panel():
|
78 |
-
return
|
79 |
-
<iframe src="/proxy/" style="width: 100%; height:
|
80 |
"""
|
81 |
|
82 |
|
83 |
with gr.Blocks() as demo:
|
84 |
-
gr.Markdown("# π PufferPanel on Hugging Face
|
85 |
gr.HTML(value=launch_panel())
|
86 |
|
87 |
-
|
88 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, root_path="/")
|
|
|
5 |
import gradio as gr
|
6 |
from fastapi import FastAPI, Request
|
7 |
from fastapi.responses import Response
|
|
|
8 |
|
9 |
# ==========================
|
10 |
# CONFIG
|
11 |
# ==========================
|
12 |
PUFFER_URL = "http://127.0.0.1:8080" # Internal PufferPanel address
|
|
|
|
|
13 |
|
14 |
|
15 |
# ==========================
|
16 |
# Start PufferPanel
|
17 |
# ==========================
|
18 |
def start_pufferpanel():
|
|
|
19 |
if not os.path.exists("pufferpanel"):
|
|
|
20 |
subprocess.run(
|
21 |
[
|
22 |
"wget",
|
|
|
28 |
)
|
29 |
subprocess.run(["tar", "xvzf", "pufferpanel.tar.gz"], check=True)
|
30 |
|
|
|
31 |
subprocess.Popen(["./pufferpanel"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
32 |
|
33 |
|
|
|
42 |
|
43 |
@app.api_route("/proxy/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
44 |
async def proxy(request: Request, path: str):
|
|
|
45 |
url = f"{PUFFER_URL}/{path}"
|
46 |
headers = dict(request.headers)
|
47 |
body = await request.body()
|
|
|
48 |
try:
|
49 |
resp = requests.request(
|
50 |
method=request.method,
|
|
|
64 |
|
65 |
|
66 |
# ==========================
|
67 |
+
# Gradio UI (clean)
|
68 |
# ==========================
|
69 |
def launch_panel():
|
70 |
+
return """
|
71 |
+
<iframe src="/proxy/" style="width: 100%; height: 90vh; border: none;"></iframe>
|
72 |
"""
|
73 |
|
74 |
|
75 |
with gr.Blocks() as demo:
|
76 |
+
gr.Markdown("# π PufferPanel on Hugging Face")
|
77 |
gr.HTML(value=launch_panel())
|
78 |
|
79 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, root_path="/")
|
|