Adedayo2000 commited on
Commit
b2e1129
·
verified ·
1 Parent(s): e686a2d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
4
+
5
+ app = FastAPI()
6
+
7
+ MODEL_ID = "Adedayo2000/sentiment-model"
8
+
9
+ hf_token = os.getenv("HF_TOKEN")
10
+
11
+ print("Loading model...")
12
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=hf_token)
13
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID, token=hf_token)
14
+ print("Model loaded successfully!")
15
+
16
+ @app.get("/")
17
+ def read_root():
18
+ return {"message": "API is live!", "model": MODEL_ID}
19
+
20
+ @app.post("/predict")
21
+ def predict(text: str):
22
+ inputs = tokenizer(text, return_tensors="pt")
23
+ outputs = model(**inputs)
24
+ return {"logits": outputs.logits.tolist()}