CoolFace
Apppublic

shrutimaurya1104/code-quality-assessment

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py36 linesDownload Raw Back to root
1import streamlit as st2from analyzers.linter import run_pylint, run_flake8, run_bandit3from analyzers.ml_model import predict_code_quality4 5st.title("๐Ÿง‘โ€๐Ÿ’ป Code Quality Assessment Tool")6 7uploaded_file = st.file_uploader("Upload a Python file", type=["py"])8 9if uploaded_file is not None:10    # Normalize line endings11    code = uploaded_file.read().decode("utf-8").replace("\r\n", "\n")12 13    st.subheader("๐Ÿ“„ Uploaded Code")14    st.code(code, language="python")15 16    # Save temporarily17    with open("temp.py", "w", encoding="utf-8") as f:18        f.write(code)19 20    st.subheader("๐Ÿ“Š Static Analysis Results")21    pylint_result = run_pylint("temp.py")22    flake8_result = run_flake8("temp.py")23    bandit_result = run_bandit("temp.py")24 25    st.text("Pylint Results:\n" + pylint_result)26    st.text("Flake8 Results:\n" + flake8_result)27    st.text("Bandit Results:\n" + bandit_result)28 29    # Count number of errors (crude but effective)30    pylint_errors = sum(1 for line in pylint_result.splitlines() if line.strip())31    flake8_errors = sum(1 for line in flake8_result.splitlines() if line.strip())32 33    st.subheader("๐Ÿค– ML-Based Quality Score")34    score = predict_code_quality(code, pylint_errors, flake8_errors)35    st.metric("Predicted Quality Score", f"{score}/100")36