File size: 867 Bytes
dacf14a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import APIRouter, HTTPException
from .schemas import ConfigRequest
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline, AutoModelForSequenceClassification
from app.models import predict_sentiment

router = APIRouter()

model_name = "fine-tuned-model"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_safetensors=True)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

@router.post("/")
def configure_model(config: ConfigRequest):
    global model, tokenizer, qa_pipeline
    try:
        model = AutoModelForQuestionAnswering.from_pretrained(config.model_name)
        tokenizer = AutoTokenizer.from_pretrained(config.model_name)
        return {"message": f"Model loaded successfully: {config.model_name}"}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))