Anirudh Esthuri commited on
Commit
42f0aac
Β·
1 Parent(s): 4e58ae3

Add error handling for imports to diagnose blank screen issue

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -1,16 +1,37 @@
1
  import os
 
 
2
  from typing import cast
3
 
4
  import streamlit as st
5
- from gateway_client import delete_profile, ingest_and_rewrite
6
- from llm import chat, set_model
7
- from model_config import MODEL_CHOICES, MODEL_TO_PROVIDER
8
 
9
  # Configure Streamlit for Hugging Face Spaces
10
  # Port is set via command line argument in Dockerfile
11
  # Don't set STREAMLIT_SERVER_PORT here to avoid conflicts
12
  os.environ["STREAMLIT_SERVER_ADDRESS"] = "0.0.0.0"
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def rewrite_message(
16
  msg: str, persona_name: str, show_rationale: bool, skip_rewrite: bool, provider: str = "openai"
@@ -40,6 +61,15 @@ def rewrite_message(
40
  # Page setup & CSS
41
  # ──────────────────────────────────────────────────────────────
42
  st.set_page_config(page_title="MemMachine Chatbot", layout="wide")
 
 
 
 
 
 
 
 
 
43
  try:
44
  with open("./styles.css") as f:
45
  st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
 
1
  import os
2
+ import sys
3
+ import traceback
4
  from typing import cast
5
 
6
  import streamlit as st
 
 
 
7
 
8
  # Configure Streamlit for Hugging Face Spaces
9
  # Port is set via command line argument in Dockerfile
10
  # Don't set STREAMLIT_SERVER_PORT here to avoid conflicts
11
  os.environ["STREAMLIT_SERVER_ADDRESS"] = "0.0.0.0"
12
 
13
+ # Try to import modules with error handling
14
+ try:
15
+ from gateway_client import delete_profile, ingest_and_rewrite
16
+ from llm import chat, set_model
17
+ from model_config import MODEL_CHOICES, MODEL_TO_PROVIDER
18
+ IMPORTS_SUCCESSFUL = True
19
+ except Exception as e:
20
+ IMPORTS_SUCCESSFUL = False
21
+ IMPORT_ERROR = str(e)
22
+ IMPORT_TRACEBACK = traceback.format_exc()
23
+ # Create dummy functions to prevent NameError
24
+ def delete_profile(user_id: str) -> bool:
25
+ return False
26
+ def ingest_and_rewrite(user_id: str, query: str, model_type: str = "openai") -> str:
27
+ return query
28
+ def chat(messages, persona):
29
+ return "Error: Could not initialize chat function", 0, 0, 0
30
+ def set_model(model_id: str) -> None:
31
+ pass
32
+ MODEL_CHOICES = ["gpt-4.1-mini"]
33
+ MODEL_TO_PROVIDER = {"gpt-4.1-mini": "openai"}
34
+
35
 
36
  def rewrite_message(
37
  msg: str, persona_name: str, show_rationale: bool, skip_rewrite: bool, provider: str = "openai"
 
61
  # Page setup & CSS
62
  # ──────────────────────────────────────────────────────────────
63
  st.set_page_config(page_title="MemMachine Chatbot", layout="wide")
64
+
65
+ # Show import errors if any
66
+ if not IMPORTS_SUCCESSFUL:
67
+ st.error("⚠️ Application Error: Failed to import required modules")
68
+ st.error(f"Error: {IMPORT_ERROR}")
69
+ with st.expander("Show full error details"):
70
+ st.code(IMPORT_TRACEBACK)
71
+ st.stop()
72
+
73
  try:
74
  with open("./styles.css") as f:
75
  st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)