File size: 4,858 Bytes
5cc8194
 
 
 
 
eb19216
ceaabcd
 
 
 
dc07abb
ceaabcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb19216
 
 
 
 
 
 
ceaabcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cc8194
 
f5864cf
41fb203
 
 
dc07abb
7a59ade
5cc8194
eb19216
5cc8194
 
eb19216
5cc8194
eb19216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41fb203
 
 
7a59ade
eb19216
5cc8194
41fb203
 
 
 
5cc8194
7a59ade
 
 
5cc8194
 
 
41fb203
 
5cc8194
41fb203
5cc8194
 
 
 
 
 
 
 
 
 
 
 
 
7a59ade
 
5cc8194
41fb203
5cc8194
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Skin Disease Detection using Vision Transformer</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            background-color: #f0f2f5;
            color: #333;
        }
        h1 {
            margin-top: 20px;
            font-size: 2em;
            color: #4a90e2;
        }
        .upload-container {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            text-align: center;
            margin: 20px 0;
            width: 80%;
            max-width: 500px;
        }
        input[type="file"] {
            margin: 20px 0;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: calc(100% - 22px);
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #4a90e2;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #357ab8;
        }
        .result {
            margin-top: 20px;
            font-size: 1.1em;
            font-weight: bold;
            color: #333;
        }
        .image-preview {
            margin-top: 20px;
            max-width: 100%;
            height: auto;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .iframe-container {
            width: 90%;
            max-width: 850px;
            height: 450px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            overflow: hidden;
            margin-bottom: 20px;
        }
        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }
    </style>
</head>
<body>
    <h1>Skin Disease Detection using Vision Transformer</h1>

    <!-- Upload and Prediction Section -->
    <div class="upload-container">
        <input type="file" id="file-input" accept="image/*" required />
        <button onclick="uploadImage()" id="upload-button">Upload and Predict</button>
        <div class="result" id="result"></div>
        <img id="image-preview" class="image-preview" style="display: none;" />
    </div>

    
    <script>
        document.getElementById('file-input').addEventListener('change', previewImage);

        function previewImage() {
            const fileInput = document.getElementById('file-input');
            const imagePreview = document.getElementById('image-preview');
            
            const file = fileInput.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    imagePreview.src = e.target.result;
                    imagePreview.style.display = 'block';
                };
                reader.readAsDataURL(file);
            }
        }

        async function uploadImage() {
            const fileInput = document.getElementById('file-input');
            const resultDiv = document.getElementById('result');
            const uploadButton = document.getElementById('upload-button');
            const imagePreview = document.getElementById('image-preview');

            if (!fileInput.files.length) {
                alert("Please select a file.");
                return;
            }

            resultDiv.textContent = '';
            uploadButton.disabled = true;

            const formData = new FormData();
            formData.append('file', fileInput.files[0]);

            resultDiv.textContent = 'Predicting...';

            try {
                const response = await fetch('https://zaman855-vit-css.hf.space/predict/', {
                    method: 'POST',
                    body: formData
                });

                if (response.ok) {
                    const data = await response.json();
                    resultDiv.textContent = `Predicted Class: ${data.predicted_class}, Confidence: ${data.confidence.toFixed(2)}`;
                } else {
                    resultDiv.textContent = 'Error: Prediction failed.';
                }
            } catch (error) {
                console.error('Error:', error);
                resultDiv.textContent = 'Error: Unable to connect to the server.';
            } finally {
                uploadButton.disabled = false;
            }
        }
    </script>
</body>
</html>