fguryel commited on
Commit
74bb35b
·
1 Parent(s): 09acea5

HF Spaces optimization: Add Streamlit config, suppress warnings, clean README metadata

Browse files
Files changed (5) hide show
  1. .streamlit/config.toml +14 -0
  2. .streamlit/secrets.toml +5 -0
  3. README.md +3 -12
  4. app.py +6 -2
  5. run.py +39 -0
.streamlit/config.toml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [server]
2
+ headless = true
3
+ port = 7860
4
+ enableCORS = false
5
+ enableXsrfProtection = false
6
+
7
+ [theme]
8
+ base = "light"
9
+ primaryColor = "#1f77b4"
10
+ backgroundColor = "#ffffff"
11
+ secondaryBackgroundColor = "#f0f2f6"
12
+
13
+ [browser]
14
+ gatherUsageStats = false
.streamlit/secrets.toml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Streamlit secrets for Hugging Face Spaces
2
+ # This helps reduce warning messages
3
+
4
+ [general]
5
+ dataFrameSerialization = "legacy"
README.md CHANGED
@@ -1,16 +1,4 @@
1
  ---
2
- title: Scikit Rag
3
- emoji: 🐢
4
- colorFrom: blue
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.47.2
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
- ---
14
  title: Scikit-learn Documentation Q&A Bot
15
  emoji: 🤖
16
  colorFrom: blue
@@ -21,6 +9,9 @@ app_file: app.py
21
  pinned: false
22
  license: mit
23
  ---
 
 
 
24
 
25
  # Scikit-learn Documentation Q&A Bot 🤖
26
 
 
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
2
  title: Scikit-learn Documentation Q&A Bot
3
  emoji: 🤖
4
  colorFrom: blue
 
9
  pinned: false
10
  license: mit
11
  ---
12
+ pinned: false
13
+ license: mit
14
+ ---
15
 
16
  # Scikit-learn Documentation Q&A Bot 🤖
17
 
app.py CHANGED
@@ -26,6 +26,10 @@ from openai import OpenAI
26
  logging.basicConfig(level=logging.INFO)
27
  logger = logging.getLogger(__name__)
28
 
 
 
 
 
29
 
30
  class RAGChatbot:
31
  """
@@ -664,5 +668,5 @@ def main():
664
  """)
665
 
666
 
667
- # This ensures the app runs properly on Hugging Face Spaces
668
- main()
 
26
  logging.basicConfig(level=logging.INFO)
27
  logger = logging.getLogger(__name__)
28
 
29
+ # Suppress Streamlit context warnings for HF Spaces
30
+ logging.getLogger("streamlit.runtime.scriptrunner_utils.script_run_context").setLevel(logging.ERROR)
31
+ logging.getLogger("streamlit.runtime.state.session_state_proxy").setLevel(logging.ERROR)
32
+
33
 
34
  class RAGChatbot:
35
  """
 
668
  """)
669
 
670
 
671
+ if __name__ == "__main__":
672
+ main()
run.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Runner script for Hugging Face Spaces
4
+ This ensures Streamlit runs properly in HF Spaces environment
5
+ """
6
+
7
+ import subprocess
8
+ import sys
9
+ import os
10
+
11
+ def main():
12
+ """Run the Streamlit app with proper configuration for HF Spaces"""
13
+
14
+ # Set environment variables for better HF Spaces compatibility
15
+ os.environ["STREAMLIT_SERVER_HEADLESS"] = "true"
16
+ os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "false"
17
+ os.environ["STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION"] = "false"
18
+
19
+ # Run streamlit with the app file
20
+ cmd = [
21
+ sys.executable, "-m", "streamlit", "run", "app.py",
22
+ "--server.port=7860",
23
+ "--server.address=0.0.0.0",
24
+ "--server.headless=true",
25
+ "--server.enableCORS=false",
26
+ "--server.enableXsrfProtection=false",
27
+ "--theme.base=light"
28
+ ]
29
+
30
+ print("🚀 Starting Streamlit app for Hugging Face Spaces...")
31
+ print(f"Command: {' '.join(cmd)}")
32
+
33
+ # Execute the command
34
+ result = subprocess.run(cmd)
35
+ return result.returncode
36
+
37
+ if __name__ == "__main__":
38
+ exit_code = main()
39
+ sys.exit(exit_code)