rabiyulfahim commited on
Commit
287f932
·
verified ·
1 Parent(s): 3edcf27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -3,6 +3,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
  import os
5
  from pydantic import BaseModel
 
 
6
 
7
  # ✅ Force Hugging Face cache to /tmp (writable in Spaces)
8
  os.environ["HF_HOME"] = "/tmp"
@@ -17,7 +19,13 @@ model = AutoModelForCausalLM.from_pretrained(model_id, cache_dir="/tmp")
17
 
18
  app = FastAPI(title="QA GPT2 API", description="Serving HuggingFace model with FastAPI")
19
 
20
-
 
 
 
 
 
 
21
  # Request schema
22
  class QueryRequest(BaseModel):
23
  question: str
 
3
  import torch
4
  import os
5
  from pydantic import BaseModel
6
+ from fastapi.middleware.cors import CORSMiddleware
7
+
8
 
9
  # ✅ Force Hugging Face cache to /tmp (writable in Spaces)
10
  os.environ["HF_HOME"] = "/tmp"
 
19
 
20
  app = FastAPI(title="QA GPT2 API", description="Serving HuggingFace model with FastAPI")
21
 
22
+ app.add_middleware(
23
+ CORSMiddleware,
24
+ allow_origins=["*"],
25
+ allow_credentials=True,
26
+ allow_methods=["*"],
27
+ allow_headers=["*"],
28
+ )
29
  # Request schema
30
  class QueryRequest(BaseModel):
31
  question: str