File size: 1,262 Bytes
1eebc45
 
 
 
 
a8b4012
 
 
 
 
 
1eebc45
 
f62790a
1eebc45
f62790a
 
 
 
 
 
 
1eebc45
 
 
 
 
 
 
 
f62790a
1eebc45
 
 
 
f62790a
 
1eebc45
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
# -*- coding: utf-8 -*-

# %%capture
# #Use capture to not show the output of installing the libraries!
import gradio as gr
import requests
import torch
import torch.nn as nn
from PIL import Image
from torchvision.models import resnet50
from torchvision.transforms import functional as F
import numpy as np
import tensorflow as tf
from transformers import pipeline

# load the model from the Hugging Face Model Hub
model = pipeline('image-classification', model='image_classification/densenet')


#model = tf.keras.models.load_model('/content/drive/MyDrive/project_image_2023_NO/saved_models/saved_model/densenet')
#labels = ['Healthy', 'Patient']
labels = {0: 'healthy', 1: 'patient'}

def classify_image(inp):
  inp = inp.reshape((-1, 224, 224, 3))
  inp = tf.keras.applications.densenet.preprocess_input(inp)
  prediction = model.predict(inp)
  confidences = {labels[i]: float(prediction[0][i]) for i in range(2)}
  return confidences


gr.Interface(fn=classify_image, 
             inputs=gr.Image(shape=(224, 224)),
             outputs=gr.Label(num_top_classes = 2),
             title="Demo",
             description="Here's a sample image classification. Enjoy!",
             examples=[['path/to/example/image.jpg']]
             ).launch(share = True)