shasee commited on
Commit
a37fdf9
·
verified ·
1 Parent(s): 148bd63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -64
app.py CHANGED
@@ -1,71 +1,38 @@
1
- import os
2
- import subprocess
3
- import threading
4
-
5
  import gradio as gr
6
  import spaces
7
- import httpx
8
- from fastapi import FastAPI, Request
9
- from fastapi.responses import Response
10
- from gradio.routes import mount_gradio_app
11
-
12
- node = None
13
-
14
- def start_node():
15
- global node
16
-
17
- if node and node.poll() is None:
18
- return "Already running"
19
-
20
- node = subprocess.Popen(
21
- ["node", "server.js"],
22
- cwd="/home/user/app"
23
- )
24
-
25
- return "Started"
26
-
27
- # Başlangıçta Node'u çalıştır
28
- threading.Thread(target=start_node, daemon=True).start()
29
 
30
- # ZeroGPU için boş GPU fonksiyonu
31
  @spaces.GPU
32
  def dummy():
33
  return "ok"
34
 
35
- app = FastAPI()
36
-
37
- @app.api_route(
38
- "/node/{path:path}",
39
- methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
40
- )
41
- async def proxy(path: str, request: Request):
42
- body = await request.body()
43
-
44
- async with httpx.AsyncClient(follow_redirects=True) as client:
45
- r = await client.request(
46
- request.method,
47
- f"http://127.0.0.1:8888/{path}",
48
- params=request.query_params,
49
- content=body,
50
- headers={k: v for k, v in request.headers.items() if k.lower() != "host"},
51
- )
52
-
53
- return Response(
54
- content=r.content,
55
- status_code=r.status_code,
56
- media_type=r.headers.get("content-type"),
57
- )
58
-
59
- with gr.Blocks(title="Node Proxy") as demo:
60
- gr.Markdown("# 🚀 Node Proxy")
61
- gr.Markdown("Node.js arka planda çalışıyor.")
62
- status = gr.Textbox(label="Status", value="Running", interactive=False)
63
- btn = gr.Button("Restart Node")
64
- btn.click(start_node, outputs=status)
65
-
66
- # FastAPI içine mount et
67
- app = mount_gradio_app(app, demo, path="/")
68
-
69
- # Gradio'yu başlat
70
- if __name__ == "__main__":
71
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
1
  import gradio as gr
2
  import spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
4
  @spaces.GPU
5
  def dummy():
6
  return "ok"
7
 
8
+ with gr.Blocks() as demo:
9
+ gr.Markdown("# Debug")
10
+
11
+ print("=" * 60)
12
+ print("GRADIO VERSION:", gr.__version__)
13
+ print("DEMO TYPE:", type(demo))
14
+ print("DEMO DIR:")
15
+ print(dir(demo))
16
+
17
+ for name in [
18
+ "app",
19
+ "fastapi_app",
20
+ "server_app",
21
+ "_app",
22
+ "_server_app",
23
+ "routes",
24
+ ]:
25
+ print(f"\n{name}:")
26
+ if hasattr(demo, name):
27
+ obj = getattr(demo, name)
28
+ print(type(obj))
29
+ try:
30
+ print(dir(obj))
31
+ except Exception as e:
32
+ print(e)
33
+ else:
34
+ print("NOT FOUND")
35
+
36
+ print("=" * 60)
37
+
38
+ demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)