joaomorossini commited on
Commit
c97211f
1 Parent(s): 174f0ca

Adjust formatting

Browse files
Files changed (2) hide show
  1. .gitignore +2 -1
  2. app.py +18 -12
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .env
 
 
1
+ .env
2
+ /venv
app.py CHANGED
@@ -71,30 +71,36 @@ def captioner(image):
71
  base64_image = image_to_base64_str(image)
72
  results = get_completion(base64_image)
73
  captions = []
74
- separator = "-" * 50
75
  for endpoint, result in results.items():
 
 
 
76
  if "error" not in result:
77
- caption = f"[{endpoint}]({hf_base_url+endpoint}): \n\n {result[0]['generated_text']} \n {separator} \n\n "
78
  else:
79
- caption = f"[{endpoint}]({hf_base_url+endpoint}): \n\n Error - {result['error']} \n {separator} \n\n "
80
- captions.append(caption)
81
- return "".join(captions) # Join all captions into a single string
 
 
 
 
82
 
83
 
84
  # --- Launch the Gradio App ---
85
  demo = gr.Interface(
86
  fn=captioner,
87
  inputs=[gr.Image(label="Upload image", type="pil")],
88
- outputs=gr.Markdown(label="Captions"),
89
- title="Captioning Comparison",
90
  description="Upload an image and see how different models describe it!",
91
  allow_flagging="never",
92
  examples=[
93
- "example_1.jpg",
94
- "example_2.jpg",
95
- "example_3.jpg",
96
- "example_4.png",
97
- "example_5.png",
98
  ],
99
  )
100
 
 
71
  base64_image = image_to_base64_str(image)
72
  results = get_completion(base64_image)
73
  captions = []
 
74
  for endpoint, result in results.items():
75
+ # Use a smaller heading or remove the heading syntax for regular text size
76
+ # header = f"#### [{endpoint}]({hf_base_url+endpoint}):"
77
+ header = f"[{endpoint}]({hf_base_url+endpoint}):" # No heading, regular text
78
  if "error" not in result:
79
+ caption = result[0]["generated_text"]
80
  else:
81
+ caption = f"Error - {result['error']}"
82
+ captions.append(
83
+ f"{header}\n{caption} \n\n"
84
+ ) # Use horizontal rule for separation
85
+ return "\n".join(
86
+ captions
87
+ ).strip() # Join all captions into a single string, separated by horizontal rules
88
 
89
 
90
  # --- Launch the Gradio App ---
91
  demo = gr.Interface(
92
  fn=captioner,
93
  inputs=[gr.Image(label="Upload image", type="pil")],
94
+ outputs=gr.Markdown(label="Captions"), # Use a single Markdown output
95
+ title="Image Captioning Model Comparison",
96
  description="Upload an image and see how different models describe it!",
97
  allow_flagging="never",
98
  examples=[
99
+ "example_1.jpg",
100
+ "example_2.jpg",
101
+ "example_3.jpg",
102
+ "example_4.png",
103
+ "example_5.png",
104
  ],
105
  )
106