from fastapi import FastAPI, Request from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse from transformers import pipeline app = FastAPI() @app.post("/query_gorilla") async def query_gorilla(req: Request): body = await request.body() return str(body) app.mount("/", StaticFiles(directory="static", html=True), name="static") @app.get("/") def index() -> FileResponse: return FileResponse(path="/app/static/index.html", media_type="text/html") TODO = ''' print('Device setup') device : str = "cuda:0" if torch.cuda.is_available() else "cpu" torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 print('Model and tokenizer setup') model_id : str = "gorilla-llm/gorilla-openfunctions-v1" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True) print('Move model to device') model.to(device) print('Pipeline setup') pipe = pipeline( "text-generation", model=model, tokenizer=tokenizer, max_new_tokens=128, batch_size=16, torch_dtype=torch_dtype, device=device, ) '''