Commit
·
8f788f9
0
Parent(s):
v1
Browse files- Dockerfile +16 -0
- app/main.py +44 -0
- docker-compose.yml +6 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.13.3
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY ./requirements.txt .
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r ./requirements.txt
|
8 |
+
|
9 |
+
|
10 |
+
COPY ./app ./app
|
11 |
+
CMD ["fastapi", "run", "app/main.py", "--port", "3000"]
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
# If running behind a proxy like Nginx or Traefik add --proxy-headers
|
16 |
+
# CMD ["fastapi", "run", "app/main.py", "--port", "80", "--proxy-headers"]
|
app/main.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request, Header
|
2 |
+
from gradio_client import Client
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
|
8 |
+
@app.api_route("/", methods=["GET", "POST"])
|
9 |
+
async def ping():
|
10 |
+
return {"pong": datetime.now().isoformat()}
|
11 |
+
|
12 |
+
|
13 |
+
@app.get("/private-policy")
|
14 |
+
async def ping():
|
15 |
+
return "We dont store your data. All data returned is public!"
|
16 |
+
|
17 |
+
@app.api_route("/gapi", methods=["GET", "POST"])
|
18 |
+
async def InvokeGradioApi(request: Request, x_hf_token: str = Header(default=None)):
|
19 |
+
if request.method == "POST":
|
20 |
+
data = await request.json()
|
21 |
+
else:
|
22 |
+
data = dict(request.query_params)
|
23 |
+
|
24 |
+
# Extrai SpaceName e AuthKey
|
25 |
+
space_name = data.pop("space", None)
|
26 |
+
auth_key = data.pop("auth", None) or x_hf_token
|
27 |
+
|
28 |
+
if not space_name:
|
29 |
+
return {"error": "Missing required parameter: space"}
|
30 |
+
|
31 |
+
print("Creating client", space_name);
|
32 |
+
client = Client(space_name, hf_token=auth_key if auth_key else None)
|
33 |
+
|
34 |
+
print("Data:")
|
35 |
+
print(data);
|
36 |
+
|
37 |
+
try:
|
38 |
+
result = client.predict(**data)
|
39 |
+
return result
|
40 |
+
except Exception as e:
|
41 |
+
return {"error": str(e)}
|
42 |
+
|
43 |
+
|
44 |
+
|
docker-compose.yml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
services:
|
2 |
+
app:
|
3 |
+
build: .
|
4 |
+
restart: unless-stopped
|
5 |
+
ports:
|
6 |
+
- 3000:3000
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi[standard]
|
2 |
+
pydantic
|
3 |
+
gradio_client
|