Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ st.set_page_config(
|
|
| 20 |
)
|
| 21 |
|
| 22 |
def init_huggingface_directories():
|
| 23 |
-
"""Initialize directory structure for Hugging Face Spaces
|
| 24 |
if os.environ.get('SPACE_ID'):
|
| 25 |
base_dir = Path("/data")
|
| 26 |
else:
|
|
@@ -32,39 +32,42 @@ def init_huggingface_directories():
|
|
| 32 |
'vectors': base_dir / "vectors",
|
| 33 |
'nltk_data': base_dir / "nltk_data",
|
| 34 |
'temp': base_dir / "temp",
|
| 35 |
-
'logs': base_dir / "logs"
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
dir_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 40 |
|
| 41 |
return directories
|
| 42 |
|
| 43 |
-
@st.cache_resource(show_spinner=False)
|
| 44 |
-
def initialize_nltk(nltk_data_dir):
|
| 45 |
-
"""Initialize NLTK resources silently."""
|
| 46 |
-
nltk.data.path.append(str(nltk_data_dir))
|
| 47 |
-
resources = ['punkt', 'averaged_perceptron_tagger', 'maxent_ne_chunker', 'words', 'stopwords']
|
| 48 |
-
for resource in resources:
|
| 49 |
-
try:
|
| 50 |
-
nltk.download(resource, download_dir=str(nltk_data_dir), quiet=True)
|
| 51 |
-
except Exception:
|
| 52 |
-
pass
|
| 53 |
-
return True
|
| 54 |
-
|
| 55 |
@st.cache_resource(show_spinner=False)
|
| 56 |
def init_components():
|
| 57 |
"""Initialize all components silently."""
|
| 58 |
try:
|
|
|
|
| 59 |
directories = init_huggingface_directories()
|
| 60 |
-
initialize_nltk(directories['nltk_data'])
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
try:
|
| 63 |
nlp = spacy.load("en_core_web_sm")
|
| 64 |
except OSError:
|
| 65 |
os.system("python -m spacy download en_core_web_sm > /dev/null 2>&1")
|
| 66 |
nlp = spacy.load("en_core_web_sm")
|
| 67 |
|
|
|
|
| 68 |
case_manager = CaseManager(base_path=str(directories['cases']))
|
| 69 |
vector_store = VectorStore(storage_path=str(directories['vectors']))
|
| 70 |
doc_processor = DocumentProcessor(base_path=str(directories['data']))
|
|
@@ -72,7 +75,7 @@ def init_components():
|
|
| 72 |
return case_manager, vector_store, doc_processor
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
-
st.error("Failed to initialize components")
|
| 76 |
raise
|
| 77 |
|
| 78 |
def main():
|
|
@@ -113,10 +116,6 @@ def main():
|
|
| 113 |
</style>
|
| 114 |
""", unsafe_allow_html=True)
|
| 115 |
|
| 116 |
-
# Header
|
| 117 |
-
st.markdown("<h1 class='main-header'>SuoMoto.AI</h1>", unsafe_allow_html=True)
|
| 118 |
-
st.markdown("<p class='main-tagline'>Empowering Legal Intelligence: Automate, Analyze, Act.</p>", unsafe_allow_html=True)
|
| 119 |
-
|
| 120 |
# Initialize components
|
| 121 |
case_manager, vector_store, doc_processor = init_components()
|
| 122 |
|
|
@@ -124,6 +123,10 @@ def main():
|
|
| 124 |
if 'user_authenticated' not in st.session_state:
|
| 125 |
st.session_state.user_authenticated = False
|
| 126 |
st.session_state.current_user = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
# Sidebar navigation with admin access
|
| 129 |
if st.session_state.user_authenticated:
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
def init_huggingface_directories():
|
| 23 |
+
"""Initialize directory structure for Hugging Face Spaces."""
|
| 24 |
if os.environ.get('SPACE_ID'):
|
| 25 |
base_dir = Path("/data")
|
| 26 |
else:
|
|
|
|
| 32 |
'vectors': base_dir / "vectors",
|
| 33 |
'nltk_data': base_dir / "nltk_data",
|
| 34 |
'temp': base_dir / "temp",
|
| 35 |
+
'logs': base_dir / "logs",
|
| 36 |
+
'prompts': base_dir / "prompts",
|
| 37 |
+
'ontology': base_dir / "ontology"
|
| 38 |
}
|
| 39 |
|
| 40 |
+
# Create directories
|
| 41 |
+
for dir_name, dir_path in directories.items():
|
| 42 |
dir_path.mkdir(parents=True, exist_ok=True)
|
| 43 |
+
st.sidebar.write(f"✓ {dir_name} directory ready")
|
| 44 |
|
| 45 |
return directories
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
@st.cache_resource(show_spinner=False)
|
| 48 |
def init_components():
|
| 49 |
"""Initialize all components silently."""
|
| 50 |
try:
|
| 51 |
+
# Set up directories
|
| 52 |
directories = init_huggingface_directories()
|
|
|
|
| 53 |
|
| 54 |
+
# Initialize NLTK
|
| 55 |
+
nltk.data.path.append(str(directories['nltk_data']))
|
| 56 |
+
resources = ['punkt', 'averaged_perceptron_tagger', 'maxent_ne_chunker', 'words', 'stopwords']
|
| 57 |
+
for resource in resources:
|
| 58 |
+
try:
|
| 59 |
+
nltk.download(resource, download_dir=str(directories['nltk_data']), quiet=True)
|
| 60 |
+
except Exception:
|
| 61 |
+
pass
|
| 62 |
+
|
| 63 |
+
# Initialize spaCy
|
| 64 |
try:
|
| 65 |
nlp = spacy.load("en_core_web_sm")
|
| 66 |
except OSError:
|
| 67 |
os.system("python -m spacy download en_core_web_sm > /dev/null 2>&1")
|
| 68 |
nlp = spacy.load("en_core_web_sm")
|
| 69 |
|
| 70 |
+
# Initialize components with proper paths
|
| 71 |
case_manager = CaseManager(base_path=str(directories['cases']))
|
| 72 |
vector_store = VectorStore(storage_path=str(directories['vectors']))
|
| 73 |
doc_processor = DocumentProcessor(base_path=str(directories['data']))
|
|
|
|
| 75 |
return case_manager, vector_store, doc_processor
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
+
st.error(f"Failed to initialize components: {str(e)}")
|
| 79 |
raise
|
| 80 |
|
| 81 |
def main():
|
|
|
|
| 116 |
</style>
|
| 117 |
""", unsafe_allow_html=True)
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# Initialize components
|
| 120 |
case_manager, vector_store, doc_processor = init_components()
|
| 121 |
|
|
|
|
| 123 |
if 'user_authenticated' not in st.session_state:
|
| 124 |
st.session_state.user_authenticated = False
|
| 125 |
st.session_state.current_user = None
|
| 126 |
+
|
| 127 |
+
# Header
|
| 128 |
+
st.markdown("<h1 class='main-header'>SuoMoto.AI</h1>", unsafe_allow_html=True)
|
| 129 |
+
st.markdown("<p class='main-tagline'>Empowering Legal Intelligence: Automate, Analyze, Act.</p>", unsafe_allow_html=True)
|
| 130 |
|
| 131 |
# Sidebar navigation with admin access
|
| 132 |
if st.session_state.user_authenticated:
|