|
| 1 | +#!/usr/bin/env python3 |
1 | 2 | import os |
| 3 | +import json |
2 | 4 |
|
3 | | -BASE_DIR = "." |
4 | | -TEMPLATE = """# {project_name} |
| 5 | +# If you keep projects in a "projects" folder change this variable to 'projects' |
| 6 | +PROJECTS_ROOT = "projects" if os.path.isdir("projects") else "." |
| 7 | + |
| 8 | +EXCLUDE_FOLDERS = {".github", ".git", ".vscode", "node_modules"} |
| 9 | + |
| 10 | +README_TEMPLATE = """# {title} |
5 | 11 |
|
6 | 12 | ## 📌 Project Overview |
7 | | -This project is part of the **Machine Learning Projects Collection (100+ projects with source code)**. |
| 13 | +{description} |
8 | 14 |
|
9 | 15 | ## 🛠️ Potential Technologies / Tools |
10 | | -- Python |
11 | | -- Pandas |
12 | | -- Scikit-learn |
13 | | -- TensorFlow/Keras (if deep learning) |
| 16 | +{tools_list} |
14 | 17 |
|
15 | 18 | ## 🚀 How to Run |
16 | 19 | 1. Clone this repository |
17 | 20 | 2. Navigate to this project folder |
18 | | -3. Install dependencies (`pip install -r requirements.txt`) |
19 | | -4. Run the code |
| 21 | +3. Install dependencies (e.g. `pip install -r requirements.txt`) |
| 22 | +4. Run the code (follow project-specific instructions) |
20 | 23 |
|
21 | 24 | --- |
22 | | -✅ Auto-generated by [ML Projects Bot] 🤖 |
| 25 | +✅ Auto-generated by ML Projects Bot 🤖 |
23 | 26 | """ |
24 | 27 |
|
25 | | -def format_name(folder): |
26 | | - return folder.replace("-", " ").replace("_", " ").title() |
27 | | - |
28 | | -for folder in os.listdir(BASE_DIR): |
29 | | - if os.path.isdir(folder) and folder not in [".github", ".git"]: |
30 | | - readme_path = os.path.join(folder, "README.md") |
31 | | - if not os.path.exists(readme_path): |
32 | | - project_name = format_name(folder) |
33 | | - with open(readme_path, "w") as f: |
34 | | - f.write(TEMPLATE.format(project_name=project_name)) |
35 | | - print(f"Generated README for {project_name}") |
| 28 | +DEFAULT_DESCRIPTION = "This project is part of the Machine-learning-projects-collection-100-plus-projects-with-source-code repository." |
| 29 | +DEFAULT_TOOLS = "Python, Pandas, Scikit-learn (customize for your project)" |
| 30 | + |
| 31 | +KEYWORD_STACKS = { |
| 32 | + "spam": "Python, Scikit-learn, NLTK, Naive Bayes", |
| 33 | + "sentiment": "Python, NLTK, Scikit-learn, TextBlob", |
| 34 | + "stock": "Pandas, yfinance, LSTM, TensorFlow/Keras", |
| 35 | + "price": "Pandas, Scikit-learn, Regression / Time-series", |
| 36 | + "image": "TensorFlow/Keras, OpenCV, CNN", |
| 37 | + "ocr": "Tesseract, OpenCV, EasyOCR", |
| 38 | + "fraud": "Scikit-learn, IsolationForest, XGBoost", |
| 39 | + "classification": "Scikit-learn, RandomForest, LogisticRegression", |
| 40 | + "regression": "Scikit-learn, LinearRegression, XGBoost", |
| 41 | + "segmentation": "U-Net, TensorFlow/PyTorch", |
| 42 | +} |
| 43 | + |
| 44 | +def format_title(name): |
| 45 | + return name.replace("-", " ").replace("_", " ").title() |
| 46 | + |
| 47 | +def guess_tools(name): |
| 48 | + lower = name.lower() |
| 49 | + for k,v in KEYWORD_STACKS.items(): |
| 50 | + if k in lower: |
| 51 | + return v |
| 52 | + return DEFAULT_TOOLS |
| 53 | + |
| 54 | +def load_metadata(folder): |
| 55 | + # Supports optional project.json containing {"name": "...", "description": "...", "tools": ["t1","t2"]} |
| 56 | + meta_path = os.path.join(folder, "project.json") |
| 57 | + if os.path.exists(meta_path): |
| 58 | + try: |
| 59 | + with open(meta_path, "r", encoding="utf-8") as f: |
| 60 | + return json.load(f) |
| 61 | + except Exception as e: |
| 62 | + print(f"Could not parse {meta_path}: {e}") |
| 63 | + return None |
| 64 | + |
| 65 | +def write_readme(folder, title, description, tools): |
| 66 | + readme_path = os.path.join(folder, "README.md") |
| 67 | + if os.path.exists(readme_path): |
| 68 | + print(f"README exists for {folder}, skipping.") |
| 69 | + return False |
| 70 | + tools_list = "\n".join(f"- {t}" for t in (tools.split(",") if isinstance(tools, str) else tools)) |
| 71 | + content = README_TEMPLATE.format(title=title, description=description, tools_list=tools_list) |
| 72 | + with open(readme_path, "w", encoding="utf-8") as f: |
| 73 | + f.write(content) |
| 74 | + print(f"Generated README.md for {folder}") |
| 75 | + return True |
| 76 | + |
| 77 | +def main(): |
| 78 | + base = os.getcwd() |
| 79 | + candidates = [] |
| 80 | + if PROJECTS_ROOT == ".": |
| 81 | + # all top-level directories except excluded ones |
| 82 | + for name in os.listdir("."): |
| 83 | + if os.path.isdir(name) and name not in EXCLUDE_FOLDERS: |
| 84 | + candidates.append(name) |
| 85 | + else: |
| 86 | + root_path = os.path.join(base, PROJECTS_ROOT) |
| 87 | + for name in os.listdir(root_path): |
| 88 | + full = os.path.join(root_path, name) |
| 89 | + if os.path.isdir(full) and name not in EXCLUDE_FOLDERS: |
| 90 | + candidates.append(full) |
| 91 | + |
| 92 | + any_written = False |
| 93 | + for folder in sorted(candidates): |
| 94 | + full_path = folder if PROJECTS_ROOT == "." else os.path.join(PROJECTS_ROOT, os.path.basename(folder)) |
| 95 | + meta = load_metadata(full_path) |
| 96 | + if meta: |
| 97 | + title = meta.get("name", format_title(os.path.basename(full_path))) |
| 98 | + description = meta.get("description", DEFAULT_DESCRIPTION) |
| 99 | + tools = meta.get("tools", guess_tools(os.path.basename(full_path))) |
| 100 | + tools_str = ", ".join(tools) if isinstance(tools, list) else tools |
| 101 | + else: |
| 102 | + title = format_title(os.path.basename(full_path)) |
| 103 | + description = DEFAULT_DESCRIPTION |
| 104 | + tools_str = guess_tools(os.path.basename(full_path)) |
| 105 | + |
| 106 | + created = write_readme(full_path, title, description, tools_str) |
| 107 | + any_written = any_written or created |
| 108 | + |
| 109 | + if not any_written: |
| 110 | + print("No new README files generated.") |
| 111 | + |
| 112 | +if __name__ == "__main__": |
| 113 | + main() |
0 commit comments