Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, Request | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse | |
| from transformers import pipeline | |
| app = FastAPI() | |
| async def query_gorilla(req: Request): | |
| body = await req.body() | |
| return { | |
| "val": body | |
| } | |
| app.mount("/", StaticFiles(directory="static", html=True), name="static") | |
| 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, | |
| ) | |
| ''' | |