Spaces:
No application file
No application file
mathysgrapotte commited on
Commit ·
d5f2853
1
Parent(s): d5fe8a1
in gradio app, we now output discovered edam ontologies and their links to an ontology browser
Browse files
main.py
CHANGED
|
@@ -4,8 +4,85 @@ from tools.bio_tools_tools import get_biotools_response, get_biotools_ontology
|
|
| 4 |
from agents.query_ontology_db import agent
|
| 5 |
import yaml
|
| 6 |
import time
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def run_multi_agent(module_name, progress=gr.Progress()):
|
| 10 |
"""Enhanced function with progress tracking"""
|
| 11 |
|
|
@@ -109,7 +186,10 @@ def run_multi_agent(module_name, progress=gr.Progress()):
|
|
| 109 |
progress(1.0, desc="✅ Llama has finished! Meta.yml updated successfully!")
|
| 110 |
time.sleep(0.5)
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
def run_interface():
|
| 115 |
""" Function to run the agent with a Gradio interface.
|
|
@@ -380,6 +460,139 @@ def run_interface():
|
|
| 380 |
border: 1px solid rgba(36, 176, 100, 0.3) !important;
|
| 381 |
color: #e9ecef !important;
|
| 382 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
"""
|
| 384 |
|
| 385 |
# create the Gradio interface
|
|
@@ -428,11 +641,9 @@ def run_interface():
|
|
| 428 |
</div>
|
| 429 |
""")
|
| 430 |
|
| 431 |
-
# create the output
|
| 432 |
-
|
| 433 |
-
label="
|
| 434 |
-
lines=15,
|
| 435 |
-
interactive=False,
|
| 436 |
elem_classes="result-container"
|
| 437 |
)
|
| 438 |
|
|
@@ -461,7 +672,7 @@ def run_interface():
|
|
| 461 |
).then(
|
| 462 |
fn=run_multi_agent,
|
| 463 |
inputs=module_input,
|
| 464 |
-
outputs=[
|
| 465 |
show_progress="full"
|
| 466 |
).then(
|
| 467 |
fn=hide_llama_status,
|
|
|
|
| 4 |
from agents.query_ontology_db import agent
|
| 5 |
import yaml
|
| 6 |
import time
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
+
def extract_format_terms_from_result(result):
|
| 10 |
+
"""Extract EDAM format terms from agent result string"""
|
| 11 |
+
if isinstance(result, str):
|
| 12 |
+
# Look for format_XXXX patterns in the result using regex
|
| 13 |
+
format_matches = re.findall(r'format_\d+', result)
|
| 14 |
+
return format_matches
|
| 15 |
+
elif isinstance(result, list):
|
| 16 |
+
# If it's already a list, filter for format terms
|
| 17 |
+
return [item for item in result if isinstance(item, str) and item.startswith('format_')]
|
| 18 |
+
return []
|
| 19 |
+
|
| 20 |
+
def format_ontology_results_html(results, meta_yml):
|
| 21 |
+
"""Format the ontology results into a nice HTML display with clickable links"""
|
| 22 |
+
|
| 23 |
+
if not results.get("input"):
|
| 24 |
+
return "<div class='no-results'>No ontology results found.</div>"
|
| 25 |
+
|
| 26 |
+
html_content = """
|
| 27 |
+
<div class='ontology-results'>
|
| 28 |
+
<div class='results-header'>
|
| 29 |
+
<h2>🧬 Discovered EDAM Ontologies</h2>
|
| 30 |
+
<p>Click on any ontology term to view detailed information in the EDAM database</p>
|
| 31 |
+
</div>
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
# Group inputs by their descriptions from meta_yml
|
| 35 |
+
input_info = {}
|
| 36 |
+
for input_channel in meta_yml.get("input", []):
|
| 37 |
+
for ch_element in input_channel:
|
| 38 |
+
for key, value in ch_element.items():
|
| 39 |
+
if value.get("type") == "file":
|
| 40 |
+
input_info[key] = value.get("description", "No description available")
|
| 41 |
|
| 42 |
+
for input_name, result in results["input"].items():
|
| 43 |
+
format_terms = extract_format_terms_from_result(result)
|
| 44 |
+
description = input_info.get(input_name, "No description available")
|
| 45 |
+
|
| 46 |
+
html_content += f"""
|
| 47 |
+
<div class='input-section'>
|
| 48 |
+
<div class='input-header'>
|
| 49 |
+
<h3>📁 {input_name}</h3>
|
| 50 |
+
<p class='input-description'>{description}</p>
|
| 51 |
+
</div>
|
| 52 |
+
<div class='ontologies-container'>
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
if format_terms:
|
| 56 |
+
for term in format_terms:
|
| 57 |
+
term_id = term.replace("format_", "")
|
| 58 |
+
link_url = f"http://edamontology.org/{term}"
|
| 59 |
+
html_content += f"""
|
| 60 |
+
<div class='ontology-card'>
|
| 61 |
+
<a href='{link_url}' target='_blank' class='ontology-link'>
|
| 62 |
+
<div class='ontology-icon'>🔗</div>
|
| 63 |
+
<div class='ontology-details'>
|
| 64 |
+
<span class='ontology-id'>{term}</span>
|
| 65 |
+
<span class='ontology-label'>Click to view in EDAM database</span>
|
| 66 |
+
</div>
|
| 67 |
+
</a>
|
| 68 |
+
</div>
|
| 69 |
+
"""
|
| 70 |
+
else:
|
| 71 |
+
html_content += """
|
| 72 |
+
<div class='no-ontologies'>
|
| 73 |
+
<span>⚠️ No EDAM format ontologies found for this input</span>
|
| 74 |
+
</div>
|
| 75 |
+
"""
|
| 76 |
+
|
| 77 |
+
html_content += """
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
html_content += "</div>"
|
| 83 |
+
|
| 84 |
+
return html_content
|
| 85 |
+
|
| 86 |
def run_multi_agent(module_name, progress=gr.Progress()):
|
| 87 |
"""Enhanced function with progress tracking"""
|
| 88 |
|
|
|
|
| 186 |
progress(1.0, desc="✅ Llama has finished! Meta.yml updated successfully!")
|
| 187 |
time.sleep(0.5)
|
| 188 |
|
| 189 |
+
# Format the results into a nice HTML display
|
| 190 |
+
formatted_results = format_ontology_results_html(results, meta_yml)
|
| 191 |
+
|
| 192 |
+
return formatted_results, "tmp_meta.yml"
|
| 193 |
|
| 194 |
def run_interface():
|
| 195 |
""" Function to run the agent with a Gradio interface.
|
|
|
|
| 460 |
border: 1px solid rgba(36, 176, 100, 0.3) !important;
|
| 461 |
color: #e9ecef !important;
|
| 462 |
}
|
| 463 |
+
|
| 464 |
+
/* Ontology Results Styling */
|
| 465 |
+
.ontology-results {
|
| 466 |
+
background: rgba(33, 37, 41, 0.95) !important;
|
| 467 |
+
border-radius: 15px !important;
|
| 468 |
+
padding: 1.5rem !important;
|
| 469 |
+
margin: 1rem 0 !important;
|
| 470 |
+
border: 2px solid rgba(36, 176, 100, 0.4) !important;
|
| 471 |
+
backdrop-filter: blur(10px) !important;
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
.results-header {
|
| 475 |
+
text-align: center;
|
| 476 |
+
margin-bottom: 2rem;
|
| 477 |
+
padding-bottom: 1rem;
|
| 478 |
+
border-bottom: 2px solid rgba(36, 176, 100, 0.3);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
.results-header h2 {
|
| 482 |
+
color: #24B064 !important;
|
| 483 |
+
font-size: 1.8rem !important;
|
| 484 |
+
font-weight: 700 !important;
|
| 485 |
+
margin: 0 0 0.5rem 0 !important;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
.results-header p {
|
| 489 |
+
color: #adb5bd !important;
|
| 490 |
+
font-size: 1rem !important;
|
| 491 |
+
margin: 0 !important;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
.input-section {
|
| 495 |
+
background: rgba(52, 58, 64, 0.8) !important;
|
| 496 |
+
border-radius: 12px !important;
|
| 497 |
+
padding: 1.5rem !important;
|
| 498 |
+
margin: 1rem 0 !important;
|
| 499 |
+
border: 1px solid rgba(36, 176, 100, 0.3) !important;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
.input-header h3 {
|
| 503 |
+
color: #24B064 !important;
|
| 504 |
+
font-size: 1.3rem !important;
|
| 505 |
+
font-weight: 600 !important;
|
| 506 |
+
margin: 0 0 0.5rem 0 !important;
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
.input-description {
|
| 510 |
+
color: #e9ecef !important;
|
| 511 |
+
font-size: 0.95rem !important;
|
| 512 |
+
margin: 0 0 1rem 0 !important;
|
| 513 |
+
font-style: italic;
|
| 514 |
+
line-height: 1.4;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
.ontologies-container {
|
| 518 |
+
display: flex;
|
| 519 |
+
flex-direction: column;
|
| 520 |
+
gap: 0.75rem;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
.ontology-card {
|
| 524 |
+
background: rgba(33, 37, 41, 0.9) !important;
|
| 525 |
+
border-radius: 10px !important;
|
| 526 |
+
border: 1px solid rgba(36, 176, 100, 0.4) !important;
|
| 527 |
+
overflow: hidden;
|
| 528 |
+
transition: all 0.3s ease !important;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
.ontology-card:hover {
|
| 532 |
+
border-color: #24B064 !important;
|
| 533 |
+
box-shadow: 0 4px 15px rgba(36, 176, 100, 0.3) !important;
|
| 534 |
+
transform: translateY(-2px);
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
.ontology-link {
|
| 538 |
+
display: flex !important;
|
| 539 |
+
align-items: center !important;
|
| 540 |
+
padding: 1rem !important;
|
| 541 |
+
text-decoration: none !important;
|
| 542 |
+
color: inherit !important;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
.ontology-link:hover {
|
| 546 |
+
background: rgba(36, 176, 100, 0.1) !important;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
.ontology-icon {
|
| 550 |
+
font-size: 1.5rem;
|
| 551 |
+
margin-right: 1rem;
|
| 552 |
+
color: #24B064;
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
.ontology-details {
|
| 556 |
+
display: flex;
|
| 557 |
+
flex-direction: column;
|
| 558 |
+
flex: 1;
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
.ontology-id {
|
| 562 |
+
color: #24B064 !important;
|
| 563 |
+
font-weight: 600 !important;
|
| 564 |
+
font-size: 1.1rem !important;
|
| 565 |
+
margin-bottom: 0.25rem;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
.ontology-label {
|
| 569 |
+
color: #adb5bd !important;
|
| 570 |
+
font-size: 0.9rem !important;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
.no-ontologies {
|
| 574 |
+
background: rgba(255, 193, 7, 0.1) !important;
|
| 575 |
+
border: 1px solid rgba(255, 193, 7, 0.3) !important;
|
| 576 |
+
border-radius: 8px !important;
|
| 577 |
+
padding: 1rem !important;
|
| 578 |
+
text-align: center;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
.no-ontologies span {
|
| 582 |
+
color: #ffc107 !important;
|
| 583 |
+
font-weight: 500;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
.no-results {
|
| 587 |
+
background: rgba(220, 53, 69, 0.1) !important;
|
| 588 |
+
border: 1px solid rgba(220, 53, 69, 0.3) !important;
|
| 589 |
+
border-radius: 8px !important;
|
| 590 |
+
padding: 2rem !important;
|
| 591 |
+
text-align: center;
|
| 592 |
+
color: #dc3545 !important;
|
| 593 |
+
font-size: 1.1rem;
|
| 594 |
+
font-weight: 500;
|
| 595 |
+
}
|
| 596 |
"""
|
| 597 |
|
| 598 |
# create the Gradio interface
|
|
|
|
| 641 |
</div>
|
| 642 |
""")
|
| 643 |
|
| 644 |
+
# create the output HTML component for the ontology results
|
| 645 |
+
ontology_output = gr.HTML(
|
| 646 |
+
label="🧬 Discovered EDAM Ontologies",
|
|
|
|
|
|
|
| 647 |
elem_classes="result-container"
|
| 648 |
)
|
| 649 |
|
|
|
|
| 672 |
).then(
|
| 673 |
fn=run_multi_agent,
|
| 674 |
inputs=module_input,
|
| 675 |
+
outputs=[ontology_output, download_button],
|
| 676 |
show_progress="full"
|
| 677 |
).then(
|
| 678 |
fn=hide_llama_status,
|