Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
import re
|
3 |
-
from langchain_groq import ChatGroq
|
4 |
-
from langchain import hub
|
5 |
-
from langchain_chroma import Chroma
|
6 |
-
from langchain_community.document_loaders import WebBaseLoader
|
7 |
-
from langchain_core.output_parsers import StrOutputParser
|
8 |
-
from langchain_core.runnables import RunnablePassthrough
|
9 |
-
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
10 |
-
from sentence_transformers import SentenceTransformer
|
11 |
-
import bs4
|
12 |
-
import torch
|
13 |
import os
|
14 |
|
15 |
# Sidebar Style with Multicolored Background
|
@@ -22,6 +12,20 @@ sidebar_bg_style = """
|
|
22 |
"""
|
23 |
st.markdown(sidebar_bg_style, unsafe_allow_html=True)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# Sidebar: Input for URL and API keys
|
26 |
st.sidebar.title("Settings")
|
27 |
|
@@ -35,37 +39,26 @@ if url_input:
|
|
35 |
else:
|
36 |
st.sidebar.markdown('<p style="color:red; font-weight:bold;">Invalid URL, please enter a valid one</p>', unsafe_allow_html=True)
|
37 |
|
|
|
|
|
|
|
38 |
# Input fields for API keys with placeholders and helper text
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# Submit button for API keys with a success/warning message
|
43 |
if st.sidebar.button("Submit API Keys"):
|
44 |
-
if api_key_1 and api_key_2:
|
45 |
os.environ["LANGCHAIN_API_KEY"] = api_key_1
|
46 |
os.environ["GROQ_API_KEY"] = api_key_2
|
47 |
-
st.sidebar.markdown('<p style="color:green; font-weight:bold;">
|
48 |
else:
|
49 |
-
st.sidebar.markdown('<p style="color:red; font-weight:bold;">Please fill in both API keys</p>', unsafe_allow_html=True)
|
50 |
-
|
51 |
-
# Main Section with Multicolored Background and Chatbot Title
|
52 |
-
main_bg_style = """
|
53 |
-
<style>
|
54 |
-
.main-content {
|
55 |
-
background: linear-gradient(135deg, #ff9a9e, #fad0c4, #fbc2eb, #a18cd1);
|
56 |
-
padding: 20px;
|
57 |
-
border-radius: 10px;
|
58 |
-
color: #333; /* Ensure text is visible against the background */
|
59 |
-
}
|
60 |
-
.stTextInput>div>div>input {
|
61 |
-
border: 1px solid #ccc; /* Style input borders */
|
62 |
-
}
|
63 |
-
</style>
|
64 |
-
"""
|
65 |
-
st.markdown(main_bg_style, unsafe_allow_html=True)
|
66 |
-
|
67 |
-
# Wrapper for main content to apply background style
|
68 |
-
st.markdown('<div class="main-content">', unsafe_allow_html=True)
|
69 |
|
70 |
# Title of the chatbot
|
71 |
st.markdown('<h1 style="color:#4CAF50; font-weight:bold;">🤖 Chatbot with URL-based Document Retrieval</h1>', unsafe_allow_html=True)
|
@@ -77,11 +70,9 @@ query = st.text_input("Ask a question based on the blog post", placeholder="Type
|
|
77 |
if 'chat_history' not in st.session_state:
|
78 |
st.session_state['chat_history'] = []
|
79 |
|
80 |
-
#
|
81 |
if st.button("Submit Query"):
|
82 |
-
if
|
83 |
-
st.markdown('<p style="color:red; font-weight:bold;">Please enter a question before submitting.</p>', unsafe_allow_html=True)
|
84 |
-
elif url_input:
|
85 |
# Blog loading logic based on user input URL
|
86 |
loader = WebBaseLoader(
|
87 |
web_paths=(url_input,), # Use the user-input URL
|
@@ -140,7 +131,4 @@ if st.button("Submit Query"):
|
|
140 |
# Display chat history
|
141 |
for q, r in st.session_state['chat_history']:
|
142 |
st.write(f"**User:** {q}")
|
143 |
-
st.write(f"**Bot:** {r}")
|
144 |
-
|
145 |
-
# Close the main content wrapper
|
146 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
# Sidebar Style with Multicolored Background
|
|
|
12 |
"""
|
13 |
st.markdown(sidebar_bg_style, unsafe_allow_html=True)
|
14 |
|
15 |
+
# Main Content Style with Multicolored Background
|
16 |
+
main_bg_style = """
|
17 |
+
<style>
|
18 |
+
.main .block-container {
|
19 |
+
background: linear-gradient(135deg, #ff9a9e, #fad0c4, #fbc2eb, #a18cd1);
|
20 |
+
padding: 2rem;
|
21 |
+
}
|
22 |
+
.css-18e3th9 {
|
23 |
+
background: linear-gradient(135deg, #ff9a9e, #fad0c4, #fbc2eb, #a18cd1);
|
24 |
+
}
|
25 |
+
</style>
|
26 |
+
"""
|
27 |
+
st.markdown(main_bg_style, unsafe_allow_html=True)
|
28 |
+
|
29 |
# Sidebar: Input for URL and API keys
|
30 |
st.sidebar.title("Settings")
|
31 |
|
|
|
39 |
else:
|
40 |
st.sidebar.markdown('<p style="color:red; font-weight:bold;">Invalid URL, please enter a valid one</p>', unsafe_allow_html=True)
|
41 |
|
42 |
+
# Option to use pre-provided API keys
|
43 |
+
use_preprovided_keys = st.sidebar.checkbox("Use pre-provided API keys")
|
44 |
+
|
45 |
# Input fields for API keys with placeholders and helper text
|
46 |
+
if not use_preprovided_keys:
|
47 |
+
api_key_1 = st.sidebar.text_input("Enter LangChain API Key", type="password", placeholder="Enter your LangChain API Key", help="Please enter a valid LangChain API key here")
|
48 |
+
api_key_2 = st.sidebar.text_input("Enter Groq API Key", type="password", placeholder="Enter your Groq API Key", help="Please enter your Groq API key here")
|
49 |
+
else:
|
50 |
+
api_key_1 = "your-preprovided-langchain-api-key" # Replace with your actual pre-provided key
|
51 |
+
api_key_2 = "your-preprovided-groq-api-key" # Replace with your actual pre-provided key
|
52 |
+
st.sidebar.markdown('<p style="color:blue; font-weight:bold;">Using pre-provided API keys</p>', unsafe_allow_html=True)
|
53 |
|
54 |
# Submit button for API keys with a success/warning message
|
55 |
if st.sidebar.button("Submit API Keys"):
|
56 |
+
if use_preprovided_keys or (api_key_1 and api_key_2):
|
57 |
os.environ["LANGCHAIN_API_KEY"] = api_key_1
|
58 |
os.environ["GROQ_API_KEY"] = api_key_2
|
59 |
+
st.sidebar.markdown('<p style="color:green; font-weight:bold;">API keys are set</p>', unsafe_allow_html=True)
|
60 |
else:
|
61 |
+
st.sidebar.markdown('<p style="color:red; font-weight:bold;">Please fill in both API keys or select the option to use pre-provided keys</p>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Title of the chatbot
|
64 |
st.markdown('<h1 style="color:#4CAF50; font-weight:bold;">🤖 Chatbot with URL-based Document Retrieval</h1>', unsafe_allow_html=True)
|
|
|
70 |
if 'chat_history' not in st.session_state:
|
71 |
st.session_state['chat_history'] = []
|
72 |
|
73 |
+
# Submit button for chat
|
74 |
if st.button("Submit Query"):
|
75 |
+
if query and url_input:
|
|
|
|
|
76 |
# Blog loading logic based on user input URL
|
77 |
loader = WebBaseLoader(
|
78 |
web_paths=(url_input,), # Use the user-input URL
|
|
|
131 |
# Display chat history
|
132 |
for q, r in st.session_state['chat_history']:
|
133 |
st.write(f"**User:** {q}")
|
134 |
+
st.write(f"**Bot:** {r}")
|
|
|
|
|
|