Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
from transformers import AutoModelForImageClassification, ViTImageProcessor
|
5 |
-
import numpy as np
|
6 |
|
7 |
# Load model
|
8 |
model = AutoModelForImageClassification.from_pretrained("Falconsai/nsfw_image_detection")
|
@@ -10,15 +9,6 @@ processor = ViTImageProcessor.from_pretrained('Falconsai/nsfw_image_detection')
|
|
10 |
|
11 |
# Function to make predictions
|
12 |
def classify_image(img):
|
13 |
-
# Check if img is a NumPy array
|
14 |
-
if isinstance(img, np.ndarray):
|
15 |
-
# Convert NumPy array to PIL.Image.Image
|
16 |
-
img = Image.fromarray(img)
|
17 |
-
|
18 |
-
# Check if img is PIL.Image.Image
|
19 |
-
if not isinstance(img, Image.Image):
|
20 |
-
return "Error: Invalid image"
|
21 |
-
|
22 |
with torch.no_grad():
|
23 |
inputs = processor(images=img, return_tensors="pt")
|
24 |
outputs = model(**inputs)
|
@@ -32,8 +22,12 @@ iface = gr.Interface(
|
|
32 |
fn=classify_image,
|
33 |
inputs="image",
|
34 |
outputs="text",
|
35 |
-
live=True
|
|
|
36 |
)
|
37 |
|
38 |
# Launch the Gradio Interface
|
39 |
-
iface.launch(
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
from transformers import AutoModelForImageClassification, ViTImageProcessor
|
|
|
5 |
|
6 |
# Load model
|
7 |
model = AutoModelForImageClassification.from_pretrained("Falconsai/nsfw_image_detection")
|
|
|
9 |
|
10 |
# Function to make predictions
|
11 |
def classify_image(img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
with torch.no_grad():
|
13 |
inputs = processor(images=img, return_tensors="pt")
|
14 |
outputs = model(**inputs)
|
|
|
22 |
fn=classify_image,
|
23 |
inputs="image",
|
24 |
outputs="text",
|
25 |
+
live=True,
|
26 |
+
interpretation="default"
|
27 |
)
|
28 |
|
29 |
# Launch the Gradio Interface
|
30 |
+
iface.launch()
|
31 |
+
|
32 |
+
|
33 |
+
#gr.load("models/Falconsai/nsfw_image_detection").launch()
|