|
import os |
|
|
|
|
|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
MODEL_ID = "EQuIP-Queries/EQuIP_3B" |
|
|
|
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) |
|
model = AutoModelForCausalLM.from_pretrained(MODEL_ID) |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
class GenerateRequest(BaseModel): |
|
prompt: str |
|
max_new_tokens: int = 50 |
|
|
|
|
|
@app.post("/generate") |
|
async def generate(req: GenerateRequest): |
|
inputs = tokenizer(req.prompt, return_tensors="pt") |
|
ids = model.generate(**inputs, max_new_tokens=req.max_new_tokens) |
|
text = tokenizer.decode(ids[0], skip_special_tokens=True) |
|
return {"generated_text": text} |