JYL480 commited on
Commit
eef3718
1 Parent(s): 90841c2
SkinCancerClass/.__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from model import predict
SkinCancerClass/__pycache__/model.cpython-310.pyc ADDED
Binary file (884 Bytes). View file
 
SkinCancerClass/app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import torch
4
+
5
+
6
+ from demos.SkinCancerClass.model import predict
7
+
8
+
9
+ class_names = [ 'benign_keratosis-like_lesions','basal_cell_carcinoma','actinic_keratoses','dermatofibroma','melanocytic_Nevi']
10
+ example_names = ["actinic_keratoses","basal_cell_carcinoma","melanocytic_Nevi"]
11
+
12
+ title = "Skin Cancer Classifier"
13
+ description = "An ViT computer vision model to classify images from HAM10000 dataset, a large collection of multi-source dermatoscopic images of common pigmented skin lesions. <br/> List: benign_keratosis-like_lesions, basal_cell_carcinoma, actinic_keratoses, dermatofibroma, melanocytic_Nevi"
14
+ article = "https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/DBW86T"
15
+
16
+ # Create examples list from "examples/" directory
17
+ example_list = [["examples/" + example, example.split('_')[0]] for example in os.listdir("examples")]
18
+ # print(example_list)
19
+ # result , timing = predict(example_list[0])
20
+ #
21
+
22
+ # Create a single dictionary
23
+
24
+
25
+ # Output the combined dictionary
26
+ # print(combined_dict)
27
+
28
+ # Create the Gradio demo
29
+ # The output of the prediction must be in a dictionary format!
30
+ demo = gr.Interface(fn=predict, # mapping function from input to output
31
+ inputs=gr.Image(type="pil"), # what are the inputs?
32
+ outputs=[gr.Label(num_top_classes=5, label="Predictions"), # what are the outputs?
33
+ gr.Number(label="Prediction time (s)")],
34
+ examples=example_list,
35
+ title=title,
36
+ description=description,
37
+ article=article,
38
+ example_labels=example_names)
39
+
40
+ # Launch the demo!
41
+ demo.launch(debug=False, # print errors locally?
42
+ share=True) # generate a publically shareable URL?
SkinCancerClass/examples/actinic_keratoses.jpg ADDED
SkinCancerClass/examples/basal_cell_carcinoma.jpg ADDED
SkinCancerClass/examples/melanocytic_Nevi.jpg ADDED
SkinCancerClass/model.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Here will be the inference to my model on hugging face!!
2
+ # Use a pipeline as a high-level helper
3
+
4
+ from timeit import default_timer as timer
5
+ from typing import Tuple, Dict
6
+ from transformers import pipeline
7
+
8
+ pipe = pipeline("image-classification", model="JYL480/vit-base-images")
9
+
10
+ image_path = "examples/melanocytic_Nevi.jpg"
11
+
12
+
13
+ def predict(image):
14
+ start = timer()
15
+ result = pipe(image)
16
+ print(result)
17
+ pred_time = round(timer() - start, 5)
18
+ combined_dict = {item['label']: float(item['score']) for item in result}
19
+ return combined_dict, pred_time
20
+
21
+ # combined_dict, pred_time = predict(image_path)
22
+ # print(combined_dict)
SkinCancerClass/requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch == 2.4.0
2
+ Pillow == 10.4.0
3
+ transformers == 4.43.3
4
+ gradio == 4.40.0