taishi-i commited on
Commit
386b976
β€’
1 Parent(s): 7bc52df

update app.py

Browse files
Files changed (5) hide show
  1. README.md +2 -2
  2. app.py +45 -147
  3. awesome-ChatGPT-repositories.json +0 -0
  4. packages.txt +0 -1
  5. requirements.txt +1 -4
README.md CHANGED
@@ -3,8 +3,8 @@ title: Awesome ChatGPT Repositories Search
3
  emoji: 🏒
4
  colorFrom: red
5
  colorTo: blue
6
- sdk: streamlit
7
- sdk_version: 1.35.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
3
  emoji: 🏒
4
  colorFrom: red
5
  colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 4.36.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -1,9 +1,7 @@
1
- import difflib
2
  import json
3
 
4
- import numpy as np
5
- import streamlit as st
6
- from pyserini.search.lucene import LuceneSearcher
7
 
8
 
9
  def read_json(file_name):
@@ -12,146 +10,46 @@ def read_json(file_name):
12
  return json_data
13
 
14
 
15
- class SearchApplication:
16
- def __init__(self):
17
- self.title = "Awesome ChatGPT repositories search"
18
-
19
- self.set_page_config()
20
- self.searcher = self.set_searcher()
21
-
22
- st.header(self.title)
23
- col1, col2 = st.columns(2)
24
- with col1:
25
- self.query = st.text_input("Search English words", value="")
26
-
27
- with col2:
28
- st.write("#")
29
- self.search_button = st.button("πŸ”Ž")
30
-
31
- st.caption(
32
- "You can search for open-source software from [1500+ "
33
- " repositories](https://github.com/taishi-i/awesome-ChatGPT-repositories)."
34
- )
35
- st.write("#")
36
-
37
- candidate_words_file = "candidate_words.json"
38
- candidate_words_json = read_json(candidate_words_file)
39
- self.candidate_words = candidate_words_json["candidate_words"]
40
-
41
- self.show_popular_words()
42
- self.show_search_results()
43
-
44
- def set_page_config(self):
45
- st.set_page_config(
46
- page_title=self.title,
47
- page_icon="😎",
48
- layout="centered",
49
- )
50
-
51
- def set_searcher(self):
52
- searcher = LuceneSearcher("indexes/docs")
53
- return searcher
54
-
55
- def show_popular_words(self):
56
- st.caption("Popular words")
57
-
58
- word1, word2, word3, word4, word5, word6 = st.columns(6)
59
- with word1:
60
- button1 = st.button("Prompt")
61
- if button1:
62
- self.query = "prompt"
63
-
64
- with word2:
65
- button2 = st.button("Chatbot")
66
- if button2:
67
- self.query = "chatbot"
68
-
69
- with word3:
70
- button3 = st.button("Langchain")
71
- if button3:
72
- self.query = "langchain"
73
-
74
- with word4:
75
- button4 = st.button("Extension")
76
- if button4:
77
- self.query = "extension"
78
-
79
- with word5:
80
- button5 = st.button("LLMs")
81
- if button5:
82
- self.query = "llms"
83
-
84
- with word6:
85
- button6 = st.button("API")
86
- if button6:
87
- self.query = "api"
88
-
89
- def show_search_results(self):
90
- if self.query or self.search_button:
91
- st.write("#")
92
-
93
- search_results = self.searcher.search(self.query, k=500)
94
- num_search_results = len(search_results)
95
- st.write(f"A total of {num_search_results} repositories found.")
96
-
97
- if num_search_results > 0:
98
- json_search_results = []
99
- for result in search_results:
100
- docid = result.docid
101
- doc = self.searcher.doc(docid)
102
- json_data = json.loads(doc.raw())
103
- json_search_results.append(json_data)
104
-
105
- for json_data in sorted(
106
- json_search_results, key=lambda x: x["freq"], reverse=True
107
- ):
108
- description = json_data["description"]
109
- url = json_data["url"]
110
- project_name = json_data["project_name"]
111
-
112
- st.write("---")
113
- st.subheader(f"[{project_name}]({url})")
114
- st.write(description)
115
-
116
- info = []
117
- language = json_data["language"]
118
- if language is not None and len(language) > 0:
119
- info.append(language)
120
- else:
121
- info.append("Laugage: Unkwown")
122
-
123
- license = json_data["license"]
124
- if license is None:
125
- info.append("License: Unkwown")
126
- else:
127
- info.append(license)
128
-
129
- st.caption(" / ".join(info))
130
-
131
- else:
132
- if len(self.query) > 0:
133
- scores = []
134
- for candidate_word in self.candidate_words:
135
- score = difflib.SequenceMatcher(
136
- None, self.query, candidate_word
137
- ).ratio()
138
- scores.append(score)
139
-
140
- num_candidate_words = 6
141
-
142
- indexes = np.argsort(scores)[::-1][:num_candidate_words]
143
- suggestions = [self.candidate_words[i] for i in indexes]
144
- suggestions = sorted(
145
- set(suggestions), key=suggestions.index
146
- )
147
- st.caption("Suggestions")
148
- for i, word in enumerate(suggestions, start=1):
149
- st.write(f"{i}: {word}")
150
-
151
-
152
- def main():
153
- SearchApplication()
154
-
155
-
156
- if __name__ == "__main__":
157
- main()
 
 
1
  import json
2
 
3
+ import gradio as gr
4
+ import pandas as pd
 
5
 
6
 
7
  def read_json(file_name):
 
10
  return json_data
11
 
12
 
13
+ data = {"project_name": [], "description": []}
14
+
15
+ json_file = "awesome-ChatGPT-repositories.json"
16
+ json_data = read_json(json_file)
17
+ for v in json_data["contents"].values():
18
+ for url, repo in v.items():
19
+ description = repo["multilingual_descriptions"]["en"]
20
+ project_name = repo["repository_name"]
21
+ data["project_name"].append(f"[{project_name}]({url})")
22
+ data["description"].append(description)
23
+
24
+
25
+ data = pd.DataFrame(data)
26
+
27
+
28
+ def show_search_results(queries):
29
+ queries = queries.lower()
30
+ queries = queries.split()
31
+
32
+ df_search = data
33
+ for query in queries:
34
+ contained_description = data["description"].str.contains(query)
35
+ contained_project_name = data["project_name"].str.contains(query)
36
+ df_search = df_search[contained_description | contained_project_name]
37
+ return df_search
38
+
39
+
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown(
42
+ """
43
+ # Awesome ChatGPT repositories search πŸ”Ž
44
+ You can search for open-source software from [1500+ repositories](https://github.com/taishi-i/awesome-ChatGPT-repositories).
45
+ """
46
+ )
47
+
48
+ query = gr.Textbox(label="Search words", placeholder="prompt")
49
+ df = gr.DataFrame(
50
+ value=data, type="pandas", datatype="markdown", height=1000
51
+ )
52
+
53
+ query.change(fn=show_search_results, inputs=query, outputs=df)
54
+
55
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
awesome-ChatGPT-repositories.json ADDED
The diff for this file is too large to render. See raw diff
 
packages.txt DELETED
@@ -1 +0,0 @@
1
- default-jdk
 
 
requirements.txt CHANGED
@@ -1,4 +1 @@
1
- pyserini
2
- faiss-cpu
3
- torch
4
- altair<5
 
1
+ pandas