subbu123456 commited on
Commit
0a5bbcc
·
verified ·
1 Parent(s): a2a0402

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +9 -0
  2. app.py +22 -0
  3. requirements.txt +5 -0
  4. roberta_model.pkl +3 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from pydantic import BaseModel
3
+ import joblib
4
+
5
+ app = FastAPI()
6
+
7
+ # Load the model
8
+ with open("roberta_model.pkl", "rb") as f:
9
+ model = joblib.load(f)
10
+
11
+ class InputText(BaseModel):
12
+ text: str
13
+
14
+ @app.post("/predict")
15
+ def predict(data: InputText):
16
+ input_text = data.text
17
+ inputs = model["tokenizer"](input_text, return_tensors="pt", padding=True, truncation=True)
18
+ with model["torch"].no_grad():
19
+ outputs = model["model"](**inputs)
20
+ logits = outputs.logits
21
+ predictions = logits.argmax(dim=1).tolist()
22
+ return {"predictions": predictions}
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.95.2
2
+ uvicorn==0.22.0
3
+ transformers==4.40.1
4
+ torch
5
+ joblib
roberta_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83acce8cff053ecb1dd5f36bf2fad7bc51ee4720e1d17b0c43afa1b029264ec3
3
+ size 11