assignment / app.py
kundan621's picture
refactor
03b3405
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"
])