luciagomez commited on
Commit
9d2dfac
·
verified ·
1 Parent(s): da635de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -9,9 +9,9 @@ import torch
9
  # Hugging Face token stored in Spaces secrets
10
  HF_TOKEN = os.environ.get("HF_TOKEN")
11
 
12
- # Persistent model path in Space filesystem
13
- MODEL_PATH = "./mistral"
14
- CACHE_DIR = "./.cache/huggingface"
15
 
16
  # Ensure directories exist
17
  os.makedirs(MODEL_PATH, exist_ok=True)
@@ -22,7 +22,7 @@ os.environ["HF_HOME"] = CACHE_DIR
22
 
23
  # Download model if not already present
24
  if not os.listdir(MODEL_PATH):
25
- print("Downloading Mistral model...")
26
  snapshot_download(
27
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
28
  repo_type="model",
@@ -30,7 +30,7 @@ if not os.listdir(MODEL_PATH):
30
  use_auth_token=HF_TOKEN
31
  )
32
  else:
33
- print("Model already exists. Skipping download.")
34
 
35
  # Load tokenizer and model from local path
36
  tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
@@ -49,7 +49,7 @@ def find_and_download_annual_report(company):
49
  query = f"site:example.com {company} annual report filetype:pdf"
50
  pdf_url = search_pdf_url(query)
51
  if pdf_url:
52
- local_path = download_pdf(pdf_url, save_dir="./pdfs")
53
  return f"Downloaded: {local_path}"
54
  return "No PDF found"
55
 
@@ -79,3 +79,4 @@ with gr.Blocks() as demo:
79
  demo.launch(server_name="0.0.0.0", server_port=7860)
80
 
81
 
 
 
9
  # Hugging Face token stored in Spaces secrets
10
  HF_TOKEN = os.environ.get("HF_TOKEN")
11
 
12
+ # Writable model path and cache directory in Spaces
13
+ MODEL_PATH = "/tmp/mistral"
14
+ CACHE_DIR = "/tmp/.cache/huggingface"
15
 
16
  # Ensure directories exist
17
  os.makedirs(MODEL_PATH, exist_ok=True)
 
22
 
23
  # Download model if not already present
24
  if not os.listdir(MODEL_PATH):
25
+ print("Downloading Mistral model to /tmp...")
26
  snapshot_download(
27
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
28
  repo_type="model",
 
30
  use_auth_token=HF_TOKEN
31
  )
32
  else:
33
+ print("Model already exists in /tmp. Skipping download.")
34
 
35
  # Load tokenizer and model from local path
36
  tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
 
49
  query = f"site:example.com {company} annual report filetype:pdf"
50
  pdf_url = search_pdf_url(query)
51
  if pdf_url:
52
+ local_path = download_pdf(pdf_url, save_dir="/tmp/pdfs")
53
  return f"Downloaded: {local_path}"
54
  return "No PDF found"
55
 
 
79
  demo.launch(server_name="0.0.0.0", server_port=7860)
80
 
81
 
82
+