Gun_detection / app.py
NKASG's picture
Update app.py
ff58162 verified
raw
history blame
789 Bytes
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=1)
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch()