Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -249,20 +249,21 @@ def display_session_id():
|
|
249 |
st.sidebar.markdown("Verwenden Sie diese ID als Referenz bei Mitteilungen oder Rückmeldungen.")
|
250 |
|
251 |
|
252 |
-
def query_pinecone(
|
253 |
-
# Assuming 'user_input' is the text from the user you want to query against the vector database
|
254 |
-
# And 'index' is your initialized Pinecone index
|
255 |
-
|
256 |
# Query Pinecone index for similar vectors
|
257 |
-
query_results = index.query(
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
|
263 |
-
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
|
|
266 |
|
267 |
|
268 |
def page1():
|
@@ -552,22 +553,27 @@ def page3():
|
|
552 |
col1, col2 = st.columns(2)
|
553 |
# Define buttons and their queries here as before
|
554 |
|
|
|
555 |
if query:
|
556 |
-
#
|
557 |
-
|
558 |
-
# Assuming query_pinecone is a function that sends the query to Pinecone and retrieves matches
|
559 |
|
|
|
|
|
|
|
|
|
|
|
560 |
for match in matches:
|
561 |
-
# Display matched texts and their scores
|
562 |
matched_text = match["metadata"].get("text", "No text available")
|
563 |
similarity_score = match["score"]
|
564 |
st.write(f"Matched Text: {matched_text} - Score: {similarity_score}")
|
565 |
|
566 |
-
#
|
567 |
-
|
568 |
-
|
569 |
except Exception as e:
|
570 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
|
|
|
|
571 |
|
572 |
def page4():
|
573 |
try:
|
|
|
249 |
st.sidebar.markdown("Verwenden Sie diese ID als Referenz bei Mitteilungen oder Rückmeldungen.")
|
250 |
|
251 |
|
252 |
+
def query_pinecone(vector, index, top_k=5):
|
|
|
|
|
|
|
253 |
# Query Pinecone index for similar vectors
|
254 |
+
query_results = index.query(vector=vector, top_k=top_k)
|
255 |
+
return query_results["matches"]
|
256 |
+
|
257 |
+
|
258 |
+
from sentence_transformers import SentenceTransformer
|
259 |
|
260 |
+
# Initialize the model
|
261 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
262 |
+
|
263 |
+
def text_to_vector(text):
|
264 |
+
# Convert input text to vector
|
265 |
+
embedding = model.encode(text)
|
266 |
+
return embedding.tolist() # Convert embedding to list
|
267 |
|
268 |
|
269 |
def page1():
|
|
|
553 |
col1, col2 = st.columns(2)
|
554 |
# Define buttons and their queries here as before
|
555 |
|
556 |
+
|
557 |
if query:
|
558 |
+
# Convert the query text to a vector
|
559 |
+
query_vector = text_to_vector(query)
|
|
|
560 |
|
561 |
+
# Query Pinecone with the vector
|
562 |
+
matches = query_pinecone(query_vector, index, top_k=5)
|
563 |
+
|
564 |
+
# Assuming query_pinecone is defined elsewhere and connects to Pinecone correctly
|
565 |
+
# Display the results
|
566 |
for match in matches:
|
|
|
567 |
matched_text = match["metadata"].get("text", "No text available")
|
568 |
similarity_score = match["score"]
|
569 |
st.write(f"Matched Text: {matched_text} - Score: {similarity_score}")
|
570 |
|
571 |
+
# Your existing logic to handle chat history and responses...
|
572 |
+
|
|
|
573 |
except Exception as e:
|
574 |
st.error(f"Upsi, an unexpected error occurred: {e}")
|
575 |
+
|
576 |
+
|
577 |
|
578 |
def page4():
|
579 |
try:
|