Update app.py
Browse files
app.py
CHANGED
@@ -8,15 +8,15 @@ df = pd.read_csv(url, encoding='utf-8-sig')
|
|
8 |
# Function to search years based on the selected mode
|
9 |
def search_years(search_mode, query):
|
10 |
if search_mode == "Search questions by YEAR":
|
11 |
-
matches = df[df['YEAR'].str.startswith(query[:4])]
|
12 |
elif search_mode == "Search questions by Keywords":
|
13 |
-
keyword_list = [keyword.strip() for keyword in query.split(',')]
|
14 |
-
matches = df[df['KEYWORDS'].apply(lambda x: any(keyword in x for keyword in keyword_list))]
|
15 |
-
elif search_mode == "Search questions by Words":
|
16 |
-
word_list = [word.strip() for word in query.split(',')]
|
17 |
-
matches = df[df['TEXT'].apply(lambda x: any(word in x for word in word_list))]
|
18 |
else:
|
19 |
-
return [], "Please select
|
20 |
|
21 |
if matches.empty:
|
22 |
return [], "No results found for your query."
|
@@ -39,7 +39,7 @@ with gr.Blocks() as app:
|
|
39 |
gr.Markdown("## ❄️ [1] Search Data")
|
40 |
|
41 |
# Radio buttons to select search mode
|
42 |
-
search_mode = gr.Radio(choices=["Search by YEAR", "Search
|
43 |
|
44 |
# Row for search query and button
|
45 |
search_input = gr.Textbox(label="Search Query: e.g., 2024 (by YEAR) or tapping (by Keywords or Words)", placeholder="Enter year or keywords or words")
|
|
|
8 |
# Function to search years based on the selected mode
|
9 |
def search_years(search_mode, query):
|
10 |
if search_mode == "Search questions by YEAR":
|
11 |
+
matches = df[df['YEAR'].str.startswith(query.strip()[:4])] # Ensure query is stripped of whitespace
|
12 |
elif search_mode == "Search questions by Keywords":
|
13 |
+
keyword_list = [keyword.strip().lower() for keyword in query.split(',')]
|
14 |
+
matches = df[df['KEYWORDS'].str.lower().apply(lambda x: any(keyword in x for keyword in keyword_list))]
|
15 |
+
elif search_mode == "Search questions by Words":
|
16 |
+
word_list = [word.strip().lower() for word in query.split(',')]
|
17 |
+
matches = df[df['TEXT'].str.lower().apply(lambda x: any(word in x for word in word_list))]
|
18 |
else:
|
19 |
+
return [], "Please select a valid search mode."
|
20 |
|
21 |
if matches.empty:
|
22 |
return [], "No results found for your query."
|
|
|
39 |
gr.Markdown("## ❄️ [1] Search Data")
|
40 |
|
41 |
# Radio buttons to select search mode
|
42 |
+
search_mode = gr.Radio(choices=["Search questions by YEAR", "Search questions by Keywords", "Search questions by Words"], label="Search Mode")
|
43 |
|
44 |
# Row for search query and button
|
45 |
search_input = gr.Textbox(label="Search Query: e.g., 2024 (by YEAR) or tapping (by Keywords or Words)", placeholder="Enter year or keywords or words")
|