baxin commited on
Commit
e63c3a7
Β·
verified Β·
1 Parent(s): bfe4e0b

Upload 7 files

Browse files
Files changed (5) hide show
  1. .gitignore +71 -0
  2. .streamlit/config.toml +9 -0
  3. Dockerfile +21 -4
  4. src/config.py +31 -0
  5. src/streamlit_app.py +39 -11
.gitignore ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # Virtual environments
28
+ venv/
29
+ env/
30
+ ENV/
31
+ .venv/
32
+ .env/
33
+ .virtualenv/
34
+
35
+ # Environments
36
+ .env
37
+ .env.*
38
+ !.env.example
39
+
40
+ # IDE specific files
41
+ .idea/
42
+ .vscode/
43
+ *.swp
44
+ *.swo
45
+ .DS_Store
46
+
47
+ # Jupyter Notebook
48
+ .ipynb_checkpoints
49
+
50
+ # Testing
51
+ .coverage
52
+ htmlcov/
53
+
54
+ # Logs
55
+ logs/
56
+ *.log
57
+
58
+ # Local development settings
59
+ local_settings.py
60
+
61
+ # Database files
62
+ *.db
63
+ *.sqlite3
64
+
65
+ # Large binary files
66
+ *.pkl
67
+ *.h5
68
+ *.npy
69
+ *.npz
70
+
71
+ venv/
.streamlit/config.toml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [server]
2
+ port = 8501
3
+ address = "0.0.0.0"
4
+
5
+ [browser]
6
+ gatherUsageStats = false
7
+
8
+ [global]
9
+ developmentMode = false
Dockerfile CHANGED
@@ -9,13 +9,30 @@ RUN apt-get update && apt-get install -y \
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
 
15
- RUN pip3 install -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  EXPOSE 8501
18
 
19
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
9
  git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # Create a non-root user
13
+ RUN useradd -m -u 1000 streamlit
14
 
15
+ # Create necessary directories and set permissions
16
+ RUN mkdir -p /app/.streamlit && \
17
+ chown -R streamlit:streamlit /app
18
+
19
+ # Switch to non-root user
20
+ USER streamlit
21
+
22
+ COPY --chown=streamlit:streamlit requirements.txt ./
23
+ COPY --chown=streamlit:streamlit src/ ./src/
24
+ COPY --chown=streamlit:streamlit .streamlit/ ./.streamlit/
25
+
26
+ RUN pip3 install --user -r requirements.txt
27
+
28
+ # Set environment variables
29
+ ENV STREAMLIT_SERVER_PORT=8501
30
+ ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
31
+ ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
32
+ ENV STREAMLIT_GLOBAL_DEVELOPMENT_MODE=false
33
 
34
  EXPOSE 8501
35
 
36
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
37
 
38
+ ENTRYPOINT ["python", "-m", "streamlit", "run", "src/streamlit_app.py"]
src/config.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Configuration for available Cerebras models."""
2
+
3
+ from typing import Dict, TypedDict
4
+
5
+ class ModelConfig(TypedDict):
6
+ name: str
7
+ tokens: int
8
+ developer: str
9
+
10
+ MODELS: Dict[str, ModelConfig] = {
11
+ "llama3.1-8b": {
12
+ "name": "Llama3.1-8b",
13
+ "tokens": 8192,
14
+ "developer": "Meta"
15
+ },
16
+ "llama-3.3-70b": {
17
+ "name": "Llama-3.3-70b",
18
+ "tokens": 8192,
19
+ "developer": "Meta"
20
+ },
21
+ "llama-4-scout-17b-16e-instruct": {
22
+ "name": "Llama4 Scout",
23
+ "tokens": 8192,
24
+ "developer": "Meta"
25
+ },
26
+ "qwen-3-32b": {
27
+ "name": "Qwen 3 32B",
28
+ "tokens": 8192,
29
+ "developer": "Alibaba"
30
+ }
31
+ }
src/streamlit_app.py CHANGED
@@ -1,28 +1,46 @@
1
  import streamlit as st
2
  import time
3
  import os
 
 
4
 
5
  # Attempt to import Cerebras SDK and specific error classes
 
 
 
 
6
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  from cerebras.cloud.sdk import Cerebras
8
- from cerebras.cloud.sdk.errors import APIError, APIConnectionError, AuthenticationError
 
 
9
  CEREBRAS_SDK_AVAILABLE = True
10
- except ImportError:
 
11
  CEREBRAS_SDK_AVAILABLE = False
 
 
 
12
  # Define dummy classes if SDK is not available, so the rest of the code doesn't break
13
  class Cerebras: pass
14
  class APIError(Exception): pass
15
  class APIConnectionError(APIError): pass
16
  class AuthenticationError(APIError): pass
17
 
18
- # --- Configuration ---
19
- MODELS = {
20
- "llama3.1-8b": {"name": "Llama3.1-8b", "tokens": 8192, "developer": "Meta"},
21
- "llama-3.3-70b": {"name": "Llama-3.3-70b", "tokens": 8192, "developer": "Meta"},
22
- "llama-4-scout-17b-16e-instruct": {"name": "Llama4 Scout", "tokens": 8192, "developer": "Meta"},
23
- "qwen-3-32b":{"name": "Qwen 3 32B", "tokens": 8192, "developer": "Qwen"},
24
- }
25
-
26
  # --- Helper Functions (Actual API Interaction) ---
27
  def get_cebras_response(api_key, model_id, current_prompt, chat_history_for_api):
28
  """
@@ -80,13 +98,22 @@ def get_cebras_response(api_key, model_id, current_prompt, chat_history_for_api)
80
  # --- Streamlit App ---
81
  st.set_page_config(page_title="Cerebras Chatbot", page_icon="πŸ€–")
82
 
 
 
 
 
 
 
83
  st.title("πŸ€– Cerebras Powered Chatbot")
84
 
85
  if not CEREBRAS_SDK_AVAILABLE:
86
  st.error(
87
- "The Cerebras SDK is not installed. Please install it by running `pip install cerebras-cloud-sdk` in your terminal and restart the app.",
88
  icon="🚨"
89
  )
 
 
 
90
  st.stop()
91
 
92
  st.caption("A Streamlit application for interacting with Cerebras models via `cerebras.cloud.sdk`.")
@@ -187,3 +214,4 @@ if prompt := st.chat_input("What would you like to ask?"):
187
  if st.sidebar.button("Clear Chat History"):
188
  st.session_state.messages = []
189
  st.rerun()
 
 
1
  import streamlit as st
2
  import time
3
  import os
4
+ import sys
5
+ from config import MODELS
6
 
7
  # Attempt to import Cerebras SDK and specific error classes
8
+ # Set up variables to capture debugging information
9
+ import_error_details = ""
10
+ sdk_import_paths = []
11
+
12
  try:
13
+ # Try to explicitly check if the cerebras module is available
14
+ import importlib.util
15
+ spec = importlib.util.find_spec("cerebras")
16
+ if spec is not None:
17
+ sdk_import_paths.append(f"cerebras module found at: {spec.origin}")
18
+ else:
19
+ sdk_import_paths.append("cerebras module not found in sys.path")
20
+
21
+ # Capture Python's module search paths
22
+ sdk_import_paths.append("Python sys.path contains:")
23
+ for path in sys.path:
24
+ sdk_import_paths.append(f" - {path}")
25
+
26
+ # Now try the actual import
27
  from cerebras.cloud.sdk import Cerebras
28
+ # Try to import error classes directly from the main SDK package
29
+ # The error classes are likely defined within the main SDK package
30
+ from cerebras.cloud.sdk import APIError, APIConnectionError, AuthenticationError
31
  CEREBRAS_SDK_AVAILABLE = True
32
+ sdk_import_paths.append("βœ… Cerebras SDK import successful")
33
+ except ImportError as e:
34
  CEREBRAS_SDK_AVAILABLE = False
35
+ import_error_details = str(e)
36
+ sdk_import_paths.append(f"❌ Import Error: {import_error_details}")
37
+
38
  # Define dummy classes if SDK is not available, so the rest of the code doesn't break
39
  class Cerebras: pass
40
  class APIError(Exception): pass
41
  class APIConnectionError(APIError): pass
42
  class AuthenticationError(APIError): pass
43
 
 
 
 
 
 
 
 
 
44
  # --- Helper Functions (Actual API Interaction) ---
45
  def get_cebras_response(api_key, model_id, current_prompt, chat_history_for_api):
46
  """
 
98
  # --- Streamlit App ---
99
  st.set_page_config(page_title="Cerebras Chatbot", page_icon="πŸ€–")
100
 
101
+ st.write("Python Path:", sys.executable)
102
+ st.write("Python Version:", sys.version)
103
+
104
+ # Display detailed import debugging information
105
+ st.expander("πŸ” SDK Import Debug Information").write("\n".join(sdk_import_paths))
106
+
107
  st.title("πŸ€– Cerebras Powered Chatbot")
108
 
109
  if not CEREBRAS_SDK_AVAILABLE:
110
  st.error(
111
+ f"The Cerebras SDK is not installed. Please install it by running `pip install cerebras-cloud-sdk` in your terminal and restart the app.\n\nError details: {import_error_details}",
112
  icon="🚨"
113
  )
114
+
115
+ # Add a command to check the pip installation
116
+ st.code("python -m pip list | grep cerebras", language="bash")
117
  st.stop()
118
 
119
  st.caption("A Streamlit application for interacting with Cerebras models via `cerebras.cloud.sdk`.")
 
214
  if st.sidebar.button("Clear Chat History"):
215
  st.session_state.messages = []
216
  st.rerun()
217
+