Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Load the model and processor
|
7 |
+
processor = AutoImageProcessor.from_pretrained("prithivMLmods/Fire-Detection-Engine")
|
8 |
+
model = AutoModelForImageClassification.from_pretrained("prithivMLmods/Fire-Detection-Engine")
|
9 |
+
|
10 |
+
def predict(image):
|
11 |
+
# Convert image to expected format
|
12 |
+
image = Image.fromarray(image)
|
13 |
+
inputs = processor(images=image, return_tensors="pt")
|
14 |
+
with torch.no_grad():
|
15 |
+
outputs = model(**inputs)
|
16 |
+
logits = outputs.logits
|
17 |
+
predicted_class = logits.argmax(-1).item()
|
18 |
+
|
19 |
+
return f"Predicted class: {predicted_class}"
|
20 |
+
|
21 |
+
# Create Gradio app
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=gr.Image(type="numpy"),
|
25 |
+
outputs=gr.Textbox(),
|
26 |
+
title="Fire Detection Engine",
|
27 |
+
description="Upload an image to check for fire."
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch()
|