sastelvio commited on
Commit
3832e65
·
verified ·
1 Parent(s): 0fc4e8c

Upload multimodal cervical cancer classifier

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import torch
4
+ import numpy as np
5
+ from PIL import Image
6
+ from sklearn.preprocessing import StandardScaler
7
+ from transformers import AutoImageProcessor
8
+ import json
9
+
10
+ # Load configuration
11
+ with open('config.json') as f:
12
+ config = json.load(f)
13
+
14
+ # Expected features
15
+ feature_names = config['feature_columns']
16
+ class_names = list(config['class_labels'].values())
17
+
18
+ # Interface Gradio
19
+ with gr.Blocks(title="Cervical Cancer Multimodal Classifier") as demo:
20
+ gr.Markdown("""
21
+ # 🔬 Cervical Cancer Multimodal Classifier
22
+
23
+ This model classifies cervical cell samples using both **histopathological images**
24
+ and **morphological features**.
25
+
26
+ Provide both inputs for best results!
27
+ """)
28
+
29
+ with gr.Row():
30
+ with gr.Column():
31
+ gr.Markdown("### Input Image")
32
+ image_input = gr.Image(label="Histopathological Image", type="pil")
33
+
34
+ with gr.Column():
35
+ gr.Markdown("### Morphological Features")
36
+ feature_inputs = []
37
+ for fname in feature_names[:10]:
38
+ feature_inputs.append(
39
+ gr.Number(label=fname, value=0.0)
40
+ )
41
+ gr.Markdown("### More Features")
42
+ feature_inputs2 = []
43
+ for fname in feature_names[10:]:
44
+ feature_inputs2.append(
45
+ gr.Number(label=fname, value=0.0)
46
+ )
47
+
48
+ submit_btn = gr.Button("🔍 Classify", variant="primary", size="lg")
49
+
50
+ with gr.Row():
51
+ output_label = gr.Label(label="Prediction", num_top_classes=7)
52
+ output_plot = gr.Plot(label="Confidence Distribution")
53
+
54
+ # Callback funtion (simplified)
55
+ def classify(image, *features):
56
+ # Load model from Hub
57
+ # Make prediction
58
+ # Return results
59
+ return "normal_superficiel", None
60
+
61
+ submit_btn.click(
62
+ classify,
63
+ inputs=[image_input] + feature_inputs + feature_inputs2,
64
+ outputs=[output_label, output_plot]
65
+ )
66
+
67
+ gr.Examples(
68
+ examples=[
69
+ ["sample1.BMP", 803.5, 27804.125, 0.028, 85.86, 192.52] + [0]*15,
70
+ ["sample2.BMP", 610.1, 18067.8, 0.032, 81.53, 153.43] + [0]*15,
71
+ ],
72
+ inputs=[image_input] + feature_inputs + feature_inputs2,
73
+ label="Example Inputs"
74
+ )
75
+
76
+ if __name__ == "__main__":
77
+ demo.launch()