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