diff --git a/.gitignore b/.gitignore index e69de29..0c2ad09 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Main.py b/Main.py new file mode 100644 index 0000000..b5297f5 --- /dev/null +++ b/Main.py @@ -0,0 +1,45 @@ +# Utility functions +def calculate_hash(text): + import hashlib + return hashlib.md5(text.encode()).hexdigest() + +def read_file(filepath): + with open(filepath, 'r', encoding='utf-8') as f: + return f.read() + +def extract_functions(code): + import ast + tree = ast.parse(code) + functions = [] + for node in ast.walk(tree): + if isinstance(node, ast.FunctionDef): + functions.append({ + 'name': node.name, + 'lineno': node.lineno, + 'args': [arg.arg for arg in node.args.args] + }) + return functions + +def merge_dicts(*dicts): + result = {} + for d in dicts: + result.update(d) + return result + +class FileProcessor: + def __init__(self, filepath): + self.filepath = filepath + self.content = None + + def load(self): + self.content = read_file(self.filepath) + return self + + def process(self): + if self.content is None: + raise ValueError("File not loaded") + return extract_functions(self.content) + + def save(self, output_path): + with open(output_path, 'w', encoding='utf-8') as f: + f.write(self.content) \ No newline at end of file diff --git a/README.md b/README.md index d270e16..651ded5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,113 @@ -streamlit -openai -fastapi \ No newline at end of file +🐍 Automated Python Docstring Generator + +An intelligent tool that automatically generates professional, industry-standard documentation (docstrings) for Python code using Abstract Syntax Trees (AST) and Large Language Models (LLMs). + +📌 Project Overview + +The Problem + +Developers often view manual documentation as time-consuming and tedious. This results in codebases with poor readability, high maintenance costs, and difficult onboarding for new team members. +Our Solution + +An AI-powered system that reads Python files, understands function logic through static analysis (AST), and generates clear, professional docstrings in seconds. It supports multiple formats (Google, NumPy, reStructuredText) and ensures 100% documentation coverage. + +✨ Key Features + + AST-Based Parsing: Uses Python's ast module to accurately identify functions, classes, parameters, and return types without executing the code. + + AI-Driven Logic Analysis: Leverages OpenAI's GPT models to understand the "Why" and "How" behind function logic, moving beyond simple keyword matching. + + Context Awareness: Recognizes class methods and global functions to provide scope-accurate descriptions. + + Multiple Style Support: Generate docstrings in Google, NumPy, or reStructuredText formats. + + Safe Code Insertion: Reconstructs code with new docstrings while preserving original logic and indentation. + + FastAPI Ready: Built with a modular backend designed to transition from a prototype to a production-grade API. + +🛠 Tech Stack + + Core: Python 3.x + + Parsing: ast (Abstract Syntax Tree) + + AI Integration: OpenAI API (GPT-4o-mini) + + Web Interface: Streamlit + + API (In Progress): FastAPI + + Environment Management: Python-dotenv, Pydantic + + +🚀 Getting Started +1. Prerequisites + + Python 3.9 or higher + + An OpenAI API Key + +2. Installation +code Bash + +# Clone the repository +git clone https://github.com/Xynash/Automated-Python-Docstring-Generator-T-B.git + +# Navigate to the project directory +cd Automated-Python-Docstring-Generator-T-B + +# Install dependencies +pip install -r requirements.txt + +3. Configuration + +Create a .env file in the root directory and add your OpenAI API key: +code Text + +OPENAI_API_KEY=your_actual_api_key_here + +4. Running the App +code Bash + +python -m streamlit run app/streamlit_app.py + +📊 Workflow & Collaboration + +This project follows a professional Feature-Branch Workflow: + + main Branch: Contains the stable project skeleton and configuration. + + Member-1 Branch: Active development for the core AI engine and UI. + + Pull Requests: All new features are reviewed and merged into main only after passing quality checks. + +🛣 Roadmap + + Core AST Parser + + AI Docstring Generation (Google Style) + + Streamlit Prototype + + FastAPI Backend Migration + + Support for JavaScript & Go + + VS Code Extension Integration + + CI/CD Pipeline for automatic documentation checks + +👥 Contributors + + Member 1 : Ansh Sharma + + Member 2 : Sreya Merin Sam + + Member 3 : Kasa Navyasa Durga + + Member 4 : Pooja Vattikoti + + +📄 License + +This project is licensed under the MIT License - see the LICENSE file for details. diff --git a/app/__pycache__/__init__.cpython-313.pyc b/app/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..041d2ee Binary files /dev/null and b/app/__pycache__/__init__.cpython-313.pyc differ diff --git a/app/api/__pycache__/__init__.cpython-313.pyc b/app/api/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..96c3a9b Binary files /dev/null and b/app/api/__pycache__/__init__.cpython-313.pyc differ diff --git a/app/api/__pycache__/main.cpython-313.pyc b/app/api/__pycache__/main.cpython-313.pyc new file mode 100644 index 0000000..92b4b6f Binary files /dev/null and b/app/api/__pycache__/main.cpython-313.pyc differ diff --git a/app/core/__pycache__/__init__.cpython-313.pyc b/app/core/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..01d3e6f Binary files /dev/null and b/app/core/__pycache__/__init__.cpython-313.pyc differ diff --git a/app/core/__pycache__/ai_docstring_engine.cpython-313.pyc b/app/core/__pycache__/ai_docstring_engine.cpython-313.pyc new file mode 100644 index 0000000..9f77d83 Binary files /dev/null and b/app/core/__pycache__/ai_docstring_engine.cpython-313.pyc differ diff --git a/app/core/__pycache__/ai_engine.cpython-313.pyc b/app/core/__pycache__/ai_engine.cpython-313.pyc new file mode 100644 index 0000000..eee20c7 Binary files /dev/null and b/app/core/__pycache__/ai_engine.cpython-313.pyc differ diff --git a/app/core/__pycache__/docstring_gen.cpython-313.pyc b/app/core/__pycache__/docstring_gen.cpython-313.pyc new file mode 100644 index 0000000..ea38c92 Binary files /dev/null and b/app/core/__pycache__/docstring_gen.cpython-313.pyc differ diff --git a/app/core/__pycache__/inserter.cpython-313.pyc b/app/core/__pycache__/inserter.cpython-313.pyc new file mode 100644 index 0000000..50d4682 Binary files /dev/null and b/app/core/__pycache__/inserter.cpython-313.pyc differ diff --git a/app/core/__pycache__/parser.cpython-313.pyc b/app/core/__pycache__/parser.cpython-313.pyc new file mode 100644 index 0000000..a776700 Binary files /dev/null and b/app/core/__pycache__/parser.cpython-313.pyc differ diff --git a/app/core/__pycache__/prompt_builder.cpython-313.pyc b/app/core/__pycache__/prompt_builder.cpython-313.pyc new file mode 100644 index 0000000..e976031 Binary files /dev/null and b/app/core/__pycache__/prompt_builder.cpython-313.pyc differ