| 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 |
|
|
|
|
| |
| 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", []) |
|
|
| |
| 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: |
| |
| if selected_categories and repo["category"] not in selected_categories: |
| continue |
|
|
| |
| if selected_language and selected_language != "All" and repo["language"] != selected_language: |
| continue |
|
|
| |
| 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) |
| |
| 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)) |
|
|
|
|
| |
| 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) |
| """ |
| ) |
|
|
| |
| 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], |
| ) |
|
|
| |
| demo.load( |
| fn=lambda: do_search("", [], "All", "English"), |
| outputs=[results_table, result_count], |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|