File size: 1,487 Bytes
b769722
 
 
 
 
 
 
 
474e992
 
 
 
b769722
03b3405
 
 
 
b769722
 
 
474e992
 
 
 
b769722
 
 
 
 
 
 
 
 
 
 
 
 
 
03b3405
 
b769722
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import subprocess
import sys

# Set environment variables for HuggingFace Spaces
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
os.environ["STREAMLIT_DATA_DIR"] = "/tmp/.streamlit"
os.environ["NLTK_DATA"] = "/tmp/nltk_data"
os.environ["HF_HOME"] = "/tmp/huggingface"
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface/transformers"
os.environ["SENTENCE_TRANSFORMERS_HOME"] = "/tmp/huggingface/sentence_transformers"
os.environ["HF_HUB_CACHE"] = "/tmp/huggingface/hub"

# Additional environment variables to suppress Streamlit internal errors
os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"

# Create directories
os.makedirs("/tmp/.streamlit", exist_ok=True)
os.makedirs("/tmp/nltk_data", exist_ok=True)
os.makedirs("/tmp/huggingface", exist_ok=True)
os.makedirs("/tmp/huggingface/transformers", exist_ok=True)
os.makedirs("/tmp/huggingface/sentence_transformers", exist_ok=True)
os.makedirs("/tmp/huggingface/hub", exist_ok=True)

# Copy config if it exists
try:
    import shutil
    if os.path.exists(".streamlit/config.toml"):
        shutil.copy(".streamlit/config.toml", "/tmp/.streamlit/")
except Exception as e:
    print(f"Could not copy config: {e}")

# Start the app
if __name__ == "__main__":
    subprocess.run([
        sys.executable, "-m", "streamlit", "run", "src/streamlit_app.py",
        "--server.port=7860",
        "--server.address=0.0.0.0",
        "--logger.level=warning"
    ])