Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,15 @@ app = FastAPI()
|
|
| 13 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 14 |
|
| 15 |
# ── Persistent storage ──────────────────────────────────────────────────────
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
THREADS_FILE = DATA_DIR / "threads.json"
|
| 19 |
|
| 20 |
def load_threads() -> dict:
|
|
@@ -892,4 +899,4 @@ loadThreads();
|
|
| 892 |
</template>
|
| 893 |
|
| 894 |
</body>
|
| 895 |
-
</html>"""
|
|
|
|
| 13 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 14 |
|
| 15 |
# ── Persistent storage ──────────────────────────────────────────────────────
|
| 16 |
+
# Use /data if persistent storage is mounted (HF Spaces), else fall back to home dir
|
| 17 |
+
_preferred = Path("/data/pharma_chat")
|
| 18 |
+
_fallback = Path(os.environ.get("HOME", "/home/user")) / "pharma_chat"
|
| 19 |
+
try:
|
| 20 |
+
_preferred.mkdir(parents=True, exist_ok=True)
|
| 21 |
+
DATA_DIR = _preferred
|
| 22 |
+
except PermissionError:
|
| 23 |
+
_fallback.mkdir(parents=True, exist_ok=True)
|
| 24 |
+
DATA_DIR = _fallback
|
| 25 |
THREADS_FILE = DATA_DIR / "threads.json"
|
| 26 |
|
| 27 |
def load_threads() -> dict:
|
|
|
|
| 899 |
</template>
|
| 900 |
|
| 901 |
</body>
|
| 902 |
+
</html>"""
|