Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,32 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
|
4 |
-
# Load
|
5 |
-
|
|
|
6 |
|
7 |
-
# Define
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
#
|
27 |
-
|
|
|
1 |
+
import torch
|
2 |
+
from torchvision import models, transforms
|
3 |
+
from torch import nn, optim
|
4 |
+
from PIL import Image
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
+
# Load a pre-trained model (e.g., ResNet50)
|
8 |
+
model = models.resnet50(pretrained=True)
|
9 |
+
model.fc = nn.Linear(model.fc.in_features, 2) # For binary classification (Thyroid: Positive/Negative)
|
10 |
|
11 |
+
# Define image transformation
|
12 |
+
transform = transforms.Compose([
|
13 |
+
transforms.Resize((224, 224)),
|
14 |
+
transforms.ToTensor(),
|
15 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
16 |
+
])
|
17 |
+
|
18 |
+
# Example function to classify images
|
19 |
+
def classify_thyroid_image(image):
|
20 |
+
image = Image.open(image).convert("RGB")
|
21 |
+
image = transform(image).unsqueeze(0) # Add batch dimension
|
22 |
+
model.eval() # Set the model to evaluation mode
|
23 |
|
24 |
+
with torch.no_grad():
|
25 |
+
output = model(image)
|
26 |
+
_, predicted = torch.max(output, 1)
|
27 |
+
|
28 |
+
diagnosis = "Thyroid Disease Detected" if predicted.item() == 1 else "No Thyroid Disease"
|
29 |
+
return diagnosis
|
30 |
|
31 |
+
# Create a Gradio interface for image upload and camera input
|
32 |
+
gr.Interface(fn=classify_thyroid_image, inputs="image", outputs="text").launch()
|