File size: 787 Bytes
fd27a87
 
 
 
 
 
 
74bbeff
fd27a87
 
 
 
 
74bbeff
 
 
fd27a87
74bbeff
 
fd27a87
74bbeff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import AutoTokenizer, AutoModelForImageClassification
from PIL import Image
import requests
import torch

# Load model from Hugging Face model hub
model_name = "best20.pt"  # Replace with your model's name on Hugging Face
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)

# Define function for image preprocessing and prediction
def process_image(image):
   img_4d=img.reshape(-1,256,256,3)
  prediction=Model.predict(img_4d)[0]
  return {class_names[i]: float(prediction[i]) for i in range(3)}

image = gr.inputs.Image(shape=(256,256))
label = gr.outputs.Label(num_top_classes=3)

gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch()