Spaces:
Sleeping
Sleeping
Commit
Β·
3e8b02e
1
Parent(s):
9d3174e
Upload 3 files
Browse files- pages/1_π_About.py +17 -0
- pages/2_π_Product_Discovery.py +124 -0
- pages/3_π_Question_And_Answering.py +30 -0
pages/1_π_About.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.set_page_config(page_title="About Semantic Search with LLMs", page_icon="π")
|
| 4 |
+
|
| 5 |
+
st.markdown("# About Semantic Search with LLMs")
|
| 6 |
+
st.sidebar.header("About Semantic Search with LLMs")
|
| 7 |
+
|
| 8 |
+
tab1, tab2 = st.tabs(["Product Discovery", "Question And Answering"])
|
| 9 |
+
with tab1:
|
| 10 |
+
st.header("Product Discovery")
|
| 11 |
+
with st.expander("Details"):
|
| 12 |
+
st.write("""Lorem Ipsum""")
|
| 13 |
+
|
| 14 |
+
with tab2:
|
| 15 |
+
st.header("Question And Answering")
|
| 16 |
+
with st.expander("Details"):
|
| 17 |
+
st.write("""Lorem Ipsum""")
|
pages/2_π_Product_Discovery.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
import ast
|
| 5 |
+
import math
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Product Disovery", page_icon="π")
|
| 9 |
+
|
| 10 |
+
st.markdown("# Product Discovery")
|
| 11 |
+
st.sidebar.header("Product Discovery")
|
| 12 |
+
|
| 13 |
+
def calculate_rows(x):
|
| 14 |
+
# Calculate the number of rows needed to incorporate x values in a grid with 4 columns
|
| 15 |
+
rows = math.ceil(x / 4)
|
| 16 |
+
return rows
|
| 17 |
+
|
| 18 |
+
def make_grid(cols, rows):
|
| 19 |
+
grid = [0]*cols
|
| 20 |
+
for i in range(cols):
|
| 21 |
+
with st.container():
|
| 22 |
+
grid[i] = st.columns(rows)
|
| 23 |
+
return grid
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def post_results(results, rows):
|
| 27 |
+
st.header("Results")
|
| 28 |
+
grid = make_grid(rows, 4)
|
| 29 |
+
count = 0
|
| 30 |
+
for j in range(rows):
|
| 31 |
+
for i in range(4):
|
| 32 |
+
with st.container():
|
| 33 |
+
product_name = results[count].get('attributes_name')
|
| 34 |
+
category_name = results[count].get('category_name')
|
| 35 |
+
brand_name = results[count].get('brand_name')
|
| 36 |
+
price = results[count].get('price_effective_min')
|
| 37 |
+
fynd_link = "https://www.gofynd.com/product/" + results[count].get('slug')
|
| 38 |
+
medias = ast.literal_eval(results[count].get('image_urls'))
|
| 39 |
+
if medias[0] == '':
|
| 40 |
+
pass
|
| 41 |
+
fynd_link = ""
|
| 42 |
+
else:
|
| 43 |
+
grid[j][i].image(medias[0], use_column_width=True)
|
| 44 |
+
grid[j][i].text(product_name)
|
| 45 |
+
grid[j][i].text(category_name)
|
| 46 |
+
grid[j][i].text(brand_name)
|
| 47 |
+
grid[j][i].text(price)
|
| 48 |
+
grid[j][i].markdown(f'<a href="{fynd_link}" target="_blank">{fynd_link}</a>', unsafe_allow_html=True)
|
| 49 |
+
count += 1
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def get_dummy_results(results):
|
| 53 |
+
for i in range(len(results), 48):
|
| 54 |
+
temp = {}
|
| 55 |
+
temp['attributes_name'] = ""
|
| 56 |
+
temp['category_name'] = ""
|
| 57 |
+
temp['brand_name'] = ""
|
| 58 |
+
temp['price_effective_min'] = ""
|
| 59 |
+
temp['slug'] = ""
|
| 60 |
+
temp['image_urls'] = "['']"
|
| 61 |
+
results.append(temp)
|
| 62 |
+
return results
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def search_image(title):
|
| 66 |
+
url = "http://localhost:8000/organization/000000001/search"
|
| 67 |
+
|
| 68 |
+
payload = json.dumps({
|
| 69 |
+
"search_type": "image",
|
| 70 |
+
"search_query": title,
|
| 71 |
+
"search_strategy": "milvus",
|
| 72 |
+
"vector_column": "vector"
|
| 73 |
+
})
|
| 74 |
+
headers = {
|
| 75 |
+
'Content-Type': 'application/json'
|
| 76 |
+
}
|
| 77 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
| 78 |
+
return response.status_code, response.json()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def search_text(title):
|
| 82 |
+
url = "http://localhost:8000/organization/000000001/search"
|
| 83 |
+
|
| 84 |
+
payload = json.dumps({
|
| 85 |
+
"search_type": "text",
|
| 86 |
+
"search_query": title,
|
| 87 |
+
"search_strategy": "milvus",
|
| 88 |
+
"vector_column": "vector"
|
| 89 |
+
})
|
| 90 |
+
headers = {
|
| 91 |
+
'Content-Type': 'application/json'
|
| 92 |
+
}
|
| 93 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
| 94 |
+
return response.status_code, response.json()
|
| 95 |
+
|
| 96 |
+
tab1, tab2 = st.tabs(["Search with Text", "Search with Image URL"])
|
| 97 |
+
with tab1:
|
| 98 |
+
st.header("Search with Text")
|
| 99 |
+
title = st.text_input('Enter search text', '')
|
| 100 |
+
if title:
|
| 101 |
+
response_status_code, response = search_text(title)
|
| 102 |
+
if response_status_code == 200:
|
| 103 |
+
print(f"Length of response: {len(response)}")
|
| 104 |
+
rows = 12
|
| 105 |
+
if len(response) < 48:
|
| 106 |
+
rows = calculate_rows(len(response))
|
| 107 |
+
response = get_dummy_results(response)
|
| 108 |
+
post_results(response, rows)
|
| 109 |
+
else:
|
| 110 |
+
st.write(f"Unable to find any results. Response Error Code: {response_status_code}")
|
| 111 |
+
|
| 112 |
+
with tab2:
|
| 113 |
+
st.header("Search with Image URL")
|
| 114 |
+
title = st.text_input('Enter image URL', '')
|
| 115 |
+
if title:
|
| 116 |
+
response_status_code, response = search_image(title)
|
| 117 |
+
if response_status_code == 200:
|
| 118 |
+
rows = 12
|
| 119 |
+
if len(response) < 48:
|
| 120 |
+
rows = calculate_rows(len(response))
|
| 121 |
+
response = get_dummy_results(response)
|
| 122 |
+
post_results(response, rows)
|
| 123 |
+
else:
|
| 124 |
+
st.write(f"Unable to find any results. Response Error Code: {response_status_code}")
|
pages/3_π_Question_And_Answering.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Question And Answering", page_icon="π")
|
| 6 |
+
|
| 7 |
+
st.markdown("# Question and Answering")
|
| 8 |
+
st.sidebar.header("Question and Answering")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def make_request(title):
|
| 12 |
+
URL = "https://api.cmlz0.de/service/flash/policy"
|
| 13 |
+
payload = json.dumps({
|
| 14 |
+
"question": title
|
| 15 |
+
})
|
| 16 |
+
headers = {'Content-Type': 'application/json'}
|
| 17 |
+
response = requests.request("POST", URL, headers=headers, data=payload)
|
| 18 |
+
return response.status_code, response.json()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
st.header("Enter your question")
|
| 22 |
+
title = st.text_input('Enter your question', '')
|
| 23 |
+
|
| 24 |
+
if title:
|
| 25 |
+
response_status_code, response = make_request(title)
|
| 26 |
+
if response_status_code == 200:
|
| 27 |
+
st.subheader('Generated answer')
|
| 28 |
+
st.text_area(label=' ', value=str(response.get('text')), height=350)
|
| 29 |
+
else:
|
| 30 |
+
st.write(f"Unable to find any results. Response Error Code: {response_status_code}")
|