This is a Flask-based application designed exclusively for anonymizing Python code and associated prompts. The app sends anonymized content to an external API, receives processed responses, and reconstructs the original identifiers from the API output. It includes a responsive web interface for user interaction.
- Python Code Anonymization: Strips sensitive identifiers (e.g., function names, variable names) from Python code and replaces them with anonymized placeholders.
- Prompt Anonymization: Maps sensitive terms in prompts using the anonymization mappings generated from the code.
- Submission: Combines anonymized code and prompts for submission to the external API.
- Response Reconstruction: Rebuilds API responses with original identifiers.
- Web Interface: Interactive UI to input Python code and prompts, view anonymized results, and rebuilt responses.
- Python 3.10 or higher
- Flask
- astor
- python-dotenv
- Anthropics Python Client
-
Clone the repository:
git clone https://github.com/your-repo/python-code-anonymizer.git cd python-code-anonymizer
-
Install dependencies:
pip install -r requirements.txt
-
Set up the
.env
file: Create a.env
file in the root directory and add your Anthropic API key:ANTHROPIC_API_KEY=your_anthropic_api_key_here
-
Run the application:
python app.py
-
Access the app: Open a web browser and navigate to
http://127.0.0.1:5000/
.
-
Input Python Code and Prompt: Enter Python code and/or a prompt in the provided fields.
-
Submit: Click the "Anonymize and Send" button to:
- Anonymize the code and prompt.
- Send the anonymized content to the external API.
- View the anonymized content, API response, and reconstructed response.
-
View Results:
- Anonymized Code: Python code with anonymized identifiers.
- Anonymized Prompt: Prompt with anonymized terms based on the code mappings.
- API Response: Raw response from the external API.
- Rebuilt Response: Original response reconstructed using the anonymization mappings.
app.py
: Flask application handling web requests and responses.anonymize.py
: Contains logic for anonymizing Python code and prompts, and rebuilding API responses.key.py
: Manages secure retrieval of the API key from the.env
file.anthropic_api_call.py
: Handles communication with the external API.templates/index.html
: HTML for the web interface.static/scripts.js
: JavaScript for UI interactivity and API integration.static/styles.css
: Styling for the web interface.
- Python-Only: This app is designed to process Python code exclusively. Other programming languages are not supported.
- External API Dependency: Requires a valid API key and access to the Anthropic API for functionality.
-
Input Python Code:
def greet(name): return f"Hello, {name}!"
-
Input Prompt:
What does the `greet` function do?
-
Anonymized Output: Code:
def function0(var0): return f"Hello, {var0}!"
Prompt:
What does the `function0` function do?
-
API Response: Processed response from the external API.
-
Rebuilt Response:
The greet function returns a greeting message for the given name.
Feel free to fork the repository, enhance the project, and submit pull requests.