Spaces:
Sleeping
Sleeping
jocko
commited on
Commit
Β·
dafea1a
1
Parent(s):
5ae6be0
add comet on all other operations
Browse files- src/streamlit_app.py +10 -8
src/streamlit_app.py
CHANGED
|
@@ -4,6 +4,12 @@
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# ====== Force all cache dirs to /tmp (writable in most environments) ======
|
| 8 |
CACHE_BASE = "/tmp/cache"
|
| 9 |
os.environ["HF_HOME"] = f"{CACHE_BASE}/hf_home"
|
|
@@ -16,25 +22,21 @@ os.environ["STREAMLIT_STATIC_DIR"] = f"{CACHE_BASE}/streamlit_static"
|
|
| 16 |
|
| 17 |
# Create the directories before imports
|
| 18 |
for path in os.environ.values():
|
| 19 |
-
if path.startswith(CACHE_BASE):
|
| 20 |
os.makedirs(path, exist_ok=True)
|
| 21 |
|
| 22 |
-
# ======
|
| 23 |
import streamlit as st
|
| 24 |
import torch
|
| 25 |
from sentence_transformers import SentenceTransformer, util
|
| 26 |
from transformers import CLIPProcessor, CLIPModel
|
| 27 |
from datasets import load_dataset, get_dataset_split_names
|
| 28 |
from PIL import Image
|
|
|
|
| 29 |
import openai
|
|
|
|
| 30 |
from opik import track, log_event
|
| 31 |
|
| 32 |
-
import os
|
| 33 |
-
os.environ["COMET_DISABLE_AUTO_LOGGING"] = "1" # disable all auto-logging
|
| 34 |
-
# or to only disable LLM patching:
|
| 35 |
-
os.environ["COMET_DISABLE_AUTO_LOGGING_LLM"] = "1"
|
| 36 |
-
|
| 37 |
-
from openai import OpenAI
|
| 38 |
|
| 39 |
# ========== π API Key ==========
|
| 40 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# ---- Disable Comet auto-patching (MUST be set BEFORE importing openai/comet_llm/comet_ml) ----
|
| 8 |
+
# Disable all Comet auto-logging / monkey-patching
|
| 9 |
+
os.environ["COMET_DISABLE_AUTO_LOGGING"] = "1"
|
| 10 |
+
# Optionally: only disable LLM auto-logging
|
| 11 |
+
os.environ["COMET_DISABLE_AUTO_LOGGING_LLM"] = "1"
|
| 12 |
+
|
| 13 |
# ====== Force all cache dirs to /tmp (writable in most environments) ======
|
| 14 |
CACHE_BASE = "/tmp/cache"
|
| 15 |
os.environ["HF_HOME"] = f"{CACHE_BASE}/hf_home"
|
|
|
|
| 22 |
|
| 23 |
# Create the directories before imports
|
| 24 |
for path in os.environ.values():
|
| 25 |
+
if isinstance(path, str) and path.startswith(CACHE_BASE):
|
| 26 |
os.makedirs(path, exist_ok=True)
|
| 27 |
|
| 28 |
+
# ====== Now safe to import libraries ======
|
| 29 |
import streamlit as st
|
| 30 |
import torch
|
| 31 |
from sentence_transformers import SentenceTransformer, util
|
| 32 |
from transformers import CLIPProcessor, CLIPModel
|
| 33 |
from datasets import load_dataset, get_dataset_split_names
|
| 34 |
from PIL import Image
|
| 35 |
+
|
| 36 |
import openai
|
| 37 |
+
from openai import OpenAI # OK to import after openai is present
|
| 38 |
from opik import track, log_event
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# ========== π API Key ==========
|
| 42 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|