Spaces:
Runtime error
Runtime error
Commit
·
72a4dff
1
Parent(s):
d36553d
AdLike App
Browse files- app.py +39 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from adlike import ad_openai_clip_vitl_patch14_336
|
| 4 |
+
import glob
|
| 5 |
+
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
model, preprocess = ad_openai_clip_vitl_patch14_336()
|
| 8 |
+
|
| 9 |
+
demo = gr.Blocks()
|
| 10 |
+
|
| 11 |
+
def predict_ad_probab(image):
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
image = preprocess(image).to(device).unsqueeze(0)
|
| 14 |
+
probs = model(image).item()
|
| 15 |
+
return round(probs, 3)
|
| 16 |
+
|
| 17 |
+
with demo:
|
| 18 |
+
|
| 19 |
+
gr.Markdown("# **<p align='center'>AdLike: Detect Advertisement Images</p>**")
|
| 20 |
+
gr.Markdown("This space demonstrates the use of AdLike. It predicts the probability of whether an Image is an Advertisement. \
|
| 21 |
+
The higher the probability, the higher the chance of an Image being Advertisement.")
|
| 22 |
+
|
| 23 |
+
with gr.Group():
|
| 24 |
+
with gr.Row():
|
| 25 |
+
input_image = gr.Image(type='pil',label="Input Image",
|
| 26 |
+
image_mode="RGB",
|
| 27 |
+
sources="upload",
|
| 28 |
+
show_label=True)
|
| 29 |
+
|
| 30 |
+
with gr.Row():
|
| 31 |
+
output_probab = gr.Number(label="Advertisement Probability", show_label=True)
|
| 32 |
+
|
| 33 |
+
with gr.Group():
|
| 34 |
+
with gr.Row():
|
| 35 |
+
submit_button = gr.Button("Predict Probability")
|
| 36 |
+
|
| 37 |
+
submit_button.click(predict_ad_probab, inputs=[input_image], outputs=[output_probab])
|
| 38 |
+
|
| 39 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
gradio
|
| 3 |
+
pillow
|
| 4 |
+
adlike
|