SyntheticVis-Umut commited on
Commit
819742e
·
1 Parent(s): 70d2fd6

Add FastAPI application with Docker support

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. app.py +16 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ # Speed up installs
4
+ ENV PIP_NO_CACHE_DIR=1 PIP_DISABLE_PIP_VERSION_CHECK=1
5
+
6
+ # Install deps
7
+ COPY requirements.txt .
8
+ RUN pip install -r requirements.txt
9
+
10
+ # Add app
11
+ COPY app.py .
12
+
13
+ # Hugging Face Spaces injects $PORT (e.g., 7860). Bind to it.
14
+ ENV PORT=7860
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+
4
+ app = FastAPI(title="Hello API")
5
+
6
+ class Prompt(BaseModel):
7
+ text: str
8
+
9
+ @app.get("/")
10
+ def root():
11
+ return {"ok": True, "message": "API is live"}
12
+
13
+ @app.post("/echo")
14
+ def echo(p: Prompt):
15
+ # do your logic here
16
+ return {"length": len(p.text), "upper": p.text.upper()}
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn