zhiminy commited on
Commit
0da6a99
·
verified ·
1 Parent(s): d4cdd0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -25
app.py CHANGED
@@ -10,6 +10,30 @@ def fetch_readme_content():
10
  st.error("Failed to fetch README.md content from GitHub.")
11
  return ""
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  class SearchApplication:
14
  def __init__(self):
15
  self.title = "Awesome Awesome Artificial Intelligence Search"
@@ -18,18 +42,19 @@ class SearchApplication:
18
  st.header(self.title)
19
  col1, col2 = st.columns(2)
20
  with col1:
21
- self.query = st.text_input("Search", value="")
22
 
23
  with col2:
24
  st.write("#")
25
- self.search_button = st.button("🔎")
26
 
27
  st.caption(
28
  "This search toolkit is a user-friendly platform that enables efficient exploration and filtering of the comprehensive [Awesome Awesome Artificial Intelligence](https://github.com/zhimin-z/awesome-awesome-artificial-intelligence) list, which includes over 100 awesome lists about artificial intelligence, making it an indispensable resource for researchers, developers, and enthusiasts in the field."
29
  )
30
  st.write("#")
31
 
32
- self.show_search_results()
 
33
 
34
  def set_page_config(self):
35
  st.set_page_config(
@@ -38,27 +63,5 @@ class SearchApplication:
38
  layout="centered",
39
  )
40
 
41
- def show_search_results(self):
42
- if self.query or self.search_button:
43
- st.write("#")
44
-
45
- readme_content = fetch_readme_content()
46
-
47
- if readme_content:
48
- search_results = []
49
- lines = readme_content.split("\n")
50
- for line in lines:
51
- if self.query.lower() in line.lower():
52
- search_results.append(line)
53
-
54
- num_search_results = len(search_results)
55
- st.write(f"A total of {num_search_results} matches found.")
56
-
57
- if num_search_results > 0:
58
- for result in search_results:
59
- st.write(result)
60
- else:
61
- st.write("No matches found.")
62
-
63
  if __name__ == "__main__":
64
  SearchApplication()
 
10
  st.error("Failed to fetch README.md content from GitHub.")
11
  return ""
12
 
13
+ def show_search_results():
14
+ query = st.session_state.query
15
+
16
+ if query:
17
+ st.write("#")
18
+
19
+ readme_content = fetch_readme_content()
20
+
21
+ if readme_content:
22
+ search_results = []
23
+ lines = readme_content.split("\n")
24
+ for line in lines:
25
+ if query.lower() in line.lower():
26
+ search_results.append(line)
27
+
28
+ num_search_results = len(search_results)
29
+ st.write(f"A total of {num_search_results} matches found.")
30
+
31
+ if num_search_results > 0:
32
+ for result in search_results:
33
+ st.write(result)
34
+ else:
35
+ st.write("No matches found.")
36
+
37
  class SearchApplication:
38
  def __init__(self):
39
  self.title = "Awesome Awesome Artificial Intelligence Search"
 
42
  st.header(self.title)
43
  col1, col2 = st.columns(2)
44
  with col1:
45
+ st.text_input("Search", value="", key='query', on_change=show_search_results)
46
 
47
  with col2:
48
  st.write("#")
49
+ # No need for search button since we're updating in real-time
50
 
51
  st.caption(
52
  "This search toolkit is a user-friendly platform that enables efficient exploration and filtering of the comprehensive [Awesome Awesome Artificial Intelligence](https://github.com/zhimin-z/awesome-awesome-artificial-intelligence) list, which includes over 100 awesome lists about artificial intelligence, making it an indispensable resource for researchers, developers, and enthusiasts in the field."
53
  )
54
  st.write("#")
55
 
56
+ # Show initial search results if there's a query
57
+ show_search_results()
58
 
59
  def set_page_config(self):
60
  st.set_page_config(
 
63
  layout="centered",
64
  )
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  if __name__ == "__main__":
67
  SearchApplication()