Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
-
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
| 5 |
|
| 6 |
-
|
| 7 |
-
model = ViTForImageClassification.from_pretrained("Falconsai/nsfw_image_detection")
|
| 8 |
-
processor = ViTFeatureExtractor.from_pretrained("Falconsai/nsfw_image_detection")
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 13 |
-
with torch.no_grad():
|
| 14 |
-
outputs = model(**inputs)
|
| 15 |
-
logits = outputs.logits
|
| 16 |
-
predicted_class_idx = logits.argmax(-1).item()
|
| 17 |
-
label = model.config.id2label[predicted_class_idx]
|
| 18 |
-
return label
|
| 19 |
|
| 20 |
-
|
| 21 |
-
demo = gr.Interface(
|
| 22 |
-
fn=predict,
|
| 23 |
-
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 24 |
-
outputs=gr.Label(label="Prediction"),
|
| 25 |
-
title="NSFW Image Detection (ViT)",
|
| 26 |
-
description="Upload an image to classify if it's NSFW or SFW."
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from flask import Flask
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def greet(name):
|
| 7 |
+
return f"Hello, {name}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
gradio_interface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
gr.mount_gradio_app(app, gradio_interface, path="/gradio")
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
app.run()
|