Hemg commited on
Commit
7adf524
·
verified ·
1 Parent(s): 938e2ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the image classification pipeline
5
+ pipeline = pipeline(task="image-classification", model="Hemg/Melanoma-Cancer-Image-Classification")
6
+
7
+ def predict(input_img):
8
+ try:
9
+ # Use the pipeline to make predictions
10
+ predictions = pipeline(input_img)
11
+ # Process the predictions
12
+ result = {p["label"]: p["score"] for p in predictions}
13
+ except:
14
+ # If an exception occurs (e.g., out-of-context image), return a default result
15
+ result = {"out_of_context": 1.0}
16
+
17
+ # Return the input image and the result
18
+ return input_img, result
19
+
20
+ # Create a Gradio interface
21
+ gradio_app = gr.Interface(
22
+ predict,
23
+ inputs=gr.Image(label="Melanoma-Cancer-Image-classification", sources=['upload', 'webcam'], type="pil"),
24
+ outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
25
+ title="Benign ? Or Malignant?"
26
+ )
27
+
28
+ # Launch the Gradio app
29
+ if __name__ == "__main__":
30
+ gradio_app.launch()