Amish Kushwaha commited on
Commit
3cc890e
·
1 Parent(s): 17e61d3

Deploy FastAPI abap model on HF Spaces with custom endpoints

Browse files
Files changed (4) hide show
  1. .gitignore +5 -0
  2. Dockerfile +15 -0
  3. app.py +24 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ venv/
2
+ .env
3
+ __pycache__/
4
+ *.pyc
5
+ .DS_Store
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python as the base image
2
+ FROM python:3.9
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy requirements and install dependencies
8
+ COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ # Copy the FastAPI app
12
+ COPY . .
13
+
14
+ # Run FastAPI server
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ # Load your Hugging Face model
6
+ model = pipeline("text-generation", model="devops-bda/Abap")
7
+
8
+ # Initialize FastAPI app
9
+ app = FastAPI()
10
+
11
+ # Define input format
12
+ class InputData(BaseModel):
13
+ input_text: str
14
+
15
+ # Health check endpoint
16
+ @app.get("/health")
17
+ async def health_check():
18
+ return {"status": "ok", "message": "Model is ready"}
19
+
20
+ # Define prediction endpoint
21
+ @app.post("/predict")
22
+ async def predict(data: InputData):
23
+ result = model(data.input_text, max_length=500)
24
+ return {"output": result}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ transformers
4
+ torch