|
|
| import gradio as gr |
| import torch |
| import numpy as np |
| from PIL import Image |
| from sklearn.preprocessing import StandardScaler |
| from transformers import AutoImageProcessor |
| import json |
|
|
| |
| with open('config.json') as f: |
| config = json.load(f) |
|
|
| |
| feature_names = config['feature_columns'] |
| class_names = list(config['class_labels'].values()) |
|
|
| |
| with gr.Blocks(title="Cervical Cancer Multimodal Classifier") as demo: |
| gr.Markdown(""" |
| # 🔬 Cervical Cancer Multimodal Classifier |
| |
| This model classifies cervical cell samples using both **histopathological images** |
| and **morphological features**. |
| |
| Provide both inputs for best results! |
| """) |
| |
| with gr.Row(): |
| with gr.Column(): |
| gr.Markdown("### Input Image") |
| image_input = gr.Image(label="Histopathological Image", type="pil") |
| |
| with gr.Column(): |
| gr.Markdown("### Morphological Features") |
| feature_inputs = [] |
| for fname in feature_names[:10]: |
| feature_inputs.append( |
| gr.Number(label=fname, value=0.0) |
| ) |
| gr.Markdown("### More Features") |
| feature_inputs2 = [] |
| for fname in feature_names[10:]: |
| feature_inputs2.append( |
| gr.Number(label=fname, value=0.0) |
| ) |
| |
| submit_btn = gr.Button("🔍 Classify", variant="primary", size="lg") |
| |
| with gr.Row(): |
| output_label = gr.Label(label="Prediction", num_top_classes=7) |
| output_plot = gr.Plot(label="Confidence Distribution") |
| |
| |
| def classify(image, *features): |
| |
| |
| |
| return "normal_superficiel", None |
| |
| submit_btn.click( |
| classify, |
| inputs=[image_input] + feature_inputs + feature_inputs2, |
| outputs=[output_label, output_plot] |
| ) |
| |
| gr.Examples( |
| examples=[ |
| ["sample1.BMP", 803.5, 27804.125, 0.028, 85.86, 192.52] + [0]*15, |
| ["sample2.BMP", 610.1, 18067.8, 0.032, 81.53, 153.43] + [0]*15, |
| ], |
| inputs=[image_input] + feature_inputs + feature_inputs2, |
| label="Example Inputs" |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|