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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
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 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="/")
 
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="/")