from fastapi import FastAPI, HTTPException from pydantic import BaseModel from transformers import AutoModelForCausalLM, AutoTokenizer app = FastAPI() model_name = "Hadeel11/fine-tuned-model" model = AutoModelForCausalLM.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) class Query(BaseModel): question: str contexts: list @app.post("/predict/") async def predict(query: Query): inputs = tokenizer(query.question, return_tensors="pt") outputs = model.generate(**inputs) answer = tokenizer.decode(outputs[0], skip_special_tokens=True) return {"answer": answer}