Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -300,6 +300,45 @@ def build_ui():
|
|
| 300 |
# ---------------- NLP ----------------
|
| 301 |
gr.Markdown("### NLP Analysis", elem_classes="heading-orange")
|
| 302 |
nlp_btn = gr.Button("Analyze Captions", elem_classes="teal-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
nlp_out = gr.HTML()
|
| 304 |
|
| 305 |
def do_nlp(captions):
|
|
@@ -311,18 +350,20 @@ def build_ui():
|
|
| 311 |
blocks = []
|
| 312 |
for label, cap in zip(labels, captions):
|
| 313 |
s, e, t = nlp_bundle(cap)
|
| 314 |
-
block = f""
|
| 315 |
<div style='flex:1;padding:10px;min-width:240px;'>
|
| 316 |
<h3><u>{label}</u></h3>
|
| 317 |
<b>Sentiment</b><br>{s}<br><br>
|
| 318 |
<b>Entities</b><br>{e}<br><br>
|
| 319 |
<b>Topics</b><br>{t}
|
| 320 |
</div>
|
| 321 |
-
""
|
| 322 |
blocks.append(block)
|
| 323 |
yield f"<div style='display:flex; gap:20px;'>{''.join(blocks)}</div>"
|
| 324 |
|
| 325 |
-
nlp_btn.click(do_nlp, inputs=[captions_state], outputs=[nlp_out])
|
|
|
|
|
|
|
| 326 |
|
| 327 |
# ---------------- VQA ----------------
|
| 328 |
gr.Markdown("### Visual Question Answering (VQA)", elem_classes="heading-orange")
|
|
|
|
| 300 |
# ---------------- NLP ----------------
|
| 301 |
gr.Markdown("### NLP Analysis", elem_classes="heading-orange")
|
| 302 |
nlp_btn = gr.Button("Analyze Captions", elem_classes="teal-btn")
|
| 303 |
+
|
| 304 |
+
with gr.Row(elem_classes="metrics-row"): # reuse metrics-row for flex layout
|
| 305 |
+
nlp_A = gr.Markdown()
|
| 306 |
+
nlp_B = gr.Markdown()
|
| 307 |
+
nlp_C = gr.Markdown()
|
| 308 |
+
|
| 309 |
+
def do_nlp_all(captions):
|
| 310 |
+
# 3 spinners like metrics
|
| 311 |
+
yield (
|
| 312 |
+
"<div class='loading-line'></div>",
|
| 313 |
+
"<div class='loading-line'></div>",
|
| 314 |
+
"<div class='loading-line'></div>"
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
if len(captions) < 3:
|
| 318 |
+
msg = "<b>All 3 captions required.</b>"
|
| 319 |
+
yield (msg, msg, msg)
|
| 320 |
+
return
|
| 321 |
+
|
| 322 |
+
labels = ["BLIP-large", "ViT-GPT2", "BLIP2"]
|
| 323 |
+
results = []
|
| 324 |
+
for label, cap in zip(labels, captions):
|
| 325 |
+
s, e, t = nlp_bundle(cap)
|
| 326 |
+
block = f"""
|
| 327 |
+
<h3><u>{label}</u></h3>
|
| 328 |
+
<b>Sentiment</b><br>{s}<br><br>
|
| 329 |
+
<b>Entities</b><br>{e}<br><br>
|
| 330 |
+
<b>Topics</b><br>{t}
|
| 331 |
+
"""
|
| 332 |
+
results.append(block)
|
| 333 |
+
|
| 334 |
+
yield (results[0], results[1], results[2])
|
| 335 |
+
|
| 336 |
+
nlp_btn.click(do_nlp_all, inputs=[captions_state], outputs=[nlp_A, nlp_B, nlp_C])
|
| 337 |
+
|
| 338 |
+
"""
|
| 339 |
+
# ---------------- NLP ---------------- COMMented out NLP
|
| 340 |
+
gr.Markdown("### NLP Analysis", elem_classes="heading-orange")
|
| 341 |
+
nlp_btn = gr.Button("Analyze Captions", elem_classes="teal-btn")
|
| 342 |
nlp_out = gr.HTML()
|
| 343 |
|
| 344 |
def do_nlp(captions):
|
|
|
|
| 350 |
blocks = []
|
| 351 |
for label, cap in zip(labels, captions):
|
| 352 |
s, e, t = nlp_bundle(cap)
|
| 353 |
+
block = f""
|
| 354 |
<div style='flex:1;padding:10px;min-width:240px;'>
|
| 355 |
<h3><u>{label}</u></h3>
|
| 356 |
<b>Sentiment</b><br>{s}<br><br>
|
| 357 |
<b>Entities</b><br>{e}<br><br>
|
| 358 |
<b>Topics</b><br>{t}
|
| 359 |
</div>
|
| 360 |
+
""
|
| 361 |
blocks.append(block)
|
| 362 |
yield f"<div style='display:flex; gap:20px;'>{''.join(blocks)}</div>"
|
| 363 |
|
| 364 |
+
nlp_btn.click(do_nlp, inputs=[captions_state], outputs=[nlp_out])"""
|
| 365 |
+
|
| 366 |
+
|
| 367 |
|
| 368 |
# ---------------- VQA ----------------
|
| 369 |
gr.Markdown("### Visual Question Answering (VQA)", elem_classes="heading-orange")
|