12
12
from dotenv import load_dotenv
13
13
from pathway .xpacks .llm .question_answering import RAGClient
14
14
15
- try :
16
- load_dotenv ()
17
- except Exception :
18
- pass
15
+ load_dotenv ()
19
16
20
17
PATHWAY_HOST = os .environ .get ("PATHWAY_HOST" , "app" )
21
18
PATHWAY_PORT = os .environ .get ("PATHWAY_PORT" , 8000 )
81
78
)
82
79
83
80
84
- question = st .text_input (label = "" , placeholder = "Why buy " )
81
+ question = st .text_input (label = "" , placeholder = "What are you searching for? " )
85
82
86
83
87
84
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:
93
90
def parse_slide_id_components (slide_id : str ) -> tuple [str , int , int ]:
94
91
stem = PurePosixPath (slide_id ).stem
95
92
(name_page , _ , page_count ) = stem .rpartition ("_" )
96
- (name , _ , page ) = stem .rpartition ("_" )
93
+ (name , _ , page ) = name_page .rpartition ("_" )
97
94
return (name , int (page ), int (page_count ))
98
95
99
96
@@ -149,10 +146,10 @@ def get_slide_link(file_name, page_num=None) -> str:
149
146
return image_url
150
147
151
148
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 " )
156
153
157
154
if response .status_code == 200 :
158
155
soup = BeautifulSoup (response .content , "html.parser" )
@@ -183,7 +180,7 @@ def get_all_drive_files() -> list[str]:
183
180
markdown_table += f"| [{ file_name } ]({ link } ) |\n "
184
181
st .markdown (markdown_table , unsafe_allow_html = True )
185
182
186
- all_drive_files = get_all_drive_files ()
183
+ all_drive_files = get_all_index_files ()
187
184
all_drive_files = [urllib .parse .unquote (i ) for i in all_drive_files ]
188
185
all_drive_files = [
189
186
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]:
250
247
251
248
252
249
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)"
258
251
259
252
260
253
# TODO: merge these
261
254
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)"
267
256
268
257
269
258
def combine_filters (* args : str | None ) -> str :
270
259
"""Construct single jmespath filter with `&&` from number of filters."""
271
260
return " && " .join ([arg for arg in args if arg is not None ])
272
261
273
262
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
-
284
263
css = """
285
264
<style>
286
265
.slider-container {
@@ -447,5 +426,5 @@ def log_rate_answer(event, idx, kwargs):
447
426
else :
448
427
st .markdown (
449
428
f"""No results were found for search query: `{ question } `
450
- and filter criteria: `{ combine_filters ( * filter_ls ) } `"""
429
+ and filter criteria: `{ combined_query_filter } `"""
451
430
)
0 commit comments