Create gradio_app.py
Browse files- gradio_app.py +23 -0
gradio_app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load your model
|
| 6 |
+
agent = pipeline("image-classification", model="your-username/your-model-name")
|
| 7 |
+
|
| 8 |
+
def analyze_image(image):
|
| 9 |
+
results = agent(image)
|
| 10 |
+
# Format results for clean output
|
| 11 |
+
return {r["label"]: r["score"] for r in results}
|
| 12 |
+
|
| 13 |
+
# Create UI
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=analyze_image,
|
| 16 |
+
inputs=gr.Image(type="pil"),
|
| 17 |
+
outputs=gr.Label(num_top_classes=3),
|
| 18 |
+
examples=["example1.jpg", "example2.jpg"],
|
| 19 |
+
title="π‘οΈ AI Vision Agent: Security Compliance Assistant",
|
| 20 |
+
description="Upload an image to detect clean-desk violations, unattended devices, and more!",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|