Spaces:
Runtime error
Runtime error
Fix langchain dependency for HF Space
Browse files
app.py
CHANGED
|
@@ -12,6 +12,14 @@ st.set_page_config(
|
|
| 12 |
initial_sidebar_state="expanded"
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Custom CSS for better styling
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
|
@@ -50,14 +58,6 @@ st.markdown("""
|
|
| 50 |
</style>
|
| 51 |
""", unsafe_allow_html=True)
|
| 52 |
|
| 53 |
-
# Initialize session state
|
| 54 |
-
if 'messages' not in st.session_state:
|
| 55 |
-
st.session_state.messages = []
|
| 56 |
-
if 'rag_system' not in st.session_state:
|
| 57 |
-
st.session_state.rag_system = None
|
| 58 |
-
if 'initialized' not in st.session_state:
|
| 59 |
-
st.session_state.initialized = False
|
| 60 |
-
|
| 61 |
# RAG System Functions
|
| 62 |
def initialize_rag_system(api_key):
|
| 63 |
"""Initialize the RAG system with all components"""
|
|
@@ -71,8 +71,6 @@ def initialize_rag_system(api_key):
|
|
| 71 |
import chromadb
|
| 72 |
from chromadb.config import Settings
|
| 73 |
import google.generativeai as genai
|
| 74 |
-
from datasets import load_dataset
|
| 75 |
-
from tqdm import tqdm
|
| 76 |
import re
|
| 77 |
except ImportError as e:
|
| 78 |
st.error(f"Import error: {e}")
|
|
@@ -93,7 +91,7 @@ def initialize_rag_system(api_key):
|
|
| 93 |
except:
|
| 94 |
collection = chroma_client.create_collection(
|
| 95 |
name=collection_name,
|
| 96 |
-
metadata={"description": "ML/AI knowledge base
|
| 97 |
)
|
| 98 |
|
| 99 |
# Check if collection already has data
|
|
@@ -149,7 +147,7 @@ def initialize_rag_system(api_key):
|
|
| 149 |
metadatas=chunk_metadatas
|
| 150 |
)
|
| 151 |
|
| 152 |
-
# Initialize Gemini using direct API
|
| 153 |
genai.configure(api_key=api_key)
|
| 154 |
|
| 155 |
return {
|
|
|
|
| 12 |
initial_sidebar_state="expanded"
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# Initialize session state immediately
|
| 16 |
+
if 'messages' not in st.session_state:
|
| 17 |
+
st.session_state.messages = []
|
| 18 |
+
if 'rag_system' not in st.session_state:
|
| 19 |
+
st.session_state.rag_system = None
|
| 20 |
+
if 'initialized' not in st.session_state:
|
| 21 |
+
st.session_state.initialized = False
|
| 22 |
+
|
| 23 |
# Custom CSS for better styling
|
| 24 |
st.markdown("""
|
| 25 |
<style>
|
|
|
|
| 58 |
</style>
|
| 59 |
""", unsafe_allow_html=True)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
# RAG System Functions
|
| 62 |
def initialize_rag_system(api_key):
|
| 63 |
"""Initialize the RAG system with all components"""
|
|
|
|
| 71 |
import chromadb
|
| 72 |
from chromadb.config import Settings
|
| 73 |
import google.generativeai as genai
|
|
|
|
|
|
|
| 74 |
import re
|
| 75 |
except ImportError as e:
|
| 76 |
st.error(f"Import error: {e}")
|
|
|
|
| 91 |
except:
|
| 92 |
collection = chroma_client.create_collection(
|
| 93 |
name=collection_name,
|
| 94 |
+
metadata={"description": "ML/AI knowledge base"}
|
| 95 |
)
|
| 96 |
|
| 97 |
# Check if collection already has data
|
|
|
|
| 147 |
metadatas=chunk_metadatas
|
| 148 |
)
|
| 149 |
|
| 150 |
+
# Initialize Gemini using direct API
|
| 151 |
genai.configure(api_key=api_key)
|
| 152 |
|
| 153 |
return {
|