Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,16 @@ from PIL import Image
|
|
8 |
# number convert to label
|
9 |
labels = ["Drawings", "Hentai", "Neutral", "Porn", "Sexy"]
|
10 |
description = """### NSFW 图片分类器 🚀
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
|
|
|
|
|
|
16 |
# Define CNN model
|
17 |
class Classifier(nn.Module):
|
18 |
def __init__(self):
|
@@ -54,18 +59,57 @@ def predict(image_path):
|
|
54 |
return result
|
55 |
|
56 |
# 美化 Gradio 界面
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
gr.Markdown("# 🌟 NSFW 图片分类器")
|
59 |
gr.Markdown(description)
|
60 |
|
61 |
with gr.Row():
|
62 |
with gr.Column():
|
63 |
-
image_input = gr.Image(type="filepath", label="📷 上传图片")
|
64 |
submit_btn = gr.Button("🚀 运行检测", variant="primary")
|
65 |
|
66 |
with gr.Column():
|
67 |
output_label = gr.Label(num_top_classes=2, label="📊 预测结果")
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
submit_btn.click(predict, inputs=image_input, outputs=output_label)
|
70 |
|
71 |
# 启动 Web 界面
|
|
|
8 |
# number convert to label
|
9 |
labels = ["Drawings", "Hentai", "Neutral", "Porn", "Sexy"]
|
10 |
description = """### NSFW 图片分类器 🚀
|
11 |
+
该模型可以分类NSFW(非工作安全)图片,支持以下类别:
|
12 |
+
- **Drawings**:绘画图像
|
13 |
+
- **Hentai**:色情漫画
|
14 |
+
- **Neutral**:中立图像
|
15 |
+
- **Porn**:成人内容
|
16 |
+
- **Sexy**:性感内容
|
17 |
|
18 |
+
上传一张图片,我们将为您预测其类别。
|
19 |
+
更多信息请访问 [GitHub](https://github.com/csuer411/nsfw_classify)"""
|
20 |
+
|
21 |
# Define CNN model
|
22 |
class Classifier(nn.Module):
|
23 |
def __init__(self):
|
|
|
59 |
return result
|
60 |
|
61 |
# 美化 Gradio 界面
|
62 |
+
css = """
|
63 |
+
.gradio-container {
|
64 |
+
font-family: 'Arial', sans-serif;
|
65 |
+
background-color: #f0f4f8;
|
66 |
+
}
|
67 |
+
.gr-button {
|
68 |
+
background-color: #4CAF50;
|
69 |
+
color: white;
|
70 |
+
font-weight: bold;
|
71 |
+
}
|
72 |
+
.gr-button:hover {
|
73 |
+
background-color: #45a049;
|
74 |
+
}
|
75 |
+
.gr-label {
|
76 |
+
font-size: 1.2em;
|
77 |
+
font-weight: bold;
|
78 |
+
}
|
79 |
+
.gr-image {
|
80 |
+
border: 2px solid #4CAF50;
|
81 |
+
border-radius: 8px;
|
82 |
+
}
|
83 |
+
.gr-row {
|
84 |
+
margin-bottom: 20px;
|
85 |
+
}
|
86 |
+
.gr-markdown {
|
87 |
+
color: #333;
|
88 |
+
}
|
89 |
+
.gr-input {
|
90 |
+
border-radius: 5px;
|
91 |
+
}
|
92 |
+
footer {visibility: hidden}
|
93 |
+
"""
|
94 |
+
|
95 |
+
with gr.Blocks(theme="huggingface", css=css) as demo:
|
96 |
gr.Markdown("# 🌟 NSFW 图片分类器")
|
97 |
gr.Markdown(description)
|
98 |
|
99 |
with gr.Row():
|
100 |
with gr.Column():
|
101 |
+
image_input = gr.Image(type="filepath", label="📷 上传图片", elem_id="input-image")
|
102 |
submit_btn = gr.Button("🚀 运行检测", variant="primary")
|
103 |
|
104 |
with gr.Column():
|
105 |
output_label = gr.Label(num_top_classes=2, label="📊 预测结果")
|
106 |
+
gr.Markdown("#### 示例图片")
|
107 |
+
examples = [
|
108 |
+
"./example/anime.jpg",
|
109 |
+
"./example/real.jpg"
|
110 |
+
]
|
111 |
+
gr.Image(examples=examples, type="filepath", label="点击上传示例图片", elem_id="example-images")
|
112 |
+
|
113 |
submit_btn.click(predict, inputs=image_input, outputs=output_label)
|
114 |
|
115 |
# 启动 Web 界面
|