Spaces:
Sleeping
Sleeping
File size: 913 Bytes
0bab57f |
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 |
import gradio as gr
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch
# Load the model and processor
processor = AutoImageProcessor.from_pretrained("prithivMLmods/Fire-Detection-Engine")
model = AutoModelForImageClassification.from_pretrained("prithivMLmods/Fire-Detection-Engine")
def predict(image):
# Convert image to expected format
image = Image.fromarray(image)
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class = logits.argmax(-1).item()
return f"Predicted class: {predicted_class}"
# Create Gradio app
iface = gr.Interface(
fn=predict,
inputs=gr.Image(type="numpy"),
outputs=gr.Textbox(),
title="Fire Detection Engine",
description="Upload an image to check for fire."
)
iface.launch()
|