Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-
|
|
| 31 |
# Set page config
|
| 32 |
st.set_page_config(page_title="Neural-Vision Enhanced", layout="wide")
|
| 33 |
|
| 34 |
-
# Custom CSS
|
| 35 |
st.markdown("""
|
| 36 |
<style>
|
| 37 |
:root {
|
|
@@ -42,62 +42,104 @@ st.markdown("""
|
|
| 42 |
--light-grey: #F3F4F6;
|
| 43 |
--white: #FFFFFF;
|
| 44 |
--border-grey: #E5E7EB;
|
|
|
|
| 45 |
}
|
| 46 |
.stApp {
|
| 47 |
-
background
|
| 48 |
font-family: 'Inter', sans-serif;
|
| 49 |
max-width: 1200px;
|
| 50 |
margin: 0 auto;
|
|
|
|
| 51 |
}
|
| 52 |
.header {
|
| 53 |
-
background
|
| 54 |
border-bottom: 2px solid var(--border-grey);
|
| 55 |
-
padding:
|
| 56 |
-
border-radius:
|
| 57 |
-
box-shadow: 0
|
| 58 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
.header-title {
|
| 61 |
color: var(--dark-blue);
|
| 62 |
-
font-size: 1.
|
| 63 |
-
font-weight:
|
| 64 |
margin: 0;
|
|
|
|
| 65 |
}
|
| 66 |
.header-subtitle {
|
| 67 |
color: var(--medium-grey);
|
| 68 |
-
font-size: 1rem;
|
| 69 |
-
margin-top:
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
.sidebar .sidebar-content {
|
| 72 |
-
background
|
| 73 |
-
border-radius:
|
| 74 |
-
box-shadow: 0
|
| 75 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
.chat-container {
|
| 78 |
-
background
|
| 79 |
-
border-radius:
|
| 80 |
-
box-shadow: 0
|
| 81 |
-
padding:
|
| 82 |
-
margin-top:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
.user-message {
|
| 85 |
-
background
|
| 86 |
color: var(--white);
|
| 87 |
-
border-radius:
|
| 88 |
-
padding:
|
| 89 |
margin-left: auto;
|
| 90 |
max-width: 80%;
|
| 91 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
.bot-message {
|
| 94 |
-
background
|
| 95 |
color: var(--medium-grey);
|
| 96 |
-
border-radius:
|
| 97 |
-
padding:
|
| 98 |
margin-right: auto;
|
| 99 |
max-width: 80%;
|
| 100 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
</style>
|
| 103 |
""", unsafe_allow_html=True)
|
|
@@ -109,6 +151,8 @@ if 'chat_history' not in st.session_state:
|
|
| 109 |
st.session_state.chat_history = []
|
| 110 |
if 'vector_store' not in st.session_state:
|
| 111 |
st.session_state.vector_store = None
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# Helper Functions
|
| 114 |
def convert_df_to_text(df):
|
|
@@ -142,7 +186,8 @@ def get_groq_response(prompt, mode, use_web_search=False):
|
|
| 142 |
docs = st.session_state.vector_store.similarity_search(prompt, k=3)
|
| 143 |
context = "\n\nDataset Context:\n" + "\n".join([f"- {doc.page_content}" for doc in docs])
|
| 144 |
|
| 145 |
-
if use_web_search:
|
|
|
|
| 146 |
tavily = TavilySearchResults(max_results=3)
|
| 147 |
web_results = tavily.invoke(prompt)
|
| 148 |
context += "\n\nWeb Search Results:\n" + "\n".join([f"- {res['content'][:200]}..." for res in web_results])
|
|
@@ -329,7 +374,16 @@ with st.sidebar:
|
|
| 329 |
st.session_state.active_page = page
|
| 330 |
st.markdown("---")
|
| 331 |
st.markdown("**Environment Setup**")
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
st.markdown("---")
|
| 334 |
st.markdown("v5.0 | © 2025 Neural-Vision")
|
| 335 |
|
|
|
|
| 31 |
# Set page config
|
| 32 |
st.set_page_config(page_title="Neural-Vision Enhanced", layout="wide")
|
| 33 |
|
| 34 |
+
# Updated Custom CSS with a modern feel
|
| 35 |
st.markdown("""
|
| 36 |
<style>
|
| 37 |
:root {
|
|
|
|
| 42 |
--light-grey: #F3F4F6;
|
| 43 |
--white: #FFFFFF;
|
| 44 |
--border-grey: #E5E7EB;
|
| 45 |
+
--gradient-bg: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
|
| 46 |
}
|
| 47 |
.stApp {
|
| 48 |
+
background: var(--gradient-bg);
|
| 49 |
font-family: 'Inter', sans-serif;
|
| 50 |
max-width: 1200px;
|
| 51 |
margin: 0 auto;
|
| 52 |
+
transition: all 0.3s ease;
|
| 53 |
}
|
| 54 |
.header {
|
| 55 |
+
background: linear-gradient(90deg, var(--white) 80%, var(--light-blue) 100%);
|
| 56 |
border-bottom: 2px solid var(--border-grey);
|
| 57 |
+
padding: 20px;
|
| 58 |
+
border-radius: 16px 16px 0 0;
|
| 59 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
|
| 60 |
text-align: center;
|
| 61 |
+
transition: transform 0.2s ease;
|
| 62 |
+
}
|
| 63 |
+
.header:hover {
|
| 64 |
+
transform: translateY(-2px);
|
| 65 |
}
|
| 66 |
.header-title {
|
| 67 |
color: var(--dark-blue);
|
| 68 |
+
font-size: 1.9rem;
|
| 69 |
+
font-weight: 800;
|
| 70 |
margin: 0;
|
| 71 |
+
letter-spacing: -0.5px;
|
| 72 |
}
|
| 73 |
.header-subtitle {
|
| 74 |
color: var(--medium-grey);
|
| 75 |
+
font-size: 1.1rem;
|
| 76 |
+
margin-top: 8px;
|
| 77 |
+
font-weight: 500;
|
| 78 |
+
opacity: 0.9;
|
| 79 |
}
|
| 80 |
.sidebar .sidebar-content {
|
| 81 |
+
background: var(--white);
|
| 82 |
+
border-radius: 16px;
|
| 83 |
+
box-shadow: 0 6px 16px rgba(0,0,0,0.12);
|
| 84 |
+
padding: 20px;
|
| 85 |
+
transition: box-shadow 0.3s ease;
|
| 86 |
+
}
|
| 87 |
+
.sidebar .sidebar-content:hover {
|
| 88 |
+
box-shadow: 0 8px 20px rgba(0,0,0,0.15);
|
| 89 |
}
|
| 90 |
.chat-container {
|
| 91 |
+
background: var(--white);
|
| 92 |
+
border-radius: 16px;
|
| 93 |
+
box-shadow: 0 6px 16px rgba(0,0,0,0.12);
|
| 94 |
+
padding: 20px;
|
| 95 |
+
margin-top: 25px;
|
| 96 |
+
transition: box-shadow 0.3s ease;
|
| 97 |
+
}
|
| 98 |
+
.chat-container:hover {
|
| 99 |
+
box-shadow: 0 8px 20px rgba(0,0,0,0.15);
|
| 100 |
}
|
| 101 |
.user-message {
|
| 102 |
+
background: linear-gradient(45deg, var(--primary-blue), #60A5FA);
|
| 103 |
color: var(--white);
|
| 104 |
+
border-radius: 20px 20px 6px 20px;
|
| 105 |
+
padding: 14px 18px;
|
| 106 |
margin-left: auto;
|
| 107 |
max-width: 80%;
|
| 108 |
+
margin-bottom: 12px;
|
| 109 |
+
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
|
| 110 |
+
transition: transform 0.2s ease;
|
| 111 |
+
}
|
| 112 |
+
.user-message:hover {
|
| 113 |
+
transform: scale(1.02);
|
| 114 |
}
|
| 115 |
.bot-message {
|
| 116 |
+
background: var(--light-grey);
|
| 117 |
color: var(--medium-grey);
|
| 118 |
+
border-radius: 20px 20px 20px 6px;
|
| 119 |
+
padding: 14px 18px;
|
| 120 |
margin-right: auto;
|
| 121 |
max-width: 80%;
|
| 122 |
+
margin-bottom: 12px;
|
| 123 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
| 124 |
+
transition: transform 0.2s ease;
|
| 125 |
+
}
|
| 126 |
+
.bot-message:hover {
|
| 127 |
+
transform: scale(1.02);
|
| 128 |
+
}
|
| 129 |
+
div.stButton > button {
|
| 130 |
+
background: var(--primary-blue);
|
| 131 |
+
color: var(--white);
|
| 132 |
+
border-radius: 12px;
|
| 133 |
+
padding: 10px 20px;
|
| 134 |
+
font-weight: 600;
|
| 135 |
+
border: none;
|
| 136 |
+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
|
| 137 |
+
transition: all 0.3s ease;
|
| 138 |
+
}
|
| 139 |
+
div.stButton > button:hover {
|
| 140 |
+
background: #2563EB;
|
| 141 |
+
transform: translateY(-2px);
|
| 142 |
+
box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
|
| 143 |
}
|
| 144 |
</style>
|
| 145 |
""", unsafe_allow_html=True)
|
|
|
|
| 151 |
st.session_state.chat_history = []
|
| 152 |
if 'vector_store' not in st.session_state:
|
| 153 |
st.session_state.vector_store = None
|
| 154 |
+
if 'tavily_api_key' not in st.session_state:
|
| 155 |
+
st.session_state.tavily_api_key = None
|
| 156 |
|
| 157 |
# Helper Functions
|
| 158 |
def convert_df_to_text(df):
|
|
|
|
| 186 |
docs = st.session_state.vector_store.similarity_search(prompt, k=3)
|
| 187 |
context = "\n\nDataset Context:\n" + "\n".join([f"- {doc.page_content}" for doc in docs])
|
| 188 |
|
| 189 |
+
if use_web_search and st.session_state.tavily_api_key:
|
| 190 |
+
os.environ["TAVILY_API_KEY"] = st.session_state.tavily_api_key
|
| 191 |
tavily = TavilySearchResults(max_results=3)
|
| 192 |
web_results = tavily.invoke(prompt)
|
| 193 |
context += "\n\nWeb Search Results:\n" + "\n".join([f"- {res['content'][:200]}..." for res in web_results])
|
|
|
|
| 374 |
st.session_state.active_page = page
|
| 375 |
st.markdown("---")
|
| 376 |
st.markdown("**Environment Setup**")
|
| 377 |
+
|
| 378 |
+
# Tavily API Key Input and Submit Button
|
| 379 |
+
tavily_api_input = st.text_input("Tavily API Key", type="password", help="Enter your Tavily API key for web search functionality")
|
| 380 |
+
if st.button("Submit API Key"):
|
| 381 |
+
if tavily_api_input:
|
| 382 |
+
st.session_state.tavily_api_key = tavily_api_input
|
| 383 |
+
st.success("Tavily API Key submitted successfully!")
|
| 384 |
+
else:
|
| 385 |
+
st.warning("Please enter a valid API key.")
|
| 386 |
+
|
| 387 |
st.markdown("---")
|
| 388 |
st.markdown("v5.0 | © 2025 Neural-Vision")
|
| 389 |
|