devops-bda/abap-api
0
1import os2from fastapi import FastAPI3from pydantic import BaseModel4from transformers import (5 AutoModelForCausalLM, 6 AutoTokenizer, 7 pipeline, 8 AutoConfig9)10 11# Load the configuration and remove any quantization config if present12config = AutoConfig.from_pretrained("devops-bda/Abap")13if hasattr(config, "quantization_config"):14 del config.quantization_config # Safely delete it instead of setting to None15 16# Load the model and tokenizer without 4-bit quantization17model = AutoModelForCausalLM.from_pretrained(18 "devops-bda/Abap",19 config=config,20 device_map="auto" # This ensures the model loads properly on CPU21)22tokenizer = AutoTokenizer.from_pretrained("devops-bda/Abap")23 24# Create a text-generation pipeline with the loaded model and tokenizer25text_gen_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)26 27app = FastAPI()28 29class InputData(BaseModel):30 input_text: str31 32@app.get("/health")33async def health_check():34 return {"status": "ok", "message": "Model is ready"}35 36@app.post("/predict")37async def predict(data: InputData):38 output = text_gen_pipeline(data.input_text, max_length=500)39 return {"output": output}