Spaces:
Running
on
Zero
Running
on
Zero
Diane Kim
commited on
Commit
·
be68989
1
Parent(s):
823e4d7
Initial round of UI updates
Browse files
app.py
CHANGED
|
@@ -88,7 +88,7 @@ class ModelManager:
|
|
| 88 |
# Global model manager instance
|
| 89 |
model_manager = ModelManager()
|
| 90 |
|
| 91 |
-
|
| 92 |
@spaces.GPU
|
| 93 |
def prompt_lm(audios: list[str], messages: list[dict[str, str]]) -> str:
|
| 94 |
"""Generate response using the model"""
|
|
@@ -124,12 +124,12 @@ def prompt_lm(audios: list[str], messages: list[dict[str, str]]) -> str:
|
|
| 124 |
def _multimodal_textbox_factory():
|
| 125 |
return gr.MultimodalTextbox(
|
| 126 |
value=None,
|
| 127 |
-
interactive=True,
|
| 128 |
-
|
| 129 |
-
placeholder="Enter message
|
| 130 |
show_label=False,
|
| 131 |
-
|
| 132 |
-
|
| 133 |
)
|
| 134 |
|
| 135 |
|
|
@@ -186,12 +186,12 @@ def _chat_tab(examples):
|
|
| 186 |
)
|
| 187 |
|
| 188 |
chatbot = gr.Chatbot(
|
| 189 |
-
label="
|
| 190 |
elem_id="chatbot",
|
| 191 |
bubble_full_width=False,
|
| 192 |
type="messages",
|
| 193 |
render_markdown=False,
|
| 194 |
-
resizeable=True
|
| 195 |
)
|
| 196 |
|
| 197 |
chat_input = _multimodal_textbox_factory()
|
|
@@ -428,15 +428,129 @@ def main(
|
|
| 428 |
],
|
| 429 |
}
|
| 430 |
|
| 431 |
-
with gr.Blocks(title="NatureLM-audio", theme=gr.themes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
with gr.Tabs():
|
| 433 |
-
with gr.Tab("
|
| 434 |
-
|
| 435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
_batch_tab()
|
| 437 |
with gr.Tab("Long Recording"):
|
| 438 |
-
_long_recording_tab()
|
| 439 |
-
|
| 440 |
return app
|
| 441 |
|
| 442 |
|
|
|
|
| 88 |
# Global model manager instance
|
| 89 |
model_manager = ModelManager()
|
| 90 |
|
| 91 |
+
|
| 92 |
@spaces.GPU
|
| 93 |
def prompt_lm(audios: list[str], messages: list[dict[str, str]]) -> str:
|
| 94 |
"""Generate response using the model"""
|
|
|
|
| 124 |
def _multimodal_textbox_factory():
|
| 125 |
return gr.MultimodalTextbox(
|
| 126 |
value=None,
|
| 127 |
+
interactive=True,
|
| 128 |
+
sources="microphone",
|
| 129 |
+
placeholder="Enter message...",
|
| 130 |
show_label=False,
|
| 131 |
+
autofocus=True,
|
| 132 |
+
submit_btn="Send"
|
| 133 |
)
|
| 134 |
|
| 135 |
|
|
|
|
| 186 |
)
|
| 187 |
|
| 188 |
chatbot = gr.Chatbot(
|
| 189 |
+
label="Chat",
|
| 190 |
elem_id="chatbot",
|
| 191 |
bubble_full_width=False,
|
| 192 |
type="messages",
|
| 193 |
render_markdown=False,
|
| 194 |
+
resizeable=True
|
| 195 |
)
|
| 196 |
|
| 197 |
chat_input = _multimodal_textbox_factory()
|
|
|
|
| 428 |
],
|
| 429 |
}
|
| 430 |
|
| 431 |
+
with gr.Blocks(title="NatureLM-audio", theme=gr.themes.Base(primary_hue="blue", font=[gr.themes.GoogleFont("Noto Sans")])) as app:
|
| 432 |
+
header = gr.HTML("""
|
| 433 |
+
<div style="display: flex; align-items: center; gap: 12px;"><h2 style="margin: 0;">NatureLM-audio<span style="font-size: 0.55em; color: #28a745; background: #e6f4ea; padding: 2px 6px; border-radius: 4px; margin-left: 8px; display: inline-block; vertical-align: top;">BETA</span></h2></div>
|
| 434 |
+
|
| 435 |
+
""")
|
| 436 |
+
|
| 437 |
with gr.Tabs():
|
| 438 |
+
with gr.Tab("Analyze Audio"):
|
| 439 |
+
uploaded_audio = gr.State()
|
| 440 |
+
with gr.Column(visible=True) as onboarding_message:
|
| 441 |
+
gr.HTML("""
|
| 442 |
+
<div style="
|
| 443 |
+
background: transparent;
|
| 444 |
+
border: 1px solid #e5e7eb;
|
| 445 |
+
border-radius: 8px;
|
| 446 |
+
padding: 16px 20px;
|
| 447 |
+
display: flex;
|
| 448 |
+
align-items: center;
|
| 449 |
+
justify-content: space-between;
|
| 450 |
+
margin-bottom: 16px;
|
| 451 |
+
margin-left: 0;
|
| 452 |
+
margin-right: 0;
|
| 453 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
| 454 |
+
">
|
| 455 |
+
<div style="display: flex; padding: 0px; align-items: center; flex: 1;">
|
| 456 |
+
<div style="font-size: 20px; margin-right: 12px;">👋</div>
|
| 457 |
+
<div style="flex: 1;">
|
| 458 |
+
<div style="font-size: 16px; font-weight: 600; color: #374151; margin-bottom: 4px;">Welcome to NatureLM-audio!</div>
|
| 459 |
+
<div style="font-size: 14px; color: #6b7280; line-height: 1.4;">Upload your first audio file below or try a sample from our library.</div>
|
| 460 |
+
</div>
|
| 461 |
+
</div>
|
| 462 |
+
<a href="https://www.earthspecies.org/blog" target="_blank" style="
|
| 463 |
+
padding: 6px 12px;
|
| 464 |
+
border-radius: 6px;
|
| 465 |
+
font-size: 13px;
|
| 466 |
+
font-weight: 500;
|
| 467 |
+
cursor: pointer;
|
| 468 |
+
border: none;
|
| 469 |
+
background: #3b82f6;
|
| 470 |
+
color: white;
|
| 471 |
+
text-decoration: none;
|
| 472 |
+
display: inline-block;
|
| 473 |
+
transition: background 0.2s ease;
|
| 474 |
+
"
|
| 475 |
+
onmouseover="this.style.background='#2563eb';"
|
| 476 |
+
onmouseout="this.style.background='#3b82f6';"
|
| 477 |
+
>View Tutorial</a>
|
| 478 |
+
</div>
|
| 479 |
+
""", padding=False)
|
| 480 |
+
with gr.Column(visible=True) as upload_section:
|
| 481 |
+
audio_input = gr.Audio(
|
| 482 |
+
type="filepath",
|
| 483 |
+
container=True,
|
| 484 |
+
interactive=True,
|
| 485 |
+
sources=['upload']
|
| 486 |
+
)
|
| 487 |
+
with gr.Group(visible=False) as chat:
|
| 488 |
+
chatbot = gr.Chatbot(
|
| 489 |
+
elem_id="chatbot",
|
| 490 |
+
type="messages",
|
| 491 |
+
render_markdown=False,
|
| 492 |
+
feedback_options=["like", "dislike", "wrong species", "incorrect response", "other"],
|
| 493 |
+
resizeable=True
|
| 494 |
+
)
|
| 495 |
+
chat_input = _multimodal_textbox_factory()
|
| 496 |
+
send_all = gr.Button("Send all")
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
def start_chat_interface(audio_path):
|
| 500 |
+
return (
|
| 501 |
+
gr.update(visible=False), # hide onboarding message
|
| 502 |
+
gr.update(visible=True), # show upload section
|
| 503 |
+
gr.update(visible=True), # show chat box
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
+
audio_input.change(
|
| 507 |
+
fn=start_chat_interface,
|
| 508 |
+
inputs=[audio_input],
|
| 509 |
+
outputs=[onboarding_message, upload_section, chat]
|
| 510 |
+
)
|
| 511 |
+
|
| 512 |
+
chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
| 513 |
+
send_all.click(bot_response, [chatbot], [chatbot])
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
with gr.Tab("Sample Library"):
|
| 517 |
+
gr.Markdown("## Sample Library\n\nExplore example audio files below.")
|
| 518 |
+
gr.Examples(
|
| 519 |
+
list(examples.values()),
|
| 520 |
+
chatbot,
|
| 521 |
+
chatbot,
|
| 522 |
+
example_labels=list(examples.keys()),
|
| 523 |
+
examples_per_page=20,
|
| 524 |
+
)
|
| 525 |
+
with gr.Tab("💡 Help"):
|
| 526 |
+
gr.Markdown("## User Guide") # to fill out
|
| 527 |
+
gr.Markdown("## Share Feedback") # to fill out
|
| 528 |
+
gr.Markdown("## FAQs") # to fill out
|
| 529 |
+
|
| 530 |
+
app.css = """
|
| 531 |
+
.welcome-banner {
|
| 532 |
+
background: transparent !important;
|
| 533 |
+
border: 1px solid #e5e7eb !important;
|
| 534 |
+
border-radius: 8px !important;
|
| 535 |
+
padding: 16px 20px !important;
|
| 536 |
+
margin-bottom: 16px !important;
|
| 537 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
.welcome-banner > div {
|
| 541 |
+
background: transparent !important;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
.welcome-banner button {
|
| 545 |
+
margin: 0 4px !important;
|
| 546 |
+
}
|
| 547 |
+
"""
|
| 548 |
+
# Disabling Batch and Long Recording tabs for now
|
| 549 |
+
""" with gr.Tab("Batch"):
|
| 550 |
_batch_tab()
|
| 551 |
with gr.Tab("Long Recording"):
|
| 552 |
+
_long_recording_tab() """
|
| 553 |
+
|
| 554 |
return app
|
| 555 |
|
| 556 |
|