SuhasGholkar commited on
Commit
67090c6
·
verified ·
1 Parent(s): 467763f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -6,17 +6,28 @@ import json
6
  import time
7
  from datetime import datetime
8
  import dateparser
9
- import streamlit as st
10
- import matplotlib.pyplot as plt
11
  import pandas as pd
12
  from openai import OpenAI
13
 
14
- # --- Hugging Face Spaces: make Streamlit write to a writable HOME ---
15
  import os, pathlib
16
  APP_DIR = pathlib.Path(__file__).parent.resolve()
17
- os.environ.setdefault("HOME", str(APP_DIR)) # avoid '/.streamlit'
18
- os.makedirs(APP_DIR / ".streamlit", exist_ok=True) # ensure dir exists
19
- os.environ.setdefault("STREAMLIT_SERVER_HEADLESS", "true") # headless always
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  # ================= CONFIG =================
22
  DB_PATH = "./tmp/olist.sqlite"
 
6
  import time
7
  from datetime import datetime
8
  import dateparser
 
 
9
  import pandas as pd
10
  from openai import OpenAI
11
 
12
+ # --- Make config/cache dirs writable on Hugging Face Spaces ---
13
  import os, pathlib
14
  APP_DIR = pathlib.Path(__file__).parent.resolve()
15
+ os.environ.setdefault("HOME", str(APP_DIR)) # avoid writing to '/'
16
+ os.environ.setdefault("XDG_CACHE_HOME", str(APP_DIR / ".cache")) # general cache
17
+ os.environ.setdefault("MPLCONFIGDIR", str(APP_DIR / ".mplconfig")) # matplotlib cache/config
18
+ os.environ.setdefault("STREAMLIT_SERVER_HEADLESS", "true") # headless always
19
+
20
+ # ensure dirs exist
21
+ (os.path.isdir(APP_DIR / ".streamlit") or os.makedirs(APP_DIR / ".streamlit", exist_ok=True))
22
+ (os.path.isdir(APP_DIR / ".cache") or os.makedirs(APP_DIR / ".cache", exist_ok=True))
23
+ (os.path.isdir(APP_DIR / ".mplconfig") or os.makedirs(APP_DIR / ".mplconfig", exist_ok=True))
24
+
25
+ # pick a non-interactive backend for matplotlib
26
+ import matplotlib
27
+ matplotlib.use("Agg")
28
+
29
+ import streamlit as st
30
+ import matplotlib.pyplot as plt
31
 
32
  # ================= CONFIG =================
33
  DB_PATH = "./tmp/olist.sqlite"