MHULO commited on
Commit
2242346
·
verified ·
1 Parent(s): 1cd966f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ # Load the model and tokenizer from the Hugging Face Hub
8
+ model_name = "your-username/ner-model"
9
+ nlp = pipeline("ner", model=model_name, tokenizer=model_name)
10
+
11
+ class TextRequest(BaseModel):
12
+ text: str
13
+
14
+ @app.post("/predict/")
15
+ def predict(request: TextRequest):
16
+ ner_results = nlp(request.text)
17
+ return ner_results
18
+
19
+ if __name__ == "__main__":
20
+ import uvicorn
21
+ uvicorn.run(app, host="0.0.0.0", port=8000)