fcakyon commited on
Commit
e189a6a
·
verified ·
1 Parent(s): 7b4e726

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -25
app.py CHANGED
@@ -1,26 +1,48 @@
1
  import os
2
  import gradio as gr
3
  from dotenv import load_dotenv
4
- from utils import EXAMPLE_ITEMS, analyze, run_example
5
 
6
  load_dotenv()
7
  TOKEN = os.getenv("HF_TOKEN")
8
 
9
- with gr.Blocks(title="Visual Content Moderation") as demo:
10
- gr.Markdown("# Viddexa - Visual Content Moderation")
11
- gr.Markdown("Official demo for [moderators](https://github.com/viddexa/moderators) package.")
12
- gr.Markdown("Upload an image or provide a URL to get an instant content analysis.")
13
- gr.Markdown(
14
- "🔗 **Project Links:** "
15
- "[Model: nsfw-mini](https://huggingface.co/viddexa/nsfw-mini) | "
16
- "[Model: nsfw-nano](https://huggingface.co/viddexa/nsfw-nano) | "
17
- "[Arxiv](https://arxiv.org/abs/2312.16338) | "
18
- "[GitHub](https://github.com/viddexa/moderators) | "
19
- "[PyPI](https://pypi.org/project/moderators/)"
20
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  with gr.Accordion("📄 BibTeX entry for citation", open=False):
23
- gr.Code(
24
  value="""@article{akyon2023nudity,
25
  title={State-of-the-art in nudity classification: A comparative analysis},
26
  author={Akyon, Fatih Cagatay and Temizel, Alptekin},
@@ -29,8 +51,9 @@ with gr.Blocks(title="Visual Content Moderation") as demo:
29
  year={2023},
30
  organization={IEEE}
31
  }""",
32
- language="bibtex",
33
  show_label=False,
 
 
34
  )
35
 
36
  with gr.Row():
@@ -52,12 +75,12 @@ with gr.Blocks(title="Visual Content Moderation") as demo:
52
  with gr.Column(scale=1):
53
  output = gr.Label(label="Classification Scores", num_top_classes=10)
54
 
55
- gr.Markdown("### Examples")
56
- gallery = gr.Gallery(
57
- value=[[url, f"Example {i+1}"] for i, (url, _) in enumerate(EXAMPLE_ITEMS)],
58
- columns=[2, 4],
59
- height=200,
60
- allow_preview=False,
61
  )
62
 
63
  analyze_btn.click(
@@ -66,9 +89,6 @@ with gr.Blocks(title="Visual Content Moderation") as demo:
66
  outputs=output,
67
  )
68
 
69
- gallery.select(
70
- fn=lambda evt: run_example(evt, TOKEN),
71
- outputs=[output, model_choice, url_input],
72
- )
73
 
74
  demo.launch()
 
1
  import os
2
  import gradio as gr
3
  from dotenv import load_dotenv
4
+ from utils import EXAMPLE_ITEMS, analyze
5
 
6
  load_dotenv()
7
  TOKEN = os.getenv("HF_TOKEN")
8
 
9
+ CSS = """
10
+ .header {
11
+ text-align: center;
12
+ padding: 2rem 1rem;
13
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
14
+ color: white;
15
+ border-radius: 8px;
16
+ margin-bottom: 2rem;
17
+ }
18
+ .header h1 { margin: 0; font-size: 2.5em; }
19
+ .header p { margin: 0.5rem 0; opacity: 0.9; }
20
+ .header a { color: white; text-decoration: underline; }
21
+ .footer {
22
+ text-align: center;
23
+ padding: 1rem;
24
+ color: #888;
25
+ margin-top: 2rem;
26
+ }
27
+ """
28
+
29
+ with gr.Blocks(title="Visual Content Moderation", css=CSS) as demo:
30
+ gr.HTML("""
31
+ <div class="header">
32
+ <h1>Viddexa - Visual Content Moderation</h1>
33
+ <p>Official demo for <a href="https://github.com/viddexa/moderators" target="_blank">moderators</a> package</p>
34
+ <p>
35
+ <a href="https://huggingface.co/viddexa/nsfw-mini" target="_blank">Model: nsfw-mini</a> |
36
+ <a href="https://huggingface.co/viddexa/nsfw-nano" target="_blank">Model: nsfw-nano</a> |
37
+ <a href="https://arxiv.org/abs/2312.16338" target="_blank">Arxiv</a> |
38
+ <a href="https://github.com/viddexa/moderators" target="_blank">GitHub</a> |
39
+ <a href="https://pypi.org/project/moderators/" target="_blank">PyPI</a>
40
+ </p>
41
+ </div>
42
+ """)
43
 
44
  with gr.Accordion("📄 BibTeX entry for citation", open=False):
45
+ gr.Textbox(
46
  value="""@article{akyon2023nudity,
47
  title={State-of-the-art in nudity classification: A comparative analysis},
48
  author={Akyon, Fatih Cagatay and Temizel, Alptekin},
 
51
  year={2023},
52
  organization={IEEE}
53
  }""",
 
54
  show_label=False,
55
+ lines=8,
56
+ max_lines=8,
57
  )
58
 
59
  with gr.Row():
 
75
  with gr.Column(scale=1):
76
  output = gr.Label(label="Classification Scores", num_top_classes=10)
77
 
78
+ gr.Examples(
79
+ examples=[[None, url, model] for url, model in EXAMPLE_ITEMS],
80
+ inputs=[image_input, url_input, model_choice],
81
+ outputs=output,
82
+ fn=lambda img, url, model: analyze(img, url, model, TOKEN),
83
+ cache_examples=False,
84
  )
85
 
86
  analyze_btn.click(
 
89
  outputs=output,
90
  )
91
 
92
+ gr.HTML('<div class="footer">Developed by Viddexa</div>')
 
 
 
93
 
94
  demo.launch()