Spaces:
Running on Zero
Running on Zero
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import spaces
|
| 4 |
+
|
| 5 |
+
# تحميل نموذج كشف العري على كرت الشاشة السريع
|
| 6 |
+
pipe = pipeline("image-classification", model="Falconsai/nsfw_image_detection")
|
| 7 |
+
|
| 8 |
+
@spaces.GPU
|
| 9 |
+
def predict(image):
|
| 10 |
+
if image is None:
|
| 11 |
+
return {"nsfw": False, "score": 0.0}
|
| 12 |
+
|
| 13 |
+
results = pipe(image)
|
| 14 |
+
nsfw_score = 0.0
|
| 15 |
+
for r in results:
|
| 16 |
+
if r['label'].lower() == 'nsfw':
|
| 17 |
+
nsfw_score = r['score']
|
| 18 |
+
|
| 19 |
+
return {
|
| 20 |
+
"nsfw": nsfw_score > 0.60,
|
| 21 |
+
"score": round(nsfw_score, 3)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=predict,
|
| 26 |
+
inputs=gr.Image(type="pil"),
|
| 27 |
+
outputs="json",
|
| 28 |
+
title="Safe Watch AI"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|