moderators / app.py
fcakyon's picture
Update app.py
eebea30 verified
import os
import gradio as gr
from dotenv import load_dotenv
from utils import analyze, prepare_examples
load_dotenv()
TOKEN = os.getenv("HF_TOKEN")
EXAMPLES = prepare_examples()
CSS = """
.header {
text-align: center;
padding: 2rem 1rem;
background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
color: white;
border-radius: 8px;
margin-bottom: 2rem;
}
.header-logo {
max-width: 400px;
height: auto;
margin: 0 auto;
display: block;
}
.header p { margin: 0.5rem 0; opacity: 0.9; }
.header a { color: white; text-decoration: underline; }
/* Hide built-in Gradio footer */
footer {
display: none !important;
}
/* Custom footer styling */
.custom-footer {
text-align: center;
padding: 1rem;
color: #888;
margin-top: 2rem;
}
"""
with gr.Blocks(
title="Visual Content Moderation",
css=CSS,
theme=gr.themes.Default(primary_hue=gr.themes.colors.teal),
analytics_enabled=False,
) as demo:
gr.HTML("""
<div class="header">
<img src="https://github.com/viddexa/moderators/releases/download/v0.1.1/logo-v2.jpeg" alt="Visual Content Moderation" class="header-logo">
<p>Official demo for the <a href="https://github.com/viddexa/moderators" target="_blank">moderators</a> package</p>
<p>
<a href="https://huggingface.co/viddexa/nsfw-detection-2-mini" target="_blank">Model: nsfw-detection-2-mini</a> |
<a href="https://huggingface.co/viddexa/nsfw-detection-2-nano" target="_blank">Model: nsfw-detection-2-nano</a> |
<a href="https://arxiv.org/abs/2312.16338" target="_blank">Arxiv</a> |
<a href="https://github.com/viddexa/moderators" target="_blank">GitHub</a> |
<a href="https://pypi.org/project/moderators/" target="_blank">PyPI</a>
</p>
</div>
""")
with gr.Accordion("πŸ“„ BibTeX entry for citation", open=False):
gr.Textbox(
value="""@article{akyon2023nudity,
title={State-of-the-art in nudity classification: A comparative analysis},
author={Akyon, Fatih Cagatay and Temizel, Alptekin},
booktitle={2023 IEEE International Conference on Acoustics, Speech, and Signal Processing Workshops (ICASSPW)},
pages={1--5},
year={2023},
organization={IEEE}
}""",
show_label=False,
lines=9,
max_lines=9,
)
with gr.Row():
with gr.Column(scale=1):
model_choice = gr.Dropdown(
choices=["viddexa/nsfw-detection-2-mini", "viddexa/nsfw-detection-2-nano"],
value="viddexa/nsfw-detection-2-mini",
label="Model",
)
with gr.Tabs():
with gr.TabItem("Upload"):
image_input = gr.Image(type="filepath", label="Image")
with gr.TabItem("URL"):
url_input = gr.Textbox(label="Image URL", placeholder="https://...")
analyze_btn = gr.Button("Analyze", variant="primary")
with gr.Column(scale=1):
output = gr.Label(label="Classification Scores", num_top_classes=5)
gr.Markdown("### 🎯 Try an Example")
gr.Examples(
examples=EXAMPLES,
inputs=[image_input, model_choice],
outputs=output,
fn=lambda img, model: analyze(img, None, model, TOKEN),
cache_examples=True,
run_on_click=True,
)
analyze_btn.click(
fn=lambda img, url, model: analyze(img, url, model, TOKEN),
inputs=[image_input, url_input, model_choice],
outputs=output,
)
gr.HTML('<div class="custom-footer">Developed by Viddexa</div>')
demo.launch()