krishshharma/Code-Explainer
0
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
AI Code Explainer
An AI-powered application that explains code snippets, providing insights into their functionality, time complexity, and common use cases. Built with LangChain, Hugging Face, and Gradio.
Features
- Code explanation with detailed analysis
- Time complexity analysis
- Common use cases identification
- User-friendly web interface
- Powered by Mistral-7B-Instruct-v0.2
Prerequisites
- Python 3.9+
- Hugging Face account and API token
- Git
Installation
- Clone the repository:
git clone https://github.com/krish341360/Code-Explainer.git
cd Code-Explainer- Install the required dependencies:
pip install -r requirements.txt- Set up your Hugging Face API token:
# Create a .env file
echo "HUGGINGFACEHUB_API_TOKEN=your_token_here" > .env- Create a
datadirectory and add your sample files:
mkdir data
# Add your sample code and documentation files
touch data/sample_code.py
touch data/docs.txtUsage
- Start the application:
python app.py- Open your web browser and navigate to the URL shown in the terminal (typically http://127.0.0.1:7860)
- Paste your code snippet in the text box and click "Submit" to get an explanation
Deploying to Hugging Face Spaces
- Create a new Space on Hugging Face:
- Go to huggingface.co/spaces
- Click "Create new Space"
- Choose "Gradio" as the SDK
- Name your space (e.g., "code-explainer")
- Push your code to the Space:
git remote add space https://huggingface.co/spaces/your-username/your-space-name
git push space main- Set up your Hugging Face API token in the Space settings:
- Go to your Space settings
- Add a secret named
HUGGINGFACEHUB_API_TOKENwith your token
Project Structure
Code-Explainer/
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── data/ # Sample code and documentation
├── sample_code.py
└── docs.txtContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
