stephenebert commited on
Commit
f451444
·
verified ·
1 Parent(s): 7d79380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
3
  # FastAPI REST API + a Gradio UI mounted at /ui
4
  # Endpoints:
5
  # GET /healthz
6
- # POST /upload (multipart image -> {filename, caption, tags})
7
  # UI:
8
  # /ui (upload image, choose top_k, see caption + tags)
9
 
@@ -18,7 +18,7 @@ import io
18
  import gradio as gr
19
  from tagger import tag_pil_image # returns (caption: str, tags: List[str])
20
 
21
- app = FastAPI(title="Image Tagger API", version="0.4.0")
22
 
23
 
24
  # ---------- Pydantic model for OpenAPI ----------
@@ -73,9 +73,9 @@ async def upload(
73
  # ---------- Gradio UI (mounted at /ui) ----------
74
  def _ui_tag(image: Image.Image, top_k: int):
75
  if image is None:
76
- return "", []
77
  caption, tags = tag_pil_image(image.convert("RGB"), "upload", top_k=top_k)
78
- return caption, tags
79
 
80
 
81
  with gr.Blocks(title="Image Tagger", analytics_enabled=False) as gr_app:
@@ -86,17 +86,14 @@ with gr.Blocks(title="Image Tagger", analytics_enabled=False) as gr_app:
86
  )
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
- inp = gr.Image(
90
- type="pil", label="Upload image", sources=["upload"], height=360
91
- )
92
  k = gr.Slider(1, 20, value=5, step=1, label="Top-k tags")
93
  btn = gr.Button("Tag it")
94
  with gr.Column(scale=1):
95
  cap = gr.Textbox(label="Caption", lines=2)
96
- tags = gr.Tags(label="Tags")
97
 
98
- btn.click(_ui_tag, inputs=[inp, k], outputs=[cap, tags])
99
 
100
  # Mount Gradio on the same FastAPI app
101
  app = gr.mount_gradio_app(app, gr_app, path="/ui")
102
-
 
3
  # FastAPI REST API + a Gradio UI mounted at /ui
4
  # Endpoints:
5
  # GET /healthz
6
+ # POST /upload -> {filename, caption, tags}
7
  # UI:
8
  # /ui (upload image, choose top_k, see caption + tags)
9
 
 
18
  import gradio as gr
19
  from tagger import tag_pil_image # returns (caption: str, tags: List[str])
20
 
21
+ app = FastAPI(title="Image Tagger API", version="0.4.1")
22
 
23
 
24
  # ---------- Pydantic model for OpenAPI ----------
 
73
  # ---------- Gradio UI (mounted at /ui) ----------
74
  def _ui_tag(image: Image.Image, top_k: int):
75
  if image is None:
76
+ return "", ""
77
  caption, tags = tag_pil_image(image.convert("RGB"), "upload", top_k=top_k)
78
+ return caption, ", ".join(tags)
79
 
80
 
81
  with gr.Blocks(title="Image Tagger", analytics_enabled=False) as gr_app:
 
86
  )
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
+ inp = gr.Image(type="pil", label="Upload image", sources=["upload"], height=360)
 
 
90
  k = gr.Slider(1, 20, value=5, step=1, label="Top-k tags")
91
  btn = gr.Button("Tag it")
92
  with gr.Column(scale=1):
93
  cap = gr.Textbox(label="Caption", lines=2)
94
+ tags_box = gr.Textbox(label="Tags (comma-separated)", lines=2)
95
 
96
+ btn.click(_ui_tag, inputs=[inp, k], outputs=[cap, tags_box])
97
 
98
  # Mount Gradio on the same FastAPI app
99
  app = gr.mount_gradio_app(app, gr_app, path="/ui")