Kaan commited on
Commit
84927e5
·
verified ·
1 Parent(s): dad82da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -8,8 +8,11 @@ app = FastAPI()
8
  @app.get("/")
9
  async def generate_text():
10
  try:
 
 
 
11
  # Specify the directory for model download within the Docker container
12
- model_dir = "/code/model"
13
  os.makedirs(model_dir, exist_ok=True)
14
 
15
  hf_hub_download(repo_id="TheBloke/Mistral-7B-v0.1-GGUF", filename="mistral-7b-v0.1.Q4_K_M.gguf", local_dir=model_dir)
@@ -23,4 +26,4 @@ async def generate_text():
23
  generated_texts = tokenizer.batch_decode(output, skip_special_tokens=True)
24
  return generated_texts
25
  except Exception as e:
26
- raise HTTPException(status_code=500, detail=str(e))
 
8
  @app.get("/")
9
  async def generate_text():
10
  try:
11
+ # Get the cache directory from the environment variable
12
+ cache_dir = os.getenv("TRANSFORMERS_CACHE", "/code/cache")
13
+
14
  # Specify the directory for model download within the Docker container
15
+ model_dir = os.path.join(cache_dir, "TheBloke/Mistral-7B-v0.1-GGUF")
16
  os.makedirs(model_dir, exist_ok=True)
17
 
18
  hf_hub_download(repo_id="TheBloke/Mistral-7B-v0.1-GGUF", filename="mistral-7b-v0.1.Q4_K_M.gguf", local_dir=model_dir)
 
26
  generated_texts = tokenizer.batch_decode(output, skip_special_tokens=True)
27
  return generated_texts
28
  except Exception as e:
29
+ raise HTTPException(status_code=500, detail=str(e))