Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,16 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
-
from
|
| 5 |
-
from utils import EXAMPLE_ITEMS, analyze, download_image
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
|
| 10 |
-
# Prepare example images
|
| 11 |
-
EXAMPLES_DIR = Path("examples")
|
| 12 |
-
EXAMPLES_DIR.mkdir(exist_ok=True)
|
| 13 |
-
|
| 14 |
-
def prepare_examples():
|
| 15 |
-
"""Download and prepare example images for display."""
|
| 16 |
-
examples = []
|
| 17 |
-
for i, (url, model) in enumerate(EXAMPLE_ITEMS):
|
| 18 |
-
img_path = EXAMPLES_DIR / f"example_{i}.jpg"
|
| 19 |
-
if not img_path.exists():
|
| 20 |
-
try:
|
| 21 |
-
img = download_image(url)
|
| 22 |
-
img.save(img_path, "JPEG", quality=95)
|
| 23 |
-
except Exception as e:
|
| 24 |
-
print(f"Warning: Could not download example {i}: {e}")
|
| 25 |
-
continue
|
| 26 |
-
examples.append([str(img_path), model])
|
| 27 |
-
return examples
|
| 28 |
-
|
| 29 |
EXAMPLES = prepare_examples()
|
| 30 |
|
| 31 |
-
CSS = """
|
| 32 |
-
.header {
|
| 33 |
-
text-align: center;
|
| 34 |
-
padding: 2rem 1rem;
|
| 35 |
-
background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
|
| 36 |
-
color: white;
|
| 37 |
-
border-radius: 8px;
|
| 38 |
-
margin-bottom: 2rem;
|
| 39 |
-
}
|
| 40 |
-
.header h1 { margin: 0; font-size: 2.5em; }
|
| 41 |
-
.header p { margin: 0.5rem 0; opacity: 0.9; }
|
| 42 |
-
.header a { color: white; text-decoration: underline; }
|
| 43 |
-
|
| 44 |
-
/* Hide built-in Gradio footer */
|
| 45 |
-
footer {
|
| 46 |
-
display: none !important;
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
/* Custom footer styling */
|
| 50 |
-
.custom-footer {
|
| 51 |
-
text-align: center;
|
| 52 |
-
padding: 1rem;
|
| 53 |
-
color: #888;
|
| 54 |
-
margin-top: 2rem;
|
| 55 |
-
}
|
| 56 |
-
"""
|
| 57 |
-
|
| 58 |
with gr.Blocks(
|
| 59 |
title="Visual Content Moderation",
|
| 60 |
-
css=
|
| 61 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.teal),
|
| 62 |
analytics_enabled=False,
|
| 63 |
) as demo:
|
|
@@ -115,7 +68,7 @@ with gr.Blocks(
|
|
| 115 |
inputs=[image_input, model_choice],
|
| 116 |
outputs=output,
|
| 117 |
fn=lambda img, model: analyze(img, None, model, TOKEN),
|
| 118 |
-
cache_examples=
|
| 119 |
run_on_click=True,
|
| 120 |
)
|
| 121 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
from utils import analyze, prepare_examples, CUSTOM_CSS
|
|
|
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
EXAMPLES = prepare_examples()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
with gr.Blocks(
|
| 12 |
title="Visual Content Moderation",
|
| 13 |
+
css=CUSTOM_CSS,
|
| 14 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.teal),
|
| 15 |
analytics_enabled=False,
|
| 16 |
) as demo:
|
|
|
|
| 68 |
inputs=[image_input, model_choice],
|
| 69 |
outputs=output,
|
| 70 |
fn=lambda img, model: analyze(img, None, model, TOKEN),
|
| 71 |
+
cache_examples=True,
|
| 72 |
run_on_click=True,
|
| 73 |
)
|
| 74 |
|