hackeracademy commited on
Commit
90f5d7c
·
1 Parent(s): 5d8cca4

Download model to /tmp to avoid permission error

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,21 +1,26 @@
1
- import os, gradio as gr
2
  from llama_cpp import Llama
3
 
4
  MODEL_URL = (
5
  "https://huggingface.co/fdtn-ai/Foundation-Sec-8B-Q4_K_M-GGUF/"
6
  "resolve/main/foundation-sec-8b-q4_k_m.gguf"
7
  )
8
- MODEL_PATH = "foundation-sec-8b-q4_k_m.gguf"
9
 
10
- # download once (Gradio blocks until the file exists)
 
 
 
 
11
  if not os.path.exists(MODEL_PATH):
12
- import requests, time
13
  with requests.get(MODEL_URL, stream=True) as r:
14
  r.raise_for_status()
15
  with open(MODEL_PATH, "wb") as f:
16
  for chunk in r.iter_content(chunk_size=8192):
17
  f.write(chunk)
 
18
 
 
19
  llm = Llama(model_path=MODEL_PATH, n_ctx=4096, verbose=False)
20
 
21
  def chat_fn(message, history):
 
1
+ import os, gradio as gr, requests, tempfile
2
  from llama_cpp import Llama
3
 
4
  MODEL_URL = (
5
  "https://huggingface.co/fdtn-ai/Foundation-Sec-8B-Q4_K_M-GGUF/"
6
  "resolve/main/foundation-sec-8b-q4_k_m.gguf"
7
  )
 
8
 
9
+ # writable directory
10
+ CACHE_DIR = "/tmp"
11
+ MODEL_PATH = os.path.join(CACHE_DIR, "foundation-sec-8b-q4_k_m.gguf")
12
+
13
+ # download only once
14
  if not os.path.exists(MODEL_PATH):
15
+ print("Downloading model … (~4.9 GB)")
16
  with requests.get(MODEL_URL, stream=True) as r:
17
  r.raise_for_status()
18
  with open(MODEL_PATH, "wb") as f:
19
  for chunk in r.iter_content(chunk_size=8192):
20
  f.write(chunk)
21
+ print("Download finished.")
22
 
23
+ # load model
24
  llm = Llama(model_path=MODEL_PATH, n_ctx=4096, verbose=False)
25
 
26
  def chat_fn(message, history):