Nightfury16 commited on
Commit
d51a527
·
1 Parent(s): 94abbf2

updated README.md, requirements.txt, Added ui/gradio_ui.py

Browse files
Files changed (4) hide show
  1. README.md +19 -7
  2. app/main.py +6 -6
  3. app/ui/gradio_ui.py +70 -0
  4. requirements.txt +1 -1
README.md CHANGED
@@ -10,9 +10,21 @@ pinned: false
10
 
11
  # 🏗️ Auto Pick MobileCLIP API
12
 
13
- This Hugging Face Space hosts a production-ready API for ranking real estate images based on their suitability for virtual staging. It uses Apple's powerful and efficient **MobileCLIP2** model to analyze images against user-defined text prompts, providing a "stageability score."
14
 
15
- The application is built with **FastAPI** for high performance and is containerized with **Docker** to ensure a consistent and reliable environment.
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  ## 🤔 How It Works
18
 
@@ -28,16 +40,16 @@ The API exposes a single endpoint for ranking images.
28
 
29
  ### Endpoint: `/api/v1/rank_image`
30
 
31
- * **Method:** `POST`
32
- * **Content-Type:** `multipart/form-data`
33
 
34
  #### Parameters
35
 
36
  1. `file`: The image file you want to analyze (`.jpg`, `.png`, etc.).
37
  2. `prompts` (Optional): A JSON string containing custom prompts. If not provided, default prompts are used.
38
- * `prompt_good` (string): Describes an ideal room for staging.
39
- * `prompt_bad` (string): Describes a room that is difficult to stage.
40
- * `prompt_aesthetic` (string, optional): Describes a desirable feature to add bonus points for.
41
 
42
  ---
43
 
 
10
 
11
  # 🏗️ Auto Pick MobileCLIP API
12
 
13
+ This Hugging Face Space hosts a powerful tool for automatically ranking images. It uses Apple's efficient **MobileCLIP2** model to score images against your criteria, making it perfect for auto-picking the best photos for real estate, e-commerce, or any other use case.
14
 
15
+ The application provides two ways to interact:
16
+
17
+ 1. **A user-friendly Web UI** (built with Gradio) for interactive testing and demonstration.
18
+ 2. **A high-performance REST API** (built with FastAPI) for programmatic integration.
19
+
20
+ ## ✨ Web UI (Gradio)
21
+
22
+ When you visit this Space, you are greeted with an interactive interface where you can:
23
+
24
+ - **Upload an image** directly from your computer.
25
+ - **Customize the prompts** to define what makes a "good" or "bad" image for your specific needs.
26
+ - **Add an "aesthetic" prompt** to give bonus points for specific features (e.g., "contains a modern fireplace").
27
+ - **See the score** calculated instantly.
28
 
29
  ## 🤔 How It Works
30
 
 
40
 
41
  ### Endpoint: `/api/v1/rank_image`
42
 
43
+ - **Method:** `POST`
44
+ - **Content-Type:** `multipart/form-data`
45
 
46
  #### Parameters
47
 
48
  1. `file`: The image file you want to analyze (`.jpg`, `.png`, etc.).
49
  2. `prompts` (Optional): A JSON string containing custom prompts. If not provided, default prompts are used.
50
+ - `prompt_good` (string): Describes an ideal room for staging.
51
+ - `prompt_bad` (string): Describes a room that is difficult to stage.
52
+ - `prompt_aesthetic` (string, optional): Describes a desirable feature to add bonus points for.
53
 
54
  ---
55
 
app/main.py CHANGED
@@ -1,14 +1,14 @@
1
  from fastapi import FastAPI
2
  from app.api.endpoints import staging
 
3
 
4
  app = FastAPI(
5
- title="Virtual Staging Ranker API",
6
- description="An API to rank images based on their suitability for virtual staging using MobileCLIP2.",
7
  version="1.0.0"
8
  )
9
 
10
- app.include_router(staging.router, prefix="/api/v1", tags=["Staging"])
11
 
12
- @app.get("/")
13
- def read_root():
14
- return {"message": "Welcome to the Staging Ranker API. Visit /docs for more info."}
 
1
  from fastapi import FastAPI
2
  from app.api.endpoints import staging
3
+ from app.ui.gradio_ui import gradio_app
4
 
5
  app = FastAPI(
6
+ title="Auto Pick MobileCLIP API",
7
+ description="An API to rank images using MobileCLIP2. Ideal for auto-picking the best photos for real estate, e-commerce, and more.", # <-- CHANGED
8
  version="1.0.0"
9
  )
10
 
 
11
 
12
+ app.include_router(staging.router, prefix="/api/v1", tags=["Image Ranking"])
13
+
14
+ app.mount("/", gradio_app)
app/ui/gradio_ui.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from app.models.clip_model import staging_ranker
4
+ from app.schemas.staging import StagingRequest
5
+
6
+ def rank_image_ui(image, prompt_good, prompt_bad, prompt_aesthetic):
7
+ """
8
+ Bridge function between the Gradio UI and our model engine.
9
+ """
10
+ if image is None:
11
+ raise gr.Error("Please upload an image to rank.")
12
+
13
+ pil_image = Image.fromarray(image)
14
+
15
+ aesthetic = prompt_aesthetic if prompt_aesthetic.strip() else None
16
+ prompts = StagingRequest(
17
+ prompt_good=prompt_good,
18
+ prompt_bad=prompt_bad,
19
+ prompt_aesthetic=aesthetic
20
+ )
21
+
22
+ score = staging_ranker.compute_score(pil_image, prompts)
23
+
24
+ return round(score, 4)
25
+
26
+
27
+ default_prompts = StagingRequest()
28
+
29
+ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px !important;}") as gradio_app:
30
+ gr.Markdown("# 🤖🖼️ Auto Pick MobileCLIP")
31
+ gr.Markdown("Upload an image and provide text prompts to score its quality and suitability. The higher the score, the better the match.")
32
+
33
+ with gr.Row():
34
+ with gr.Column(scale=1):
35
+ image_input = gr.Image(type="numpy", label="Upload Image")
36
+
37
+ gr.Markdown("### Customize Scoring Prompts")
38
+ prompt_good_input = gr.Textbox(
39
+ label="✅ Good Prompt",
40
+ value=default_prompts.prompt_good,
41
+ lines=3
42
+ )
43
+ prompt_bad_input = gr.Textbox(
44
+ label="❌ Bad Prompt",
45
+ value=default_prompts.prompt_bad,
46
+ lines=3
47
+ )
48
+ prompt_aesthetic_input = gr.Textbox(
49
+ label="✨ Aesthetic 'Plus' Prompt (Optional)",
50
+ placeholder="e.g., 'features a modern fireplace' or 'hardwood floors'",
51
+ lines=2
52
+ )
53
+
54
+ submit_button = gr.Button("Rank Image", variant="primary")
55
+
56
+ with gr.Column(scale=1):
57
+ output_score = gr.Number(label="🏆 Stageability Score", interactive=False)
58
+
59
+ submit_button.click(
60
+ fn=rank_image_ui,
61
+ inputs=[
62
+ image_input,
63
+ prompt_good_input,
64
+ prompt_bad_input,
65
+ prompt_aesthetic_input
66
+ ],
67
+ outputs=output_score
68
+ )
69
+
70
+
requirements.txt CHANGED
@@ -5,6 +5,6 @@ pydantic-settings
5
  python-multipart
6
  torch
7
  Pillow
8
-
9
  git+https://github.com/mlfoundations/open_clip.git
10
  git+https://github.com/apple/ml-mobileclip
 
5
  python-multipart
6
  torch
7
  Pillow
8
+ gradio
9
  git+https://github.com/mlfoundations/open_clip.git
10
  git+https://github.com/apple/ml-mobileclip