KevanSoon
commited on
Commit
·
6f21a14
1
Parent(s):
8fe3b65
initlaize fastapi endpoint and dockerfile
Browse files- Dockerfile +14 -0
- main.py +24 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use official Python runtime base image
|
| 2 |
+
FROM python:3.10.9
|
| 3 |
+
|
| 4 |
+
# Copy project files
|
| 5 |
+
COPY . .
|
| 6 |
+
|
| 7 |
+
# Set working directory
|
| 8 |
+
WORKDIR /
|
| 9 |
+
|
| 10 |
+
# Install dependencies listed in requirements.txt
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Command to run FastAPI app on port 7860
|
| 14 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from gradio_client import Client
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Create Gradio client instance once
|
| 8 |
+
client = Client("https://kby-ai-facerecognition.hf.space/--replicas/ij0t7/")
|
| 9 |
+
|
| 10 |
+
# Pydantic model for input URLs
|
| 11 |
+
class ImagesInput(BaseModel):
|
| 12 |
+
image1: str
|
| 13 |
+
image2: str
|
| 14 |
+
|
| 15 |
+
@app.post("/face-recognition/")
|
| 16 |
+
async def face_recognition(data: ImagesInput):
|
| 17 |
+
# Call the Gradio client predict with the URLs from request body
|
| 18 |
+
result = client.predict(
|
| 19 |
+
data.image1, # parameter_8 image
|
| 20 |
+
data.image2, # parameter_11 image
|
| 21 |
+
fn_index=2
|
| 22 |
+
)
|
| 23 |
+
# Return the prediction result as JSON
|
| 24 |
+
return {"result": result}
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.99.1
|
| 2 |
+
uvicorn[standard]==0.22.0
|
| 3 |
+
gradio-client==0.5.3
|