unography commited on
Commit
70d5b34
·
verified ·
1 Parent(s): 53fbd3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -9,6 +9,7 @@ from gradio_client.client import Job
9
 
10
  DESCRIPTION = "# Comparing image captioning models"
11
  ORIGINAL_SPACE_INFO = """\
 
12
  - [GIT-large fine-tuned on COCO](https://huggingface.co/spaces/library-samples/image-captioning-with-git)
13
  - [BLIP-large](https://huggingface.co/spaces/library-samples/image-captioning-with-blip)
14
  - [BLIP-2 OPT 6.7B](https://huggingface.co/spaces/merve/BLIP2-with-transformers)
@@ -26,6 +27,15 @@ torch.hub.download_url_to_file(
26
  )
27
 
28
 
 
 
 
 
 
 
 
 
 
29
  def generate_caption_git(image_path: str, return_job: bool = False) -> str | Job:
30
  try:
31
  client = Client("hysts/image-captioning-with-git")
@@ -116,8 +126,9 @@ def generate_caption_fuyu(image_path: str, return_job: bool = False) -> str | Jo
116
  return ""
117
 
118
 
119
- def generate_captions(image_path: str) -> tuple[str, str, str, str, str, str]:
120
  jobs = [
 
121
  generate_caption_git(image_path, return_job=True),
122
  generate_caption_blip(image_path, return_job=True),
123
  generate_caption_blip2_opt(image_path, return_job=True),
@@ -135,6 +146,7 @@ with gr.Blocks(css="style.css") as demo:
135
  input_image = gr.Image(type="filepath")
136
  run_button = gr.Button("Caption")
137
  with gr.Column():
 
138
  out_git = gr.Textbox(label="GIT-large fine-tuned on COCO")
139
  out_blip = gr.Textbox(label="BLIP-large")
140
  out_blip2_opt = gr.Textbox(label="BLIP-2 OPT 6.7B")
@@ -143,6 +155,7 @@ with gr.Blocks(css="style.css") as demo:
143
  out_fuyu = gr.Textbox(label="Fuyu-8B")
144
 
145
  outputs = [
 
146
  out_git,
147
  out_blip,
148
  out_blip2_opt,
 
9
 
10
  DESCRIPTION = "# Comparing image captioning models"
11
  ORIGINAL_SPACE_INFO = """\
12
+ - [BLIP fine-tuned for long captions](https://huggingface.co/spaces/unography/image-captioning-with-longcap)
13
  - [GIT-large fine-tuned on COCO](https://huggingface.co/spaces/library-samples/image-captioning-with-git)
14
  - [BLIP-large](https://huggingface.co/spaces/library-samples/image-captioning-with-blip)
15
  - [BLIP-2 OPT 6.7B](https://huggingface.co/spaces/merve/BLIP2-with-transformers)
 
27
  )
28
 
29
 
30
+ def generate_caption_longcap(image_path: str, return_job: bool = False) -> str | Job:
31
+ try:
32
+ client = Client("hysts/image-captioning-with-git")
33
+ fn = client.submit if return_job else client.predict
34
+ return fn(image_path, api_name="/caption")
35
+ except Exception:
36
+ gr.Warning("The GIT-large Space is currently unavailable. Please try again later.")
37
+ return ""
38
+
39
  def generate_caption_git(image_path: str, return_job: bool = False) -> str | Job:
40
  try:
41
  client = Client("hysts/image-captioning-with-git")
 
126
  return ""
127
 
128
 
129
+ def generate_captions(image_path: str) -> tuple[str, str, str, str, str, str, str]:
130
  jobs = [
131
+ generate_caption_longcap(image_path, return_job=True),
132
  generate_caption_git(image_path, return_job=True),
133
  generate_caption_blip(image_path, return_job=True),
134
  generate_caption_blip2_opt(image_path, return_job=True),
 
146
  input_image = gr.Image(type="filepath")
147
  run_button = gr.Button("Caption")
148
  with gr.Column():
149
+ out_longcap = gr.Textbox(label="BLIP fine-tuned for long captions")
150
  out_git = gr.Textbox(label="GIT-large fine-tuned on COCO")
151
  out_blip = gr.Textbox(label="BLIP-large")
152
  out_blip2_opt = gr.Textbox(label="BLIP-2 OPT 6.7B")
 
155
  out_fuyu = gr.Textbox(label="Fuyu-8B")
156
 
157
  outputs = [
158
+ out_longcap,
159
  out_git,
160
  out_blip,
161
  out_blip2_opt,