Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def predict_image(image):
|
7 |
+
pipe = pipeline("image-classification", model="itsTomLie/Jaundice_Classifier")
|
8 |
+
|
9 |
+
if isinstance(image, np.ndarray):
|
10 |
+
image = Image.fromarray(image.astype('uint8'))
|
11 |
+
elif isinstance(image, str):
|
12 |
+
image = Image.open(image)
|
13 |
+
|
14 |
+
result = pipe(image)
|
15 |
+
|
16 |
+
label = result[0]['label']
|
17 |
+
confidence = result[0]['score']
|
18 |
+
|
19 |
+
print(f"Prediction: {label}, Confidence: {confidence}")
|
20 |
+
|
21 |
+
return label, confidence
|
22 |
+
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=predict_image,
|
25 |
+
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
26 |
+
outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence")]
|
27 |
+
)
|
28 |
+
|
29 |
+
interface.launch()
|