Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import requests
|
5 |
+
|
6 |
+
st.title("Prompt Search Engine")
|
7 |
+
|
8 |
+
query = st.text_input("Enter your query:")
|
9 |
+
use_pinecone = st.radio(
|
10 |
+
"Choose search method:",
|
11 |
+
('Pinecone Vector Search', 'Cosine Similarity')
|
12 |
+
)
|
13 |
+
n = st.number_input("Number of results:", min_value=1, max_value=20, value=5)
|
14 |
+
|
15 |
+
if st.button("Search"):
|
16 |
+
search_method = use_pinecone == 'Pinecone Vector Search'
|
17 |
+
response = requests.post("http://localhost:5000/search", json={"query": query, "n": n, "use_pinecone": search_method})
|
18 |
+
|
19 |
+
# Log the response for debugging
|
20 |
+
st.write("Response Status Code:", response.status_code)
|
21 |
+
|
22 |
+
try:
|
23 |
+
results = response.json()
|
24 |
+
# for score, prompt in results:
|
25 |
+
# st.write(f"{score:.2f} - {prompt}")
|
26 |
+
for result in results:
|
27 |
+
score = float(result['score'])
|
28 |
+
prompt = result['prompt']
|
29 |
+
st.write(f"{score:.2f} - {prompt}")
|
30 |
+
except json.JSONDecodeError as e:
|
31 |
+
st.error(f"Failed to decode JSON response: {e}")
|
32 |
+
st.write(response.content)
|