Spaces:
Sleeping
Sleeping
brian-xetdata
commited on
Commit
·
f24e0f7
1
Parent(s):
523223a
Adding reverse proxy for netron
Browse files- Dockerfile +2 -1
- app.py +28 -5
- requirements.txt +3 -0
- wrapper.sh +11 -0
Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
FROM python:3.9
|
2 |
|
3 |
RUN useradd -m -u 1000 user
|
4 |
USER user
|
@@ -10,4 +10,5 @@ COPY --chown=user ./requirements.txt requirements.txt
|
|
10 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
|
12 |
COPY --chown=user . /app
|
|
|
13 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
FROM python:3.9-alpine3.20
|
2 |
|
3 |
RUN useradd -m -u 1000 user
|
4 |
USER user
|
|
|
10 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
|
12 |
COPY --chown=user . /app
|
13 |
+
|
14 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
@@ -1,8 +1,31 @@
|
|
1 |
-
from
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask
|
2 |
|
3 |
+
from starlette.requests import Request
|
4 |
+
from starlette.responses import StreamingResponse
|
5 |
+
from starlette.background import BackgroundTask
|
6 |
|
7 |
+
import httpx
|
8 |
+
|
9 |
+
client = httpx.AsyncClient(base_url="http://127.0.0.1:8080/")
|
10 |
+
|
11 |
+
async def _reverse_proxy(request: Request):
|
12 |
+
url = httpx.URL(path=request.url.path,
|
13 |
+
query=request.url.query.encode("utf-8"))
|
14 |
+
rp_req = client.build_request(request.method, url,
|
15 |
+
headers=request.headers.raw,
|
16 |
+
content=await request.body())
|
17 |
+
rp_resp = await client.send(rp_req, stream=True)
|
18 |
+
return StreamingResponse(
|
19 |
+
rp_resp.aiter_raw(),
|
20 |
+
status_code=rp_resp.status_code,
|
21 |
+
headers=rp_resp.headers,
|
22 |
+
background=BackgroundTask(rp_resp.aclose),
|
23 |
+
)
|
24 |
|
25 |
+
app = Flask(__name__)
|
26 |
+
|
27 |
+
app.add_route("/netron", _reverse_proxy, methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
28 |
+
|
29 |
+
@app.get("/")
|
30 |
+
def base():
|
31 |
+
return "<p>Netron is running</p>"
|
requirements.txt
CHANGED
@@ -1,2 +1,5 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
+
flask
|
4 |
+
httpx
|
5 |
+
netron
|
wrapper.sh
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Start the netron server
|
4 |
+
netron &
|
5 |
+
|
6 |
+
# Start the the web app
|
7 |
+
uvicorn app:app --host 0.0.0.0 --port 7860 &
|
8 |
+
|
9 |
+
wait -n
|
10 |
+
|
11 |
+
exit $?
|