darshankr commited on
Commit
cafe5d4
·
verified ·
1 Parent(s): af779bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ # Initialize FastAPI and load your Hugging Face model
6
+ app = FastAPI()
7
+ model = pipeline("text-classification", model="your-username/your-model-name")
8
+
9
+ # Define request body with Pydantic
10
+ class InputData(BaseModel):
11
+ text: str
12
+
13
+ # API endpoint to receive input and return predictions
14
+ @app.post("/predict/")
15
+ async def predict(input_data: InputData):
16
+ try:
17
+ result = model(input_data.text)
18
+ return {"output": result}
19
+ except Exception as e:
20
+ raise HTTPException(status_code=500, detail=str(e))