Spaces:
Sleeping
Sleeping
Download app.py from erayman09/secure-code-reviewer: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/erayman09/secure-code-reviewer/resolve/main/app.py
- Command line
-
hf download hf://spaces/erayman09/secure-code-reviewer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/erayman09/secure-code-reviewer/resolve/main/app.py
1.02 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the Microsoft CodeReviewer model | |
| code_analyzer = pipeline("text-classification", model="microsoft/codereviewer") | |
| # Function to analyze code snippets | |
| def analyze_code(code_snippet): | |
| result = code_analyzer(code_snippet) | |
| # Interpret the model's output | |
| if result[0]["label"] == "LABEL_1": # Assuming LABEL_1 means insecure or problematic | |
| return ( | |
| f"⚠️ chi haja matmach ajmi: {result[0]['label']} " | |
| f"(ti9a: {result[0]['score']:.2f})\n" | |
| "💡 Suggestion: Review the flagged code section and improve it according to best practices." | |
| ) | |
| else: | |
| return "✅ Code m9wd wlah!" | |
| # Gradio interface setup | |
| interface = gr.Interface( | |
| fn=analyze_code, | |
| inputs="text", | |
| outputs="text", | |
| title="Microsoft Code Reviewer", | |
| description="Paste a code snippet to analyze for vulnerabilities or improvements." | |
| ) | |
| # Launch the interface | |
| if __name__ == "__main__": | |
| interface.launch() | |