Spaces:
Sleeping
Sleeping
| 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() | |