Skip to content

Commit b2038be

Browse files
berkecanrizaiManul from Pathway
authored andcommitted
fix and some cleanups from migration (#7287)
GitOrigin-RevId: 7900bcadc60c5b2291cce5e50f1e400b6a6f4f2e
1 parent 7ddca2a commit b2038be

File tree

1 file changed

+11
-32
lines changed
  • examples/pipelines/slides_ai_search/ui

1 file changed

+11
-32
lines changed

examples/pipelines/slides_ai_search/ui/ui.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
from dotenv import load_dotenv
1313
from pathway.xpacks.llm.question_answering import RAGClient
1414

15-
try:
16-
load_dotenv()
17-
except Exception:
18-
pass
15+
load_dotenv()
1916

2017
PATHWAY_HOST = os.environ.get("PATHWAY_HOST", "app")
2118
PATHWAY_PORT = os.environ.get("PATHWAY_PORT", 8000)
@@ -81,7 +78,7 @@
8178
)
8279

8380

84-
question = st.text_input(label="", placeholder="Why buy")
81+
question = st.text_input(label="", placeholder="What are you searching for?")
8582

8683

8784
def get_options_list(metadata_list: list[dict], opt_key: str) -> list:
@@ -93,7 +90,7 @@ def get_options_list(metadata_list: list[dict], opt_key: str) -> list:
9390
def parse_slide_id_components(slide_id: str) -> tuple[str, int, int]:
9491
stem = PurePosixPath(slide_id).stem
9592
(name_page, _, page_count) = stem.rpartition("_")
96-
(name, _, page) = stem.rpartition("_")
93+
(name, _, page) = name_page.rpartition("_")
9794
return (name, int(page), int(page_count))
9895

9996

@@ -149,10 +146,10 @@ def get_slide_link(file_name, page_num=None) -> str:
149146
return image_url
150147

151148

152-
def get_all_drive_files() -> list[str]:
153-
logger.info("request get_all_drive_files")
154-
response = requests.get(file_server_pdf_base_url)
155-
logger.info("response get_all_drive_files")
149+
def get_all_index_files() -> list[str]:
150+
logger.info("request get_all_index_files")
151+
response = requests.get(file_server_pdf_base_url + "/")
152+
logger.info("response get_all_index_files")
156153

157154
if response.status_code == 200:
158155
soup = BeautifulSoup(response.content, "html.parser")
@@ -183,7 +180,7 @@ def get_all_drive_files() -> list[str]:
183180
markdown_table += f"| [{file_name}]({link}) |\n"
184181
st.markdown(markdown_table, unsafe_allow_html=True)
185182

186-
all_drive_files = get_all_drive_files()
183+
all_drive_files = get_all_index_files()
187184
all_drive_files = [urllib.parse.unquote(i) for i in all_drive_files]
188185
all_drive_files = [
189186
i for i in all_drive_files if i.endswith(".pdf") or i.endswith(".pptx")
@@ -250,37 +247,19 @@ def get_all_drive_files() -> list[str]:
250247

251248

252249
def get_category_filter(category: str) -> str:
253-
return f"contains({str(category)}, category)"
254-
if category == "No Filter":
255-
return None
256-
else:
257-
return f"category == `{category}`"
250+
return f"contains(`{str(category)}`, category)"
258251

259252

260253
# TODO: merge these
261254
def get_language_filter(lang: str) -> str:
262-
return f"contains({str(lang)}, language)"
263-
if lang == "No Filter":
264-
return None
265-
else:
266-
return f"language == `{lang}`"
255+
return f"contains(`{str(lang)}`, language)"
267256

268257

269258
def combine_filters(*args: str | None) -> str:
270259
"""Construct single jmespath filter with `&&` from number of filters."""
271260
return " && ".join([arg for arg in args if arg is not None])
272261

273262

274-
@st.cache_resource()
275-
def get_b64img_with_href(bin_str, target_url, width: int = 350, margin=20):
276-
html_code = f"""<a href="{target_url}"><img style="display: block; margin: {margin}px auto {margin}px auto" loading="lazy" src="data:image/png;base64,{bin_str}" width="{width}" /></a>""" # noqa: E501
277-
return html_code
278-
279-
280-
icon_thumbs_up = '<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M7.493 18.5c-.425 0-.82-.236-.975-.632A7.5 7.5 0 0 1 6 15.125a7.47 7.47 0 0 1 1.602-4.634c.151-.192.373-.309.6-.397c.473-.183.89-.514 1.212-.924a9 9 0 0 1 2.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.5 4.5 0 0 0 .322-1.672V2.75A.75.75 0 0 1 15 2a2.25 2.25 0 0 1 2.25 2.25c0 1.152-.26 2.243-.723 3.218c-.266.558.107 1.282.725 1.282h3.126c1.026 0 1.945.694 2.054 1.715q.068.633.068 1.285a11.95 11.95 0 0 1-2.649 7.521c-.388.482-.987.729-1.605.729H14.23a4.5 4.5 0 0 1-1.423-.23l-3.114-1.04a4.5 4.5 0 0 0-1.423-.23zm-5.162-7.773a12 12 0 0 0-.831 4.398a12 12 0 0 0 .52 3.507C2.28 19.482 3.105 20 3.994 20H4.9c.445 0 .72-.498.523-.898a9 9 0 0 1-.924-3.977c0-1.708.476-3.305 1.302-4.666c.245-.403-.028-.959-.5-.959H4.25c-.832 0-1.612.453-1.918 1.227"/></svg>' # noqa: E501
281-
282-
icon_thumbs_down = '<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M15.73 5.5h1.035A7.47 7.47 0 0 1 18 9.625a7.47 7.47 0 0 1-1.235 4.125h-.148c-.806 0-1.533.446-2.031 1.08a9 9 0 0 1-2.861 2.4c-.723.384-1.35.956-1.653 1.715a4.5 4.5 0 0 0-.322 1.672v.633A.75.75 0 0 1 9 22a2.25 2.25 0 0 1-2.25-2.25c0-1.152.26-2.243.723-3.218c.266-.558-.107-1.282-.725-1.282H3.622c-1.026 0-1.945-.694-2.054-1.715A12 12 0 0 1 1.5 12.25c0-2.848.992-5.464 2.649-7.521C4.537 4.247 5.136 4 5.754 4H9.77a4.5 4.5 0 0 1 1.423.23l3.114 1.04a4.5 4.5 0 0 0 1.423.23m5.939 8.523c.536-1.362.831-2.845.831-4.398c0-1.22-.182-2.398-.52-3.507c-.26-.85-1.084-1.368-1.973-1.368H19.1c-.445 0-.72.498-.523.898c.591 1.2.924 2.55.924 3.977a8.96 8.96 0 0 1-1.302 4.666c-.245.403.028.959.5.959h1.053c.832 0 1.612-.453 1.918-1.227"/></svg>' # noqa: E501
283-
284263
css = """
285264
<style>
286265
.slider-container {
@@ -447,5 +426,5 @@ def log_rate_answer(event, idx, kwargs):
447426
else:
448427
st.markdown(
449428
f"""No results were found for search query: `{question}`
450-
and filter criteria: `{combine_filters(*filter_ls)}`"""
429+
and filter criteria: `{combined_query_filter}`"""
451430
)

0 commit comments

Comments
 (0)