Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI(title="QA GPT2 API", description="Serving HuggingFace model with FastAPI")
|
| 6 |
|
| 7 |
-
# Load model once on startup
|
| 8 |
-
model_id = "rabiyulfahim/qa_python_gpt2" # 👈 replace with your HF repo
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 10 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 11 |
|
| 12 |
@app.get("/")
|
| 13 |
def home():
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
os.environ["TRANSFORMERS_CACHE"] = "/app/cache"
|
| 8 |
+
|
| 9 |
+
model_id = "rabiyulfahim/qa_python_gpt2"
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir="/app/cache")
|
| 12 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, cache_dir="/app/cache")
|
| 13 |
|
| 14 |
app = FastAPI(title="QA GPT2 API", description="Serving HuggingFace model with FastAPI")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@app.get("/")
|
| 18 |
def home():
|