update app.py
Browse files
app.py
CHANGED
|
@@ -1,60 +1,243 @@
|
|
| 1 |
import json
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
|
| 7 |
def read_json(file_name):
|
| 8 |
-
with open(file_name, "r") as f:
|
| 9 |
json_data = json.load(f)
|
| 10 |
return json_data
|
| 11 |
|
| 12 |
|
| 13 |
-
|
| 14 |
-
if len(text) > max_length:
|
| 15 |
-
return text[: max_length - 1] + "…"
|
| 16 |
-
else:
|
| 17 |
-
return text
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
data = {"project_name": [], "description": []}
|
| 21 |
-
|
| 22 |
json_file = "awesome-ChatGPT-repositories.json"
|
| 23 |
json_data = read_json(json_file)
|
| 24 |
-
for v in json_data["contents"].values():
|
| 25 |
-
for url, repo in v.items():
|
| 26 |
-
description = repo["multilingual_descriptions"]["en"]
|
| 27 |
-
project_name = repo["repository_name"]
|
| 28 |
-
data["project_name"].append(f"[{truncate_text(project_name)}]({url})")
|
| 29 |
-
data["description"].append(description)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
contained_project_name = data["project_name"].str.contains(query)
|
| 43 |
-
df_search = df_search[contained_description | contained_project_name]
|
| 44 |
-
return df_search
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
You can search for open-source software from [2000+ repositories](https://github.com/taishi-i/awesome-ChatGPT-repositories).
|
| 52 |
-
"""
|
| 53 |
)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
|
| 8 |
def read_json(file_name):
|
| 9 |
+
with open(file_name, "r", encoding="utf-8") as f:
|
| 10 |
json_data = json.load(f)
|
| 11 |
return json_data
|
| 12 |
|
| 13 |
|
| 14 |
+
# Load data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
json_file = "awesome-ChatGPT-repositories.json"
|
| 16 |
json_data = read_json(json_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
candidate_words_file = "candidate_words.json"
|
| 19 |
+
candidate_words_data = read_json(candidate_words_file)
|
| 20 |
+
candidate_words = candidate_words_data.get("candidate_words", [])
|
| 21 |
+
|
| 22 |
+
# Build repository data with categories
|
| 23 |
+
repos_data = []
|
| 24 |
+
categories = set()
|
| 25 |
+
|
| 26 |
+
for category, repos in json_data["contents"].items():
|
| 27 |
+
categories.add(category)
|
| 28 |
+
for url, repo in repos.items():
|
| 29 |
+
repos_data.append({
|
| 30 |
+
"url": url,
|
| 31 |
+
"name": repo["repository_name"],
|
| 32 |
+
"user": repo.get("user_name", ""),
|
| 33 |
+
"language": repo.get("language") or "N/A",
|
| 34 |
+
"license": repo.get("license") or "N/A",
|
| 35 |
+
"description_en": repo["multilingual_descriptions"].get("en", ""),
|
| 36 |
+
"description_ja": repo["multilingual_descriptions"].get("ja", ""),
|
| 37 |
+
"description_zh_hans": repo["multilingual_descriptions"].get("zh-hans", ""),
|
| 38 |
+
"description_zh_hant": repo["multilingual_descriptions"].get("zh-hant", ""),
|
| 39 |
+
"topics": repo.get("topics", []),
|
| 40 |
+
"category": category,
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
categories = sorted(list(categories))
|
| 44 |
+
total_repos = len(repos_data)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def get_description(repo, lang):
|
| 48 |
+
"""Get description based on language selection"""
|
| 49 |
+
if lang == "English":
|
| 50 |
+
return repo["description_en"]
|
| 51 |
+
elif lang == "Japanese":
|
| 52 |
+
return repo["description_ja"]
|
| 53 |
+
elif lang == "Chinese (Simplified)":
|
| 54 |
+
return repo["description_zh_hans"]
|
| 55 |
+
elif lang == "Chinese (Traditional)":
|
| 56 |
+
return repo["description_zh_hant"]
|
| 57 |
+
return repo["description_en"]
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def search_repos(query, selected_categories, selected_language, lang):
|
| 61 |
+
"""Search repositories based on query and filters"""
|
| 62 |
+
results = []
|
| 63 |
+
query_lower = query.lower().strip()
|
| 64 |
+
queries = query_lower.split() if query_lower else []
|
| 65 |
+
|
| 66 |
+
for repo in repos_data:
|
| 67 |
+
# Category filter
|
| 68 |
+
if selected_categories and repo["category"] not in selected_categories:
|
| 69 |
+
continue
|
| 70 |
+
|
| 71 |
+
# Language filter
|
| 72 |
+
if selected_language and selected_language != "All" and repo["language"] != selected_language:
|
| 73 |
+
continue
|
| 74 |
+
|
| 75 |
+
# Text search
|
| 76 |
+
if queries:
|
| 77 |
+
description = get_description(repo, lang).lower()
|
| 78 |
+
name_lower = repo["name"].lower()
|
| 79 |
+
topics_str = " ".join(repo["topics"]).lower()
|
| 80 |
+
search_text = f"{name_lower} {description} {topics_str}"
|
| 81 |
+
|
| 82 |
+
if not all(q in search_text for q in queries):
|
| 83 |
+
continue
|
| 84 |
+
|
| 85 |
+
results.append(repo)
|
| 86 |
+
|
| 87 |
+
return results
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def format_results(results, lang):
|
| 91 |
+
"""Format results for display"""
|
| 92 |
+
if not results:
|
| 93 |
+
return pd.DataFrame(columns=["Repository", "Category", "Language", "Description"])
|
| 94 |
+
|
| 95 |
+
data = {
|
| 96 |
+
"Repository": [],
|
| 97 |
+
"Category": [],
|
| 98 |
+
"Language": [],
|
| 99 |
+
"Description": [],
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
for repo in results:
|
| 103 |
+
repo_link = f"[{repo['name']}]({repo['url']})"
|
| 104 |
+
description = get_description(repo, lang)
|
| 105 |
+
# Truncate long descriptions
|
| 106 |
+
if len(description) > 150:
|
| 107 |
+
description = description[:147] + "..."
|
| 108 |
+
|
| 109 |
+
data["Repository"].append(repo_link)
|
| 110 |
+
data["Category"].append(repo["category"])
|
| 111 |
+
data["Language"].append(repo["language"])
|
| 112 |
+
data["Description"].append(description)
|
| 113 |
+
|
| 114 |
+
return pd.DataFrame(data)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def do_search(query, selected_categories, selected_language, lang):
|
| 118 |
+
"""Main search function"""
|
| 119 |
+
results = search_repos(query, selected_categories, selected_language, lang)
|
| 120 |
+
df = format_results(results, lang)
|
| 121 |
+
count_text = f"Found **{len(results)}** repositories"
|
| 122 |
+
return df, count_text
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def get_random_suggestion():
|
| 126 |
+
"""Get random search suggestion from candidate words"""
|
| 127 |
+
if candidate_words:
|
| 128 |
+
suggestions = random.sample(candidate_words, min(5, len(candidate_words)))
|
| 129 |
+
return ", ".join(suggestions)
|
| 130 |
+
return "prompt, langchain, agent, chatbot, api"
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def get_languages():
|
| 134 |
+
"""Get unique programming languages"""
|
| 135 |
+
languages = set()
|
| 136 |
+
for repo in repos_data:
|
| 137 |
+
if repo["language"] and repo["language"] != "N/A":
|
| 138 |
+
languages.add(repo["language"])
|
| 139 |
+
return ["All"] + sorted(list(languages))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
# Build the Gradio interface
|
| 143 |
+
with gr.Blocks(
|
| 144 |
+
title="Awesome ChatGPT Repositories Search",
|
| 145 |
+
theme=gr.themes.Soft(),
|
| 146 |
+
) as demo:
|
| 147 |
+
gr.Markdown(
|
| 148 |
+
"""
|
| 149 |
+
# Awesome ChatGPT Repositories Search
|
| 150 |
|
| 151 |
+
Discover and explore **{total}** open-source repositories from the [awesome-ChatGPT-repositories](https://github.com/taishi-i/awesome-ChatGPT-repositories) collection.
|
| 152 |
+
Find tools, libraries, and projects related to ChatGPT, LLMs, and AI.
|
| 153 |
+
""".format(total=total_repos)
|
| 154 |
+
)
|
| 155 |
|
| 156 |
+
with gr.Row():
|
| 157 |
+
with gr.Column(scale=3):
|
| 158 |
+
query_input = gr.Textbox(
|
| 159 |
+
label="Search",
|
| 160 |
+
placeholder="Enter keywords to search (e.g., prompt, langchain, agent)",
|
| 161 |
+
)
|
| 162 |
+
suggestion = gr.Markdown(
|
| 163 |
+
f"*Try searching:* {get_random_suggestion()}",
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
with gr.Column(scale=1):
|
| 167 |
+
display_lang = gr.Dropdown(
|
| 168 |
+
choices=["English", "Japanese", "Chinese (Simplified)", "Chinese (Traditional)"],
|
| 169 |
+
value="English",
|
| 170 |
+
label="Description Language",
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
with gr.Accordion("Filters", open=False):
|
| 174 |
+
with gr.Row():
|
| 175 |
+
with gr.Column():
|
| 176 |
+
category_filter = gr.CheckboxGroup(
|
| 177 |
+
choices=categories,
|
| 178 |
+
label="Categories",
|
| 179 |
+
)
|
| 180 |
+
with gr.Column():
|
| 181 |
+
language_filter = gr.Dropdown(
|
| 182 |
+
choices=get_languages(),
|
| 183 |
+
value="All",
|
| 184 |
+
label="Programming Language",
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
result_count = gr.Markdown("")
|
| 188 |
+
|
| 189 |
+
results_table = gr.DataFrame(
|
| 190 |
+
value=format_results(repos_data[:100], "English"),
|
| 191 |
+
datatype=["markdown", "str", "str", "str"],
|
| 192 |
+
interactive=False,
|
| 193 |
+
wrap=True,
|
| 194 |
+
)
|
| 195 |
|
| 196 |
+
gr.Markdown(
|
| 197 |
+
"""
|
| 198 |
+
---
|
| 199 |
+
**Tips:**
|
| 200 |
+
- Use multiple keywords separated by spaces for AND search
|
| 201 |
+
- Use filters to narrow down results by category or programming language
|
| 202 |
+
- Click on repository names to visit their GitHub pages
|
| 203 |
|
| 204 |
+
Made with Gradio | Data from [awesome-ChatGPT-repositories](https://github.com/taishi-i/awesome-ChatGPT-repositories)
|
| 205 |
+
"""
|
| 206 |
+
)
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
+
# Event handlers
|
| 209 |
+
def on_search_change(query, categories, language, lang):
|
| 210 |
+
return do_search(query, categories, language, lang)
|
| 211 |
|
| 212 |
+
query_input.change(
|
| 213 |
+
fn=on_search_change,
|
| 214 |
+
inputs=[query_input, category_filter, language_filter, display_lang],
|
| 215 |
+
outputs=[results_table, result_count],
|
|
|
|
|
|
|
| 216 |
)
|
| 217 |
|
| 218 |
+
category_filter.change(
|
| 219 |
+
fn=on_search_change,
|
| 220 |
+
inputs=[query_input, category_filter, language_filter, display_lang],
|
| 221 |
+
outputs=[results_table, result_count],
|
| 222 |
+
)
|
| 223 |
|
| 224 |
+
language_filter.change(
|
| 225 |
+
fn=on_search_change,
|
| 226 |
+
inputs=[query_input, category_filter, language_filter, display_lang],
|
| 227 |
+
outputs=[results_table, result_count],
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
display_lang.change(
|
| 231 |
+
fn=on_search_change,
|
| 232 |
+
inputs=[query_input, category_filter, language_filter, display_lang],
|
| 233 |
+
outputs=[results_table, result_count],
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
# Initialize with all results
|
| 237 |
+
demo.load(
|
| 238 |
+
fn=lambda: do_search("", [], "All", "English"),
|
| 239 |
+
outputs=[results_table, result_count],
|
| 240 |
+
)
|
| 241 |
|
| 242 |
+
if __name__ == "__main__":
|
| 243 |
+
demo.launch()
|