File size: 662 Bytes
2242346
 
 
52674a0
d65b8c0
9baebbc
858e262
e1aef3f
c6523f5
2242346
 
 
 
8d8398d
2242346
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
import os
from huggingface_hub import login

# Log in to Hugging Face
access_token = os.environ.get("ACCESS_TOKEN_1")
login(token=access_token)

app = FastAPI()

# Load the model and tokenizer from the Hugging Face Hub
model_name = "MHULO/yembaner"
nlp = pipeline("ner", model=model_name, tokenizer=model_name)

class TextRequest(BaseModel):
    text: str

@app.post("/predict/")
def predict(request: TextRequest):
    ner_results = nlp(request.text)
    return ner_results

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)