Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,9 +16,8 @@ if "messages" not in st.session_state:
|
|
16 |
st.session_state.messages = []
|
17 |
if "query" not in st.session_state:
|
18 |
st.session_state.query = ""
|
19 |
-
|
20 |
-
|
21 |
-
st.image("banner_policy.jpg", use_container_width=True)
|
22 |
|
23 |
##############################################
|
24 |
##
|
@@ -77,19 +76,6 @@ def get_credentials():
|
|
77 |
from ibm_watsonx_ai.client import APIClient
|
78 |
from ibm_watsonx_ai.foundation_models.embeddings.sentence_transformer_embeddings import SentenceTransformerEmbeddings
|
79 |
|
80 |
-
if "client" not in st.session_state:
|
81 |
-
with st.spinner("β³ Waking the wizard ..."):
|
82 |
-
IBM_token()
|
83 |
-
wml_credentials = get_credentials()
|
84 |
-
st.session_state.client = APIClient(credentials=wml_credentials, project_id=os.getenv("IBM_PROJECT_ID"))
|
85 |
-
|
86 |
-
#vector_index_details = st.session_state.client.data_assets.get_details(VECTOR_DB)
|
87 |
-
#st.session_state.vector_index_properties = vector_index_details["entity"]["vector_index"]
|
88 |
-
#st.session_state.top_n = 20 if st.session_state.vector_index_properties["settings"].get("rerank") else int(st.session_state.vector_index_properties["settings"]["top_k"])
|
89 |
-
|
90 |
-
st.session_state.emb = SentenceTransformerEmbeddings('sentence-transformers/all-MiniLM-L6-v2')
|
91 |
-
st.session_state.top_n = 10
|
92 |
-
|
93 |
def rerank( client, documents, query, top_n ):
|
94 |
from ibm_watsonx_ai.foundation_models import Rerank
|
95 |
|
@@ -176,10 +162,6 @@ def hydrate_chromadb():
|
|
176 |
)
|
177 |
return collection
|
178 |
|
179 |
-
if "chroma_collection" not in st.session_state:
|
180 |
-
with st.spinner("β³ Dusting off the scroll books ..."):
|
181 |
-
st.session_state.chroma_collection = hydrate_chromadb()
|
182 |
-
|
183 |
def proximity_search( question ):
|
184 |
query_vectors = st.session_state.emb.embed_query(question)
|
185 |
query_result = st.session_state.chroma_collection.query(
|
@@ -213,12 +195,16 @@ def do_query(query):
|
|
213 |
#st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
214 |
#st.session_state.query = query
|
215 |
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
|
|
|
|
|
|
221 |
|
|
|
222 |
st.sidebar.title("π Synergy Scrolling")
|
223 |
st.sidebar.write(
|
224 |
"Synergy Scrolling analyzes policies and finds relevant past projects. "
|
@@ -226,8 +212,52 @@ st.sidebar.write(
|
|
226 |
"previous LabLab hackathons."
|
227 |
)
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
query = ""
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
# Suggested search queries as buttons
|
232 |
col1, col2, col3 = st.columns(3)
|
233 |
|
|
|
16 |
st.session_state.messages = []
|
17 |
if "query" not in st.session_state:
|
18 |
st.session_state.query = ""
|
19 |
+
if "extended_query" not in st.session_state:
|
20 |
+
st.session_state.extended_query = ""
|
|
|
21 |
|
22 |
##############################################
|
23 |
##
|
|
|
76 |
from ibm_watsonx_ai.client import APIClient
|
77 |
from ibm_watsonx_ai.foundation_models.embeddings.sentence_transformer_embeddings import SentenceTransformerEmbeddings
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
def rerank( client, documents, query, top_n ):
|
80 |
from ibm_watsonx_ai.foundation_models import Rerank
|
81 |
|
|
|
162 |
)
|
163 |
return collection
|
164 |
|
|
|
|
|
|
|
|
|
165 |
def proximity_search( question ):
|
166 |
query_vectors = st.session_state.emb.embed_query(question)
|
167 |
query_result = st.session_state.chroma_collection.query(
|
|
|
195 |
#st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
196 |
#st.session_state.query = query
|
197 |
|
198 |
+
############################
|
199 |
+
##
|
200 |
+
## UI
|
201 |
+
##
|
202 |
+
############################
|
203 |
+
|
204 |
+
# Load the banner image from the same directory
|
205 |
+
st.image("banner_policy.jpg", use_container_width=True)
|
206 |
|
207 |
+
# set up sidebar
|
208 |
st.sidebar.title("π Synergy Scrolling")
|
209 |
st.sidebar.write(
|
210 |
"Synergy Scrolling analyzes policies and finds relevant past projects. "
|
|
|
212 |
"previous LabLab hackathons."
|
213 |
)
|
214 |
|
215 |
+
################ INIT
|
216 |
+
|
217 |
+
if "client" not in st.session_state:
|
218 |
+
with st.spinner("β³ Waking the wizard ..."):
|
219 |
+
IBM_token()
|
220 |
+
wml_credentials = get_credentials()
|
221 |
+
st.session_state.client = APIClient(credentials=wml_credentials, project_id=os.getenv("IBM_PROJECT_ID"))
|
222 |
+
|
223 |
+
#vector_index_details = st.session_state.client.data_assets.get_details(VECTOR_DB)
|
224 |
+
#st.session_state.vector_index_properties = vector_index_details["entity"]["vector_index"]
|
225 |
+
#st.session_state.top_n = 20 if st.session_state.vector_index_properties["settings"].get("rerank") else int(st.session_state.vector_index_properties["settings"]["top_k"])
|
226 |
+
|
227 |
+
st.session_state.emb = SentenceTransformerEmbeddings('sentence-transformers/all-MiniLM-L6-v2')
|
228 |
+
st.session_state.top_n = 10
|
229 |
+
|
230 |
+
if "chroma_collection" not in st.session_state:
|
231 |
+
with st.spinner("β³ Dusting off the scroll books ..."):
|
232 |
+
st.session_state.chroma_collection = hydrate_chromadb()
|
233 |
+
|
234 |
query = ""
|
235 |
|
236 |
+
################ main UI
|
237 |
+
|
238 |
+
st.title("π Policy Scroll")
|
239 |
+
st.subheader("AI-Powered Project & Policy Matching")
|
240 |
+
st.write("Explore the Lab Lab Library to find relevant past projects that align with your policy or new initiative.")
|
241 |
+
|
242 |
+
################ sidebar UI
|
243 |
+
|
244 |
+
policy_input = st.sidebar.text_area("π Enter Your Policy or Business Idea:")
|
245 |
+
|
246 |
+
if st.sidebar.button("π Connect with IBM Chat"):
|
247 |
+
if policy_input.strip():
|
248 |
+
prompt = f"Define search criteria for projects to implement: {policy_input}"
|
249 |
+
|
250 |
+
# Get response from IBM
|
251 |
+
with st.spinner("Analyzing..."):
|
252 |
+
result = IBM_chat(prompt)
|
253 |
+
query = "Find 3 projects that best match these criteria: " + result
|
254 |
+
st.session_state["extended_query"] = query
|
255 |
+
else:
|
256 |
+
st.sidebar.warning("Please enter a policy or business idea first!")
|
257 |
+
|
258 |
+
# Display AI result in another textarea
|
259 |
+
st.sidebar.text_area("π‘ Extended query:", value=st.session_state.get("extended_query", ""), height=150)
|
260 |
+
|
261 |
# Suggested search queries as buttons
|
262 |
col1, col2, col3 = st.columns(3)
|
263 |
|