Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from bioscore import reproducibility, data_quality, model_readiness
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def check_reproducibility(file):
|
| 8 |
+
if file is None:
|
| 9 |
+
return "Please upload a .ipynb or .py file"
|
| 10 |
+
result = reproducibility(file.name)
|
| 11 |
+
level_emoji = {"full": "✅", "partial": "⚠️", "minimal": "❌"}
|
| 12 |
+
emoji = level_emoji.get(result["level"], "")
|
| 13 |
+
output = f"{emoji} Level: **{result['level']}** (score: {result['score']})\n\n"
|
| 14 |
+
if result["issues"]:
|
| 15 |
+
output += "**Issues found:**\n"
|
| 16 |
+
for issue in result["issues"]:
|
| 17 |
+
output += f"- {issue}\n"
|
| 18 |
+
else:
|
| 19 |
+
output += "No issues found — fully reproducible!"
|
| 20 |
+
return output
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def check_data_quality(file, domain):
|
| 24 |
+
if file is None:
|
| 25 |
+
return "Please upload a .csv file"
|
| 26 |
+
result = data_quality(file.name, domain=domain)
|
| 27 |
+
output = f"**Overall quality:** {result['overall']} / 1.0\n\n"
|
| 28 |
+
output += f"- Completeness: {result['completeness']}\n"
|
| 29 |
+
output += f"- Consistency: {result['consistency']}\n"
|
| 30 |
+
if result["overall"] >= 0.8:
|
| 31 |
+
output += "\n✅ Quality is good — safe to proceed with training"
|
| 32 |
+
elif result["overall"] >= 0.5:
|
| 33 |
+
output += "\n⚠️ Quality is moderate — review before training"
|
| 34 |
+
else:
|
| 35 |
+
output += "\n❌ Quality is low — fix data issues before training"
|
| 36 |
+
return output
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def check_model_readiness(file):
|
| 40 |
+
if file is None:
|
| 41 |
+
return "Please upload a .pkl model file"
|
| 42 |
+
result = model_readiness(file.name)
|
| 43 |
+
status = "✅ Ready for production" if result["ready"] else "❌ Not ready for production"
|
| 44 |
+
output = f"{status} (score: {result['score']})\n\n"
|
| 45 |
+
if result["gaps"]:
|
| 46 |
+
output += "**Gaps to fix:**\n"
|
| 47 |
+
for gap in result["gaps"]:
|
| 48 |
+
output += f"- {gap}\n"
|
| 49 |
+
else:
|
| 50 |
+
output += "No gaps — model passes all readiness checks!"
|
| 51 |
+
return output
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
with gr.Blocks(title="bioscore — Biomedical Scoring Toolkit", theme=gr.themes.Base()) as demo:
|
| 55 |
+
gr.Markdown("# 🧬 bioscore\nBiomedical scoring toolkit — reproducibility, data quality, model readiness")
|
| 56 |
+
gr.Markdown("[pip install bioscore](https://pypi.org/project/bioscore/) · [Source](https://github.com/K-RnD-Lab/SPHERE-III-TECHNOLOGY)")
|
| 57 |
+
|
| 58 |
+
with gr.Tab("Reproducibility"):
|
| 59 |
+
gr.Markdown("Upload a Jupyter notebook (.ipynb) or Python script (.py) to check reproducibility")
|
| 60 |
+
rep_file = gr.File(label="Upload notebook/script", file_types=[".ipynb", ".py"])
|
| 61 |
+
rep_btn = gr.Button("Check Reproducibility", variant="primary")
|
| 62 |
+
rep_out = gr.Markdown()
|
| 63 |
+
rep_btn.click(check_reproducibility, inputs=[rep_file], outputs=[rep_out])
|
| 64 |
+
|
| 65 |
+
with gr.Tab("Data Quality"):
|
| 66 |
+
gr.Markdown("Upload a CSV dataset to assess quality")
|
| 67 |
+
dq_file = gr.File(label="Upload CSV", file_types=[".csv"])
|
| 68 |
+
dq_domain = gr.Dropdown(["general", "oncology", "agriculture"], value="general", label="Domain")
|
| 69 |
+
dq_btn = gr.Button("Check Data Quality", variant="primary")
|
| 70 |
+
dq_out = gr.Markdown()
|
| 71 |
+
dq_btn.click(check_data_quality, inputs=[dq_file, dq_domain], outputs=[dq_out])
|
| 72 |
+
|
| 73 |
+
with gr.Tab("Model Readiness"):
|
| 74 |
+
gr.Markdown("Upload a pickled ML model (.pkl) to check production readiness")
|
| 75 |
+
mr_file = gr.File(label="Upload model (.pkl)", file_types=[".pkl"])
|
| 76 |
+
mr_btn = gr.Button("Check Model Readiness", variant="primary")
|
| 77 |
+
mr_out = gr.Markdown()
|
| 78 |
+
mr_btn.click(check_model_readiness, inputs=[mr_file], outputs=[mr_out])
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
demo.launch()
|