File size: 2,291 Bytes
54afcfb
 
0326be8
fdaab4a
0326be8
54afcfb
0326be8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9cfef3d
 
0326be8
 
 
54afcfb
0326be8
 
 
 
 
4e6d175
0326be8
 
8c8a578
0326be8
8c8a578
0326be8
 
4e6d175
0326be8
 
 
 
 
 
 
 
 
 
8c8a578
0326be8
 
4e088d7
0326be8
9cfef3d
0326be8
bab77b5
0326be8
4e088d7
0326be8
 
54afcfb
 
0326be8
9cfef3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr
import torch
import torchvision.transforms as transforms
from PIL import Image
from model import load_model

# Load model
model_path = 'best_model_augmented.pth'
model = load_model(model_path)

# Define preprocessing transformations
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
])

# Define the class names
class_names = ['Normal', 'Monkeypox', 'Chickenpox', 'Measles']

def predict_image(image):
    # Preprocess the image
    image = Image.fromarray(image)
    image = transform(image).unsqueeze(0)
    
    # Perform inference
    model.eval()
    with torch.no_grad():
        outputs = model(image)
        _, predicted = torch.max(outputs, 1)
        predicted_class = class_names[predicted.item()]
    
    return predicted_class

# HTML for custom styling
title = (
    "<h1 style='text-align: center; font-family: Arial, sans-serif;'>PoxNet</h1>"
    "<p style='text-align: center; font-family: Arial, sans-serif;'>"
    "<a href='https://x.com/ronith_sharmila' target='_blank'>@ronithsharmila</a>"
    "</p>"
)

description = (
    "<p style='text-align: center; font-family: Arial, sans-serif;'>"
    "Upload an image of a skin lesion to classify it into one of the following categories:</p>"
    "<p style='text-align: center; font-family: Arial, sans-serif; font-weight: bold;'>"
    "Normal, Monkeypox, Chickenpox, Measles</p>"
    "<p style='text-align: center; font-family: Arial, sans-serif;'>"
    "Please note that this model is not a substitute for professional medical advice, diagnosis, or treatment. "
    "Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition."
    "</p>"
    "<p style='text-align: center; font-family: Arial, sans-serif;'>"
    "<a href='https://paypal.me/ronithsharmila?country.x=US&locale.x=en_US' target='_blank'>SUPPORT MY PROJECTS HERE !</a>"
    "</p>"
)

# Gradio app interface
app = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="numpy", label="Upload Image"),
    outputs=gr.Textbox(label="Prediction"),
    title=title,
    description=description,
    theme="default"  # Use the default theme or specify a different theme if available
)

# Launch the app
app.launch()