ART_database / app.py
udiksh's picture
Rename app_pubcrawler_articles_fixed_fixed(2).py to app.py
09bd19a verified
Raw History Blame Contribute Delete
232 kB
import os import gradio as gr import pandas as pd import numpy as np import datetime import urllib.parse import urllib.request import urllib.error import json import time import re import html as html_lib from supabase import create_client, Client # ── Helper: build query from terms and operators ────────────── def build_boolean_query(term1, op1, term2, op2, term3): """ Build a boolean query from up to three terms with operators. """ terms = [] if term1 and term1.strip(): terms.append(term1.strip()) if term2 and term2.strip(): terms.append(term2.strip()) if term3 and term3.strip(): terms.append(term3.strip()) if len(terms) == 0: return "" if len(terms) == 1: return terms[0] # Build query with operators query_parts = [] for i, t in enumerate(terms): # Put quotes around phrases with spaces if ' ' in t and not (t.startswith('"') and t.endswith('"')): t = f'"{t}"' query_parts.append(t) # Insert operators between terms if len(query_parts) == 2: return f"{query_parts[0]} {op1} {query_parts[1]}" else: return f"{query_parts[0]} {op1} {query_parts[1]} {op2} {query_parts[2]}" def normalize_boolean_query(query: str) -> str: """ Replace lowercase 'and' and 'or' with uppercase operators. """ if not query: return query pattern_and = re.compile(r'(?<!\w)and(?!\w)', re.IGNORECASE) pattern_or = re.compile(r'(?<!\w)or(?!\w)', re.IGNORECASE) query = pattern_and.sub('AND', query) query = pattern_or.sub('OR', query) return query def _is_boolean_query(query: str) -> bool: """Return True if query contains AND or OR operators.""" q = normalize_boolean_query(query) return ' AND ' in q or ' OR ' in q # ── Admin authentication using session tracking ────────────────── _admin_sessions = {} # session_id -> timestamp _admin_roles = {} # session_id -> "senior" or "junior" _admin_users = {} # session_id -> current app user name def set_admin_active(session_id, role="senior"): if session_id: _admin_sessions[session_id] = time.time() _admin_roles[session_id] = role return True def is_admin_active(session_id): return session_id in _admin_sessions def get_admin_role(session_id): return _admin_roles.get(session_id) def is_senior_admin(session_id): return get_admin_role(session_id) == "senior" def is_junior_admin(session_id): return get_admin_role(session_id) == "junior" def set_current_app_user(session_id, user_name): if session_id: _admin_users[session_id] = _normalize_app_user(user_name) def get_current_app_user(session_id): return _normalize_app_user(_admin_users.get(session_id, "")) def clear_current_app_user(session_id): if session_id: _admin_users.pop(session_id, None) # ── Supabase credentials ────────────────────────────────────────── url: str = os.environ.get("SUPABASE_URL") key: str = os.environ.get("SUPABASE_KEY") AUTH_USER = os.environ.get("UPLOAD_USER") AUTH_PASS = os.environ.get("UPLOAD_PASS") if not url or not key: print("Warning: Missing Supabase credentials in Space Secrets!") supabase = None else: supabase: Client = create_client(url, key) HOMEPAGE_FILE = "homepage_content.html" HOME_CONTACT_HTML = """ <div style="font-family:'Segoe UI',system-ui,sans-serif;max-width:1100px;margin:32px auto 0;padding:0 16px 48px;"> <div style="display:flex;align-items:center;gap:16px;margin-bottom:36px;"> <div style="flex:1;height:1px;background:linear-gradient(to right,#e2e8f0,#c7d2fe);"></div> <span style="font-size:11px;font-weight:700;color:#94a3b8;letter-spacing:0.12em;text-transform:uppercase;">Our Team &amp; Contact</span> <div style="flex:1;height:1px;background:linear-gradient(to left,#e2e8f0,#c7d2fe);"></div> </div> <!-- OUR TEAM --> <div style="margin-bottom:48px;"> <div style="display:flex;align-items:center;gap:10px;margin-bottom:24px;"> <div style="width:36px;height:36px;border-radius:10px;background:#eff6ff;display:flex;align-items:center;justify-content:center;font-size:18px;"></div> <h2 style="margin:0;font-size:20px;font-weight:800;color:#0f172a;">Our Team</h2> </div> <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(235px,1fr));gap:18px;"> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:20px;box-shadow:0 2px 8px rgba(0,0,0,0.05);position:relative;overflow:hidden;"> <div style="position:absolute;top:0;left:0;right:0;height:4px;background:linear-gradient(to right,#2563eb,#7c3aed);"></div> <div style="display:flex;align-items:center;gap:12px;margin:10px 0 14px;"> <div style="width:48px;height:48px;border-radius:50%;background:#eff6ff;border:2px solid #bfdbfe;display:flex;align-items:center;justify-content:center;font-size:22px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;line-height:1.3;">Dr. Bharati Pandey</div><div style="font-size:11px;font-weight:600;color:#2563eb;margin-top:2px;">Scientist</div></div> </div> <div style="display:flex;align-items:flex-start;gap:8px;font-size:12px;color:#475569;line-height:1.5;"><span></span><span>Animal Biotechnology Division, NDRI, Karnal</span></div> </div> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:20px;box-shadow:0 2px 8px rgba(0,0,0,0.05);position:relative;overflow:hidden;"> <div style="position:absolute;top:0;left:0;right:0;height:4px;background:linear-gradient(to right,#059669,#0891b2);"></div> <div style="display:flex;align-items:center;gap:12px;margin:10px 0 14px;"> <div style="width:48px;height:48px;border-radius:50%;background:#f0fdf4;border:2px solid #bbf7d0;display:flex;align-items:center;justify-content:center;font-size:22px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;line-height:1.3;">Mr. Udiksh Malik</div><div style="font-size:11px;font-weight:600;color:#059669;margin-top:2px;">Intern</div></div> </div> <div style="display:flex;align-items:flex-start;gap:8px;font-size:12px;color:#475569;line-height:1.5;"><span></span><span>B.Sc. Biotechnology (Hons), Amity University, Noida</span></div> </div> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:20px;box-shadow:0 2px 8px rgba(0,0,0,0.05);position:relative;overflow:hidden;"> <div style="position:absolute;top:0;left:0;right:0;height:4px;background:linear-gradient(to right,#7c3aed,#db2777);"></div> <div style="display:flex;align-items:center;gap:12px;margin:10px 0 14px;"> <div style="width:48px;height:48px;border-radius:50%;background:#faf5ff;border:2px solid #ddd6fe;display:flex;align-items:center;justify-content:center;font-size:22px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;line-height:1.3;">Dr. Manoj Kumar Singh</div><div style="font-size:11px;font-weight:600;color:#7c3aed;margin-top:2px;">Principal Scientist</div></div> </div> <div style="display:flex;align-items:flex-start;gap:8px;font-size:12px;color:#475569;line-height:1.5;"><span></span><span>Animal Biotechnology Division, NDRI, Karnal</span></div> </div> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:20px;box-shadow:0 2px 8px rgba(0,0,0,0.05);position:relative;overflow:hidden;"> <div style="position:absolute;top:0;left:0;right:0;height:4px;background:linear-gradient(to right,#d97706,#dc2626);"></div> <div style="display:flex;align-items:center;gap:12px;margin:10px 0 14px;"> <div style="width:48px;height:48px;border-radius:50%;background:#fffbeb;border:2px solid #fde68a;display:flex;align-items:center;justify-content:center;font-size:22px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;line-height:1.3;">Dr. Naresh Selokar</div><div style="font-size:11px;font-weight:600;color:#d97706;margin-top:2px;">Senior Scientist</div></div> </div> <div style="display:flex;align-items:flex-start;gap:8px;font-size:12px;color:#475569;line-height:1.5;"><span></span><span>Animal Biotechnology Division, NDRI, Karnal</span></div> </div> </div> </div> <!-- CONTACT US --> <div> <div style="display:flex;align-items:center;gap:10px;margin-bottom:24px;"> <div style="width:36px;height:36px;border-radius:10px;background:#f0fdf4;display:flex;align-items:center;justify-content:center;font-size:18px;"></div> <h2 style="margin:0;font-size:20px;font-weight:800;color:#0f172a;">Contact Us</h2> </div> <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(310px,1fr));gap:18px;"> <!-- Dr. Bharati Pandey --> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:24px;box-shadow:0 2px 8px rgba(0,0,0,0.05);"> <div style="display:flex;align-items:center;gap:10px;margin-bottom:18px;"> <div style="width:40px;height:40px;border-radius:50%;background:#eff6ff;border:2px solid #bfdbfe;display:flex;align-items:center;justify-content:center;font-size:18px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;">Dr. Bharati Pandey</div><div style="font-size:11px;color:#2563eb;font-weight:600;">Scientist &middot; NDRI</div></div> </div> <div style="display:flex;flex-direction:column;gap:10px;"> <a href="mailto:bharati.pandey@icar.org.in" style="display:flex;align-items:center;gap:10px;text-decoration:none;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:10px 12px;"> <span style="font-size:16px;flex-shrink:0;"></span> <div><div style="font-size:10px;font-weight:700;color:#94a3b8;letter-spacing:0.06em;text-transform:uppercase;">Email</div><div style="font-size:12.5px;color:#2563eb;font-weight:500;">bharati.pandey@icar.org.in</div></div> </a> <a href="tel:+919560421766" style="display:flex;align-items:center;gap:10px;text-decoration:none;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:10px 12px;"> <span style="font-size:16px;flex-shrink:0;"></span> <div><div style="font-size:10px;font-weight:700;color:#94a3b8;letter-spacing:0.06em;text-transform:uppercase;">Phone</div><div style="font-size:12.5px;color:#0f172a;font-weight:500;">+91&nbsp;9560421766</div></div> </a> <div style="display:flex;align-items:center;gap:10px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:10px 12px;"> <span style="font-size:16px;flex-shrink:0;"></span> <div><div style="font-size:10px;font-weight:700;color:#94a3b8;letter-spacing:0.06em;text-transform:uppercase;">Address</div><div style="font-size:12.5px;color:#0f172a;font-weight:500;">Animal Biotechnology Division, NDRI, Karnal</div></div> </div> </div> </div> <!-- Udiksh Malik --> <div style="background:#ffffff;border:1px solid #e2e8f0;border-radius:12px;padding:24px;box-shadow:0 2px 8px rgba(0,0,0,0.05);"> <div style="display:flex;align-items:center;gap:10px;margin-bottom:18px;"> <div style="width:40px;height:40px;border-radius:50%;background:#f0fdf4;border:2px solid #bbf7d0;display:flex;align-items:center;justify-content:center;font-size:18px;flex-shrink:0;"></div> <div><div style="font-size:14px;font-weight:800;color:#0f172a;">Udiksh Malik</div><div style="font-size:11px;color:#059669;font-weight:600;">Intern &middot; Amity University</div></div> </div> <div style="display:flex;flex-direction:column;gap:10px;"> <a href="mailto:malikudiksh@gmail.com" style="display:flex;align-items:center;gap:10px;text-decoration:none;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:10px 12px;"> <span style="font-size:16px;flex-shrink:0;"></span> <div><div style="font-size:10px;font-weight:700;color:#94a3b8;letter-spacing:0.06em;text-transform:uppercase;">Email</div><div style="font-size:12.5px;color:#2563eb;font-weight:500;">malikudiksh@gmail.com</div></div> </a> <div style="display:flex;align-items:center;gap:10px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;padding:10px 12px;"> <span style="font-size:16px;flex-shrink:0;"></span> <div><div style="font-size:10px;font-weight:700;color:#94a3b8;letter-spacing:0.06em;text-transform:uppercase;">Address</div><div style="font-size:12.5px;color:#0f172a;font-weight:500;">B.Sc. Biotechnology (Hons) with Research, Amity University, Noida</div></div> </div> </div> </div> </div> </div> </div> """ # ── Paper Alert Configuration ───────────────────────────────────────────────── PAPER_ALERT_TOPIC = "bovine oocyte transcriptomics" PAPER_ALERT_DAYS = 30 PAPER_ALERT_MAX = 5 # ───────────────────────────────────────────────────────────────────────────── EXACT_MATCH_COLUMNS = ["Accession", "Organism", "Type", "Platform", "Samples", "Study Title"] ALL_UNIQUE_COLUMNS = EXACT_MATCH_COLUMNS + ["tissue", "dataset"] BLANK_TEMPLATE_DF = pd.DataFrame(columns=ALL_UNIQUE_COLUMNS) GEO_TOOLS_DATA = [ {"Name": "GEO2R", "URL": "https://www.ncbi.nlm.nih.gov/geo/geo2r/", "Type": "Web-based (Free)", "Feature": "Official NCBI tool; differential gene expression between sample groups; volcano plots, Venn diagrams."}, {"Name": "GEOexplorer", "URL": "https://geoexplorer.rosalind.kcl.ac.uk/", "Type": "Web-based (Free)", "Feature": "End-to-end gene expression analysis; EDA, DGEA, gene enrichment analysis (GEA); interactive plots."}, {"Name": "shinyGEO", "URL": "http://gdancik.github.io/shinyGEO/", "Type": "Web-based / Docker (Free)", "Feature": "Download expression and sample data from GEO; differential expression and survival analysis."}, {"Name": "iDEP", "URL": "http://bioinformatics.sdstate.edu/idep/", "Type": "Web-based (Free)", "Feature": "Integrated analysis platform; DEG analysis (DESeq2, edgeR, limma); PCA, heatmaps, pathway enrichment."}, {"Name": "TidyGEO", "URL": "https://tidygeo.uams.edu/", "Type": "Web-based (Free)", "Feature": "Downloads and reformats GEO series; tidies and standardises sample-level annotations."}, {"Name": "GeneCloudOmics", "URL": "https://abiotrans.ait.ie/", "Type": "Web-based (Free)", "Feature": "23 data analytics and bioinformatics tasks; PCA, clustering, t-SNE, DEG analysis, pathway enrichment."}, {"Name": "BART (Bioinformatics Array Research Tool)", "URL": "http://bart.salk.edu/", "Type": "Web-based (Free)", "Feature": "Automates microarray download and analysis from GEO; batch effect correction; differential expression; functional enrichment."}, {"Name": "GEOquery (R/Bioconductor)", "URL": "https://bioconductor.org/packages/GEOquery/", "Type": "Standalone - R package (Free)", "Feature": "Downloads GEO datasets directly into R; parses GEO SOFT/MINiML formats into ExpressionSet objects."}, {"Name": "GEOfetch", "URL": "https://github.com/pepkit/geofetch", "Type": "Standalone - CLI (Free)", "Feature": "Command-line tool for downloading GEO data and metadata; outputs standardised PEP format."}, {"Name": "GEOmetadb (R/Bioconductor)", "URL": "https://bioconductor.org/packages/GEOmetadb/", "Type": "Standalone - R package (Free)", "Feature": "SQLite database of all GEO metadata; enables advanced SQL queries; faster than NCBI API."}, {"Name": "NCBI Datasets (GEO)", "URL": "https://www.ncbi.nlm.nih.gov/datasets/", "Type": "Web-based + CLI (Free)", "Feature": "Official NCBI data retrieval portal; download GEO datasets, metadata, and associated sequences."}, {"Name": "Correlation Engine (formerly NextBio)", "URL": "https://www.illumina.com/products/by-type/informatics-products/basespace-correlation-engine.html", "Type": "Web-based (Freemium)", "Feature": "Cross-study meta-analysis; correlation of gene expression signatures across GEO studies; disease/drug association analysis; biomarker discovery."}, {"Name": "Phantasus", "URL": "https://genome.ifmo.ru/phantasus/", "Type": "Web-based (Free)", "Feature": "Interactive visual analysis of GEO datasets; heatmaps, PCA, k-means clustering, DESeq2/limma."}, {"Name": "ExpressionAtlas", "URL": "https://www.ebi.ac.uk/gxa/", "Type": "Web-based (Free)", "Feature": "Curated gene expression across species and conditions; differential and baseline expression data."}, {"Name": "Enrichr", "URL": "https://maayanlab.cloud/Enrichr/", "Type": "Web-based (Free)", "Feature": "Gene set enrichment analysis; 200+ gene set libraries; interactive visualisations; accepts gene lists."} ] SRA_TOOLS_DATA = [ {"Name": "SRA Toolkit (NCBI)", "URL": "https://github.com/ncbi/sra-tools", "Type": "Standalone – CLI (Free)", "Feature": "Official NCBI toolkit; prefetch (downloads SRA files), fasterq-dump (converts to FASTQ, multi-threaded); fastq-dump, sam-dump, vdb-config; supports SRA/dbGaP/ADSP data; handles paired-end and single-end reads."}, {"Name": "SRA Explorer", "URL": "https://sra-explorer.info/", "Type": "Web-based (Free)", "Feature": "Browser-based search of SRA by accession/keyword; generates batch download scripts (curl/wget/Aspera); finds ENA FTP direct download URLs; exports metadata; no installation required."}, {"Name": "pysradb", "URL": "https://github.com/saketkc/pysradb", "Type": "Standalone – Python (Free)", "Feature": "Python package for SRA and GEO metadata retrieval; converts between GSE/RSP/SRX/SRR accessions; downloads FASTQ files; LLM-based metadata extraction; batch operations; integrates with Entrez API."}, {"Name": "Kingfisher", "URL": "https://github.com/wwood/kingfisher-download", "Type": "Standalone – CLI (Free)", "Feature": "Fast flexible SRA/ENA/AWS/GCP download; tries multiple download methods in sequence (ENA FTP, Aspera, AWS, GCP, prefetch); FASTQ/FASTA/SRA/GZIP output; usually faster than SRA Toolkit."}, {"Name": "ffq (Find FASTQ)", "URL": "https://github.com/pachterlab/ffq", "Type": "Standalone – CLI (Free)", "Feature": "Retrieves metadata and download links for SRA, GEO, ENA, DDBJ, EMBL datasets by accession; outputs JSON with full metadata; converts between SRA/study/sample/run accessions; no data download (links only)."}, {"Name": "SRAdownloader", "URL": "https://github.com/s-andrews/sradownloader", "Type": "Standalone – CLI (Free)", "Feature": "Takes SRA Run Selector annotation table as input; retrieves FASTQ files from ENA or NCBI; assigns meaningful filenames based on metadata; batch processing; simpler interface than SRA Toolkit."}, {"Name": "nf-core/fetchngs", "URL": "https://nf-co.re/fetchngs/", "Type": "Standalone – Nextflow (Free)", "Feature": "Nextflow pipeline for downloading raw sequencing data from SRA/ENA/DDBJ/GEO; automatically downloads FASTQ and metadata; outputs standardised samplesheets for other nf-core pipelines; supports HPC/cloud."}, {"Name": "parallel-fastq-dump", "URL": "https://github.com/rvalieris/parallel-fastq-dump", "Type": "Standalone – CLI (Free)", "Feature": "Parallelised wrapper for fastq-dump; splits SRA file and downloads in chunks simultaneously; faster than standard fastq-dump; supports gzip compression; retains all fastq-dump options."}, {"Name": "ENA Browser / ENA FTP", "URL": "https://www.ebi.ac.uk/ena/browser/", "Type": "Web-based + FTP (Free)", "Feature": "European mirror of SRA data; often faster downloads than NCBI for non-US users; direct FTP/Aspera access to FASTQ files; metadata search; API access; direct wget/curl download of FASTQ without conversion."}, {"Name": "Entrez Direct (EDirect)", "URL": "https://www.ncbi.nlm.nih.gov/books/NBK179288/", "Type": "Standalone – CLI (Free)", "Feature": "NCBI command-line utilities for querying all NCBI databases including SRA; esearch, efetch, elink, efilter commands; powerful text-based queries; metadata retrieval; scripting-friendly."}, {"Name": "Trim Galore", "URL": "https://github.com/FelixKrueger/TrimGalore", "Type": "Standalone – CLI (Free)", "Feature": "Quality trimming of FASTQ reads from SRA downloads; adapter auto-detection; integrates FastQC reports; supports paired-end; RRBS and small RNA modes; simple one-command usage."}, {"Name": "Trimmomatic", "URL": "http://www.usadellab.org/cms/?page=trimmomatic", "Type": "Standalone – Java (Free)", "Feature": "Flexible adapter trimming and quality filtering; LEADING, TRAILING, SLIDINGWINDOW, MINLEN, AVGQUAL, HEADCROP parameters; paired-end and single-end support; widely used in standard pipelines."}, {"Name": "fastp", "URL": "https://github.com/OpenGene/fastp", "Type": "Standalone – CLI (Free)", "Feature": "Ultra-fast FASTQ QC and trimming; automatic adapter detection; duplication analysis; per-base quality correction; HTML/JSON reports; supports paired-end; very fast due to multithreading."}, {"Name": "FastQC", "URL": "https://www.bioinformatics.babraham.ac.uk/projects/fastqc/", "Type": "Standalone + Web (Free)", "Feature": "Per-base quality scores; sequence content; GC content; adapter contamination; overrepresented sequences; duplication levels; HTML QC report; GUI and command-line modes; supports many formats."}, {"Name": "MultiQC", "URL": "https://multiqc.info/", "Type": "Standalone – CLI (Free)", "Feature": "Aggregates QC reports from FastQC, Trimmomatic, fastp, STAR, BWA, Bowtie2, featureCounts, and 100+ other tools into a single interactive HTML report; essential for multi-sample SRA studies."}, {"Name": "Galaxy (UseGalaxy.org)", "URL": "https://usegalaxy.org/", "Type": "Web-based (Free)", "Feature": "Browser-based bioinformatics platform; SRA import via accession; quality control; alignment; variant calling; assembly; annotation; 1,000+ integrated tools; no programming required; workflow sharing."}, {"Name": "NCBI Run Selector", "URL": "https://www.ncbi.nlm.nih.gov/Traces/study/", "Type": "Web-based (Free)", "Feature": "Web interface to browse and filter SRA experiments; filter by organism, platform, library strategy, read length, metadata; download accession lists and metadata tables for batch downloading."}, ] # ── Helper functions ────────────────────────────────────────────────────────── def sanitize_dataframe(df): df = df.replace({np.nan: None, 'nan': None, 'NaN': None}) return df.astype(object).where(pd.notnull(df), None) def normalize_val(v): if v is None or pd.isna(v) or str(v).lower().strip() in ['nan', 'none', '<na>', 'n/a']: return "" return str(v).lower().strip() BOS_TAURUS_ALIASES = {"bos taurus", "cattle"} def normalize_organism(v): val = normalize_val(v) return "bos taurus" if val in BOS_TAURUS_ALIASES else val def read_saved_homepage(): if os.path.exists(HOMEPAGE_FILE): try: with open(HOMEPAGE_FILE, "r", encoding="utf-8") as f: return f.read() except Exception: return "" return "" def save_homepage_content(html_content): try: with open(HOMEPAGE_FILE, "w", encoding="utf-8") as f: f.write(html_content) return " Homepage saved successfully!" except Exception as e: return f" Error saving: {str(e)}" def generate_view_html(): saved_content = read_saved_homepage() if not saved_content.strip(): return '<div style="min-height:500px;">' + HOMEPAGE_DEFAULT + '</div>' return f"""<div style="border:1px solid #e2e8f0;border-radius:8px;padding:24px;background:#ffffff;min-height:500px;color:#1e293b;font-family:system-ui,sans-serif;">{saved_content}</div>""" def generate_editor_html(): saved_content = read_saved_homepage() return f"""<div style="border:1px solid #e2e8f0;border-radius:8px;padding:16px;background:#ffffff;min-height:500px;display:flex;flex-direction:column;gap:12px;font-family:system-ui,sans-serif;"> <div id="homepage-canvas-editor" contenteditable="true" style="flex-grow:1;min-height:450px;outline:none;padding:16px;border:1px dashed #cbd5e1;border-radius:6px;overflow-y:auto;color:#1e293b;background:#f8fafc;">{saved_content}</div> </div>""" # ── Paper Alert HTML generator ──────────────────────────────────────────────── def generate_paper_alert_html( topic=PAPER_ALERT_TOPIC, days=PAPER_ALERT_DAYS, max_results=PAPER_ALERT_MAX ): topic_js = topic.replace("'", "\\'") return f""" <div id="paper-alert-overlay" style="display:none;position:fixed;inset:0;background:rgba(15,23,42,0.55); z-index:99999;align-items:center;justify-content:center;"> <div id="paper-alert-box" style="background:#ffffff;border-radius:12px;padding:28px 32px; max-width:640px;width:92%;max-height:82vh;overflow-y:auto; position:relative;border:1px solid #e2e8f0; box-shadow:0 16px 48px rgba(0,0,0,0.18);font-family:system-ui,sans-serif;"> <button onclick="closePaperAlert()" style="position:absolute;top:14px;right:16px;background:none;border:none; font-size:20px;cursor:pointer;color:#64748b;line-height:1;padding:4px 8px; border-radius:4px;" aria-label="Close paper alert"></button> <div style="display:flex;align-items:center;gap:12px;margin-bottom:18px;"> <div style="width:40px;height:40px;border-radius:50%;background:#eff6ff; display:flex;align-items:center;justify-content:center;flex-shrink:0;"> <span style="font-size:20px;"></span> </div> <div> <h2 style="margin:0;font-size:16px;font-weight:700;color:#0f172a;"> Recent Publications Alert </h2> <p style="margin:0;font-size:12px;color:#64748b;"> Last {days} days &nbsp;&bull;&nbsp; Topic:&nbsp;<em style="color:#2563eb;">{topic}</em> </p> </div> </div> <div id="paper-alert-list"> <div style="display:flex;align-items:center;gap:10px;padding:12px 0;color:#64748b;font-size:13px;"> <span style="display:inline-block;width:16px;height:16px;border:2px solid #2563eb; border-top-color:transparent;border-radius:50%; animation:pa-spin 0.8s linear infinite;"></span> Fetching latest papers from PubMed&hellip; </div> </div> <div style="margin-top:18px;display:flex;justify-content:space-between;align-items:center; border-top:1px solid #f1f5f9;padding-top:14px;"> <label style="display:flex;align-items:center;gap:6px;font-size:12px;color:#64748b;cursor:pointer;"> <input type="checkbox" id="pa-no-show" style="accent-color:#2563eb;"> Don&rsquo;t show again this session </label> <button onclick="closePaperAlert()" style="background:#2563eb;color:#fff;border:none;border-radius:6px; padding:8px 22px;font-size:13px;font-weight:600;cursor:pointer;"> Got it </button> </div> </div> </div> <style> @keyframes pa-spin {{ to {{ transform: rotate(360deg); }} }} </style> <script> (function() {{ var TOPIC = '{topic_js}'; var DAYS = {days}; var MAX_RESULTS = {max_results}; function closePaperAlert() {{ var overlay = document.getElementById('paper-alert-overlay'); if (overlay) overlay.style.display = 'none'; if (document.getElementById('pa-no-show') && document.getElementById('pa-no-show').checked) {{ try {{ sessionStorage.setItem('pa_dismissed', '1'); }} catch(e) {{}} }} }} window.closePaperAlert = closePaperAlert; function getMinDate() {{ var d = new Date(); d.setDate(d.getDate() - DAYS); var mm = String(d.getMonth() + 1).padStart(2, '0'); var dd = String(d.getDate()).padStart(2, '0'); return d.getFullYear() + '/' + mm + '/' + dd; }} function escapeHtml(str) {{ return String(str) .replace(/&/g, '&amp;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;') .replace(/"/g, '&quot;'); }} function renderPapers(articles) {{ var list = document.getElementById('paper-alert-list'); if (!list) return; if (!articles || articles.length === 0) {{ list.innerHTML = '<div style="padding:14px 0;color:#64748b;font-size:13px;text-align:center;">' + ' No new papers found in the last ' + DAYS + ' days for this topic.</div>'; return; }} var countLabel = articles.length === 1 ? '1 new paper found on PubMed' : articles.length + ' new papers found on PubMed'; var html = '<p style="font-size:12px;color:#475569;margin:0 0 12px;">&nbsp;' + countLabel + ':</p>'; articles.forEach(function(a) {{ html += '<div style="border:1px solid #e2e8f0;border-radius:8px;padding:12px 14px;' + 'margin-bottom:10px;background:#f8fafc;">' + '<a href="https://pubmed.ncbi.nlm.nih.gov/' + escapeHtml(a.uid) + '/" ' + 'target="_blank" rel="noopener noreferrer" ' + 'style="font-size:13px;font-weight:600;color:#2563eb;text-decoration:none;' + 'line-height:1.5;display:block;margin-bottom:5px;">' + escapeHtml(a.title) + '</a>' + '<p style="margin:0;font-size:11.5px;color:#64748b;">' + escapeHtml(a.authors) + (a.journal ? ' &bull; <em>' + escapeHtml(a.journal) + '</em>' : '') + (a.date ? ' &bull; ' + escapeHtml(a.date) : '') + '</p>' + '</div>'; }}); list.innerHTML = html; }} function renderError(msg) {{ var list = document.getElementById('paper-alert-list'); if (!list) return; list.innerHTML = '<div style="padding:12px;background:#fef2f2;border:1px solid #fecaca;' + 'border-radius:6px;color:#dc2626;font-size:13px;">&nbsp;' + escapeHtml(msg) + '</div>'; }} function fetchPapers() {{ var minDate = getMinDate(); var termRaw = TOPIC + ' AND ("' + minDate + '"[Date - Publication] : "3000"[Date - Publication])'; var term = encodeURIComponent(termRaw); var searchURL = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi' + '?db=pubmed&retmax=' + MAX_RESULTS + '&retmode=json&sort=date&term=' + term; fetch(searchURL) .then(function(r) {{ if (!r.ok) throw new Error('PubMed search request failed (' + r.status + ')'); return r.json(); }}) .then(function(data) {{ var ids = data.esearchresult && data.esearchresult.idlist; if (!ids || ids.length === 0) {{ renderPapers([]); return null; }} var summaryURL = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi' + '?db=pubmed&retmode=json&id=' + ids.join(','); return fetch(summaryURL); }}) .then(function(r) {{ if (!r) return null; if (!r.ok) throw new Error('PubMed summary request failed (' + r.status + ')'); return r.json(); }}) .then(function(data) {{ if (!data) return; var result = data.result; var uids = result.uids || []; var articles = uids.map(function(uid) {{ var a = result[uid] || {{}}; var rawAuth = a.authors || []; var names = rawAuth.slice(0, 3).map(function(x) {{ return x.name || ''; }}); if (rawAuth.length > 3) names.push('et al.'); return {{ uid: uid, title: a.title || 'Untitled', journal: a.fulljournalname || a.source || '', date: a.pubdate || '', authors: names.join(', ') || 'Unknown authors' }}; }}); renderPapers(articles); }}) .catch(function(err) {{ renderError('Could not fetch papers. Please check your connection. (' + err.message + ')'); }}); }} if (document.readyState === 'loading') {{ document.addEventListener('DOMContentLoaded', init); }} else {{ setTimeout(init, 600); }} }})(); </script> """ # ══════════════════════════════════════════════════════════════════════════════ # ── Multi-Database Literature Search Engine ─────────────────────────────────── # Searches: PubMed · Europe PMC · CrossRef · Semantic Scholar · bioRxiv/medRxiv # ══════════════════════════════════════════════════════════════════════════════ def _safe_request(url, headers=None, timeout=12): """Make an HTTP GET request and return parsed JSON, or None on failure.""" try: default_headers = {'User-Agent': 'Mozilla/5.0 (BioinformaticsHub/1.0)'} if headers: default_headers.update(headers) req = urllib.request.Request(url, headers=default_headers) with urllib.request.urlopen(req, timeout=timeout) as resp: return json.loads(resp.read().decode('utf-8')) except Exception: return None def _fetch_pubmed(query, since_date_str, max_results=200): """Fetch from NCBI PubMed using boolean query (AND/OR) with separate date range.""" results = [] try: query = normalize_boolean_query(query) query_enc = urllib.parse.quote(query) search_url = ( f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi" f"?db=pubmed&retmax={max_results}&retmode=json&sort=date" f"&term={query_enc}&mindate={since_date_str}&maxdate=3000" ) search_data = _safe_request(search_url) if not search_data: return results, "PubMed: request failed" ids = search_data.get('esearchresult', {}).get('idlist', []) if not ids: return results, "PubMed: 0 results" summary_url = ( f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi" f"?db=pubmed&retmode=json&id={','.join(ids)}" ) summary_data = _safe_request(summary_url) if not summary_data: return results, f"PubMed: retrieved {len(ids)} IDs but summary failed" result_dict = summary_data.get('result', {}) uids = result_dict.get('uids', []) for uid in uids: a = result_dict.get(uid, {}) raw_auth = a.get('authors', []) names = [x.get('name', '') for x in raw_auth[:3]] if len(raw_auth) > 3: names.append('et al.') results.append({ 'title': a.get('title', 'Untitled'), 'authors': ', '.join(names) if names else 'Unknown Authors', 'journal': a.get('fulljournalname', a.get('source', '')), 'date': a.get('pubdate', 'N/A'), 'url': f"https://pubmed.ncbi.nlm.nih.gov/{uid}/", 'doi': a.get('elocationid', '').replace('doi: ', '').strip(), 'source': 'PubMed', 'source_color': '#dc2626', 'source_bg': '#fef2f2', }) return results, f"PubMed: {len(results)} results" except Exception as e: return results, f"PubMed: error – {str(e)}" def _fetch_europe_pmc(query, since_date_str, max_results=200): """Fetch from Europe PMC using boolean query with dateFrom parameter.""" results = [] try: query = normalize_boolean_query(query) since_epmc = since_date_str.replace('/', '-') query_enc = urllib.parse.quote(query) url = ( f"https://www.ebi.ac.uk/europepmc/webservices/rest/search" f"?query={query_enc}&resultType=core&pageSize={max_results}&format=json&sort=P_PDATE_D%20desc" f"&dateFrom={since_epmc}" ) data = _safe_request(url) if not data: return results, "Europe PMC: request failed" articles = data.get('resultList', {}).get('result', []) for a in articles: authors_list = a.get('authorList', {}).get('author', []) names = [au.get('fullName', '') for au in authors_list[:3]] if len(authors_list) > 3: names.append('et al.') doi = a.get('doi', '') pmid = a.get('pmid', '') article_url = ( f"https://pubmed.ncbi.nlm.nih.gov/{pmid}/" if pmid else (f"https://doi.org/{doi}" if doi else f"https://europepmc.org/article/{a.get('source','')}/{a.get('id','')}") ) results.append({ 'title': a.get('title', 'Untitled').rstrip('.'), 'authors': ', '.join(names) if names else 'Unknown Authors', 'journal': a.get('journalTitle', a.get('bookOrReportDetails', {}).get('publisher', '')), 'date': a.get('firstPublicationDate', a.get('pubYear', 'N/A')), 'url': article_url, 'doi': doi, 'source': 'Europe PMC', 'source_color': '#7c3aed', 'source_bg': '#f5f3ff', }) return results, f"Europe PMC: {len(results)} results" except Exception as e: return results, f"Europe PMC: error – {str(e)}" def _fetch_crossref(query, since_date_str, max_results=100): """Fetch from CrossRef Works API – supports simple phrase queries.""" results = [] try: since_cr = since_date_str.replace('/', '-') query_enc = urllib.parse.quote(query) url = ( f"https://api.crossref.org/works" f"?query={query_enc}&filter=from-pub-date:{since_cr}" f"&rows={max_results}&sort=published&order=desc" f"&select=DOI,title,author,container-title,published,type" f"&mailto=biohub@example.com" ) data = _safe_request(url) if not data: return results, "CrossRef: request failed" items = data.get('message', {}).get('items', []) for item in items: item_type = item.get('type', '') if item_type not in ('journal-article', 'proceedings-article', 'posted-content'): continue titles = item.get('title', ['Untitled']) title = titles[0] if titles else 'Untitled' authors_raw = item.get('author', []) names = [] for au in authors_raw[:3]: fn = au.get('given', '') ln = au.get('family', '') names.append(f"{fn} {ln}".strip() if fn or ln else au.get('name', '')) if len(authors_raw) > 3: names.append('et al.') journals = item.get('container-title', []) journal = journals[0] if journals else '' doi = item.get('DOI', '') pub_date_parts = item.get('published', {}).get('date-parts', [[]]) parts = pub_date_parts[0] if pub_date_parts else [] pub_date = '-'.join(str(p) for p in parts) if parts else 'N/A' results.append({ 'title': title, 'authors': ', '.join(n for n in names if n) or 'Unknown Authors', 'journal': journal, 'date': pub_date, 'url': f"https://doi.org/{doi}" if doi else '', 'doi': doi, 'source': 'CrossRef', 'source_color': '#059669', 'source_bg': '#ecfdf5', }) return results, f"CrossRef: {len(results)} results" except Exception as e: return results, f"CrossRef: error – {str(e)}" def _fetch_semantic_scholar(query, since_date_str, max_results=100): """Fetch from Semantic Scholar – simple query string.""" results = [] try: since_ss = since_date_str.replace('/', '-') query_enc = urllib.parse.quote(query) url = ( f"https://api.semanticscholar.org/graph/v1/paper/search" f"?query={query_enc}" f"&publicationDateOrYear={since_ss}:" f"&fields=title,authors,venue,year,publicationDate,externalIds,openAccessPdf" f"&limit={min(max_results, 100)}" f"&sort=publicationDate:desc" ) data = _safe_request(url, headers={'x-api-key': ''}) if not data: return results, "Semantic Scholar: request failed" papers = data.get('data', []) for p in papers: authors_raw = p.get('authors', []) names = [a.get('name', '') for a in authors_raw[:3]] if len(authors_raw) > 3: names.append('et al.') ext_ids = p.get('externalIds', {}) doi = ext_ids.get('DOI', '') paper_id = p.get('paperId', '') pdf_info = p.get('openAccessPdf') or {} article_url = ( pdf_info.get('url') or (f"https://doi.org/{doi}" if doi else '') or (f"https://www.semanticscholar.org/paper/{paper_id}" if paper_id else '') ) pub_date = p.get('publicationDate') or str(p.get('year', 'N/A')) results.append({ 'title': p.get('title', 'Untitled'), 'authors': ', '.join(n for n in names if n) or 'Unknown Authors', 'journal': p.get('venue', ''), 'date': pub_date, 'url': article_url, 'doi': doi, 'source': 'Semantic Scholar', 'source_color': '#d97706', 'source_bg': '#fffbeb', }) return results, f"Semantic Scholar: {len(results)} results" except Exception as e: return results, f"Semantic Scholar: error – {str(e)}" def _normalize_doi(doi): """Normalize common DOI forms to a bare DOI string.""" doi = (doi or "").strip() doi = re.sub(r'^(?:https?://)?(?:dx\.)?doi\.org/', '', doi, flags=re.IGNORECASE) doi = doi.strip().rstrip('.,;') return doi.lower() def _extract_doi(doi_text): """Extract a DOI from provider strings such as 'pii: ..., doi: 10.xxxx/yyy'.""" raw = str(doi_text or '').strip() if not raw: return '' # Prefer an actual DOI-looking substring over provider prefixes such as pii:/doi:. match = re.search(r'(10\.\d{4,9}/[^\s,;]+)', raw, flags=re.IGNORECASE) if match: return _normalize_doi(match.group(1)) return _normalize_doi(raw) def _doi_html_result(doi, title, authors='', journal='', date='', url='', source='DOI lookup', user_name=''): doi = _extract_doi(doi) doi_display = doi url = url or f"https://doi.org/{doi}" is_reviewed = _is_reviewed_paper(doi=doi, link=url, user_name=user_name) if (doi or url) else False reviewed_badge = ( '<span style="background:#dcfce7;color:#15803d;padding:3px 8px;border-radius:9999px;' 'font-size:10px;font-weight:700;"> Read</span>' if is_reviewed else '' ) return f""" <div style=\"font-family:system-ui,sans-serif;border:1px solid #e2e8f0;border-radius:10px; padding:18px;background:#ffffff;box-shadow:0 1px 3px rgba(0,0,0,0.04);"> <div style=\"display:flex;align-items:center;gap:8px;margin-bottom:8px;flex-wrap:wrap;\"> <span style=\"background:#ecfdf5;color:#059669;padding:3px 8px;border-radius:9999px;font-size:10px;font-weight:700;\">{source}</span> <span style=\"font-size:11px;color:#94a3b8;\">DOI</span> {reviewed_badge} </div> <a href=\"{url}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"font-size:15px;font-weight:700;color:#2563eb;text-decoration:none;line-height:1.5;display:block;margin-bottom:10px;\"> {title} </a> <div style=\"font-size:12px;color:#475569;line-height:1.7;\"> {f'<div><strong>Authors:</strong> {authors}</div>' if authors else ''} {f'<div><strong>Journal:</strong> <em>{journal}</em></div>' if journal else ''} {f'<div><strong>Date:</strong> {date}</div>' if date else ''} <div><strong>DOI:</strong> <a href=\"{url}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color:#2563eb;word-break:break-all;\">{doi_display}</a></div> </div> </div> """ def search_by_doi(doi, user_name=""): """Look up a DOI across CrossRef, Europe PMC and PubMed.""" doi = _extract_doi(doi) if not doi or not re.match(r'^10\.\d{4,9}/\S+$', doi): return "<div style='color:#dc2626;font-size:13px;padding:12px;border:1px solid #fecaca;border-radius:8px;'> Please enter a valid DOI, for example <code>10.1093/nar/gkac123</code>.</div>" # CrossRef — primary DOI metadata source cr_url = "https://api.crossref.org/works/" + urllib.parse.quote(doi, safe='') cr = _safe_request(cr_url) if cr and cr.get('message'): item = cr['message'] titles = item.get('title') or ['Untitled'] title = titles[0] if titles else 'Untitled' auth = item.get('author') or [] names = [] for a in auth[:5]: name = ' '.join(x for x in [a.get('given',''), a.get('family','')] if x).strip() or a.get('name','') if name: names.append(name) if len(auth) > 5: names.append('et al.') journals = item.get('container-title') or [] journal = journals[0] if journals else '' date_parts = (item.get('published-print') or item.get('published-online') or item.get('published') or {}).get('date-parts', [[]]) parts = date_parts[0] if date_parts else [] date = '-'.join(str(x) for x in parts) if parts else '' url = item.get('URL') or f"https://doi.org/{doi}" return _doi_html_result(doi, title, ', '.join(names), journal, date, url, 'CrossRef', user_name) # Europe PMC fallback epmc = _safe_request( "https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=" + urllib.parse.quote(f'DOI:"{doi}"') + "&resultType=core&pageSize=5&format=json" ) if epmc: items = epmc.get('resultList', {}).get('result', []) if items: item = items[0] authors_list = item.get('authorList', {}).get('author', []) names = [a.get('fullName','') for a in authors_list[:5] if a.get('fullName')] if len(authors_list) > 5: names.append('et al.') pmid = item.get('pmid','') url = f"https://pubmed.ncbi.nlm.nih.gov/{pmid}/" if pmid else f"https://doi.org/{doi}" return _doi_html_result( doi, item.get('title','Untitled'), ', '.join(names), item.get('journalTitle',''), item.get('firstPublicationDate', str(item.get('pubYear',''))), url, 'Europe PMC', user_name ) # PubMed final fallback pm_url = ( "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmode=json&retmax=5&term=" + urllib.parse.quote(f'"{doi}"[AID] OR "{doi}"[DOI]') ) pm = _safe_request(pm_url) ids = (pm or {}).get('esearchresult', {}).get('idlist', []) if ids: sm = _safe_request( "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&id=" + ','.join(ids) ) if sm: result = sm.get('result', {}) uid = result.get('uids', [ids[0]])[0] item = result.get(uid, {}) raw = item.get('authors', []) names = [a.get('name','') for a in raw[:5] if a.get('name')] if len(raw) > 5: names.append('et al.') return _doi_html_result( doi, item.get('title','Untitled'), ', '.join(names), item.get('fulljournalname', item.get('source','')), item.get('pubdate',''), f"https://pubmed.ncbi.nlm.nih.gov/{uid}/", 'PubMed', user_name ) return "<div style='padding:20px;background:#ffffff;border:1px dashed #cbd5e1;border-radius:8px;text-align:center;color:#64748b;'> No publication metadata found for <strong style='color:#2563eb;'>" + doi + "</strong>.</div>" def get_reviewed_table_df(user_name=''): """Return reviewed papers belonging only to the supplied app user.""" columns = ['DOI', 'Reviewed At', 'User', 'Link'] user_name = _normalize_app_user(user_name) if not user_name: return pd.DataFrame(columns=columns) rows = [] if _check_reviewed_table(): try: res = ( supabase.table('reviewed_articles') .select('doi,reviewed_at,user,link') .eq('user', user_name) .order('reviewed_at', desc=True) .execute() ) for r in (res.data or []): doi = (r.get('doi') or '').strip() link = (r.get('link') or '').strip() if doi or link: rows.append({ 'DOI': doi, 'Reviewed At': r.get('reviewed_at') or '', 'User': r.get('user') or user_name, 'Link': link or (f'https://doi.org/{doi}' if doi else ''), }) except Exception: # Backward compatibility when the optional link column has not been added. try: res = ( supabase.table('reviewed_articles') .select('doi,reviewed_at,user') .eq('user', user_name) .order('reviewed_at', desc=True) .execute() ) for r in (res.data or []): doi = (r.get('doi') or '').strip() if doi: rows.append({ 'DOI': doi, 'Reviewed At': r.get('reviewed_at') or '', 'User': r.get('user') or user_name, 'Link': f'https://doi.org/{doi}', }) except Exception: pass db_dois = {str(r['DOI']).lower() for r in rows if str(r['DOI']).strip()} db_links = {str(r['Link']).lower() for r in rows if str(r['Link']).strip()} for doi in sorted(_reviewed_cache_by_user.get(user_name, set())): if doi not in db_dois: rows.append({ 'DOI': doi, 'Reviewed At': 'Session only', 'User': user_name, 'Link': f'https://doi.org/{doi}', }) for link in sorted(_reviewed_link_cache_by_user.get(user_name, set())): if link.lower() not in db_links: rows.append({ 'DOI': _extract_doi(link), 'Reviewed At': 'Session only', 'User': user_name, 'Link': link, }) return pd.DataFrame(rows, columns=columns) def reviewed_row_selection(evt: gr.SelectData, current_df): try: row_idx = evt.index[0] doi = str(current_df.iloc[row_idx].get('DOI', '')).strip() link = str(current_df.iloc[row_idx].get('Link', '')).strip() identifier = doi or link return identifier, f'Selected reviewed article: {identifier}' if identifier else 'No article selected.' except Exception as e: return '', f'Selection error: {e}' def remove_selected_reviewed_doi(selected_doi, user_name, request: gr.Request): session_hash = getattr(request, 'session_hash', None) if not session_hash or session_hash not in _admin_sessions: return 'Admin login required. Please log in first.', get_reviewed_table_df(user_name), '' if not is_senior_admin(session_hash): return 'Senior admin access required to remove reviewed articles.', get_reviewed_table_df(user_name), '' user_name = get_current_app_user(session_hash) if not user_name: return 'Please select a user first.', get_reviewed_table_df(), '' if not selected_doi or not selected_doi.strip(): return 'Select a marked article first.', get_reviewed_table_df(user_name), '' msg = remove_reviewed_article(selected_doi, user_name) return msg, get_reviewed_table_df(user_name), '' def _fetch_biorxiv(query, since_date_str, max_results=100): """Fetch from bioRxiv/medRxiv – basic keyword filtering (simple AND on split terms).""" results = [] try: today_str = datetime.date.today().strftime("%Y-%m-%d") since_bxr = since_date_str.replace('/', '-') # Extract keywords (remove quotes and split) keywords = [w.strip('"').lower() for w in query.split() if len(w) > 2 and w not in ('AND', 'OR', 'NOT')] # If query has quotes, keep them as phrase? # We'll keep it simple: use the raw query as a phrase for title/abstract checking. for server in ['biorxiv', 'medrxiv']: url = f"https://api.biorxiv.org/details/{server}/{since_bxr}/{today_str}/0/json" data = _safe_request(url) if not data: continue collection = data.get('collection', []) for item in collection: title = item.get('title', 'Untitled') abstract = item.get('abstract', '').lower() # Check if all keywords appear (simple AND) match = True for kw in keywords: if kw not in title.lower() and kw not in abstract: match = False break if not match: continue doi = item.get('doi', '') authors_str = item.get('authors', 'Unknown Authors') author_list = [a.strip() for a in authors_str.split(';')] names = author_list[:3] if len(author_list) > 3: names.append('et al.') results.append({ 'title': title, 'authors': '; '.join(names), 'journal': f"{server.capitalize()} (Preprint)", 'date': item.get('date', 'N/A'), 'url': f"https://doi.org/{doi}" if doi else f"https://www.{server}.org/", 'doi': doi, 'source': server.capitalize(), 'source_color': '#0891b2', 'source_bg': '#ecfeff', }) if len(results) >= max_results: break if len(results) >= max_results: break return results, f"bioRxiv/medRxiv: {len(results)} results" except Exception as e: return results, f"bioRxiv/medRxiv: error – {str(e)}" def _deduplicate(all_results): """Remove duplicates by DOI (if present) or by normalised title.""" seen_dois = set() seen_titles = set() unique = [] for r in all_results: doi = r.get('doi', '').strip().lower() title_key = r.get('title', '').strip().lower()[:80] if doi and doi in seen_dois: continue if title_key and title_key in seen_titles: continue if doi: seen_dois.add(doi) if title_key: seen_titles.add(title_key) unique.append(r) return unique def _sort_results(results): """Sort results by date descending, with unparseable dates last.""" def date_key(r): d = r.get('date', '') or '' for fmt in ('%Y-%m-%d', '%Y/%m/%d', '%Y %b %d', '%Y %b', '%Y'): try: return datetime.datetime.strptime(d.strip()[:len(fmt)+2], fmt) except Exception: pass parts = d.strip().split() if parts: try: return datetime.datetime(int(parts[0]), 1, 1) except Exception: pass return datetime.datetime.min return sorted(results, key=date_key, reverse=True) def _render_source_badge(source, color, bg): return ( f'<span style="background:{bg};color:{color};padding:2px 7px;' f'border-radius:9999px;font-size:10px;font-weight:700;' f'border:1px solid {color}22;white-space:nowrap;">{source}</span>' ) def _run_multi_db_search(query, selected_sources, since_date, since_date_dash, window_label, user_name=""): """ Shared engine for running a multi-database search given an explicit 'since' date window, and rendering the resulting HTML. """ if not query or not query.strip(): return "<div style='color:#dc2626;font-size:13px;padding:12px;'> Please enter a valid search query.</div>" # If query contains boolean operators, force only PubMed if _is_boolean_query(query): selected_sources = ['PubMed'] # override all_results = [] source_logs = [] source_map = { 'PubMed': lambda: _fetch_pubmed(query, since_date), 'Europe PMC': lambda: _fetch_europe_pmc(query, since_date_dash), 'CrossRef': lambda: _fetch_crossref(query, since_date_dash), 'Semantic Scholar': lambda: _fetch_semantic_scholar(query, since_date_dash), 'bioRxiv / medRxiv': lambda: _fetch_biorxiv(query, since_date_dash), } for src_name, fetch_fn in source_map.items(): if src_name not in selected_sources: continue try: res, log = fetch_fn() all_results.extend(res) source_logs.append(log) except Exception as e: source_logs.append(f"{src_name}: unexpected error – {str(e)}") if not all_results: log_html = ' &nbsp;|&nbsp;'.join(source_logs) return f""" <div style='padding:28px;background:#ffffff;border:1px dashed #cbd5e1; border-radius:8px;text-align:center;color:#64748b; font-family:system-ui,sans-serif;'> No papers found for <strong style="color:#2563eb;">"{query}"</strong> {window_label}.<br> <span style="font-size:11px;margin-top:8px;display:block;color:#94a3b8;">{log_html}</span> </div>""" unique_results = _deduplicate(all_results) sorted_results = _sort_results(unique_results) source_counts = {} for r in sorted_results: src = r.get('source', 'Unknown') source_counts[src] = source_counts.get(src, 0) + 1 badge_row = ' '.join( f'<span style="background:#f1f5f9;color:#475569;padding:3px 9px;' f'border-radius:9999px;font-size:11px;font-weight:600;">' f'{src}: {cnt}</span>' for src, cnt in source_counts.items() ) log_html = ' &nbsp;|&nbsp;'.join(source_logs) reviewed_dois, reviewed_links = load_reviewed_keys(user_name) html = f""" <div style="font-family:system-ui,sans-serif;"> <div style="background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px; padding:14px 18px;margin-bottom:18px;"> <p style="margin:0 0 8px;font-size:14px;font-weight:700;color:#0f172a;"> {len(sorted_results)} unique publications retrieved <span style="font-size:12px;color:#64748b;font-weight:400;"> ({window_label} · deduplicated) </span> </p> <div style="display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px;">{badge_row}</div> <p style="margin:0;font-size:11px;color:#94a3b8;">{log_html}</p> </div> """ # No reviewed DOIs or mark buttons - removed entirely for r in sorted_results: src_badge = _render_source_badge(r['source'], r['source_color'], r['source_bg']) title = r.get('title', 'Untitled') url = r.get('url', '') authors = r.get('authors', 'Unknown Authors') journal = r.get('journal', '') date = r.get('date', 'N/A') doi = _extract_doi(r.get('doi', '')) reviewed_badge = ( '<span style="background:#dcfce7;color:#15803d;padding:2px 8px;border-radius:9999px;' 'font-weight:700;font-size:11px;"> Read</span>' if (doi and doi in reviewed_dois) or (_normalize_reviewed_link(url) and _normalize_reviewed_link(url) in reviewed_links) else '' ) doi_link = ( f'<a href="https://doi.org/{doi}" target="_blank" rel="noopener noreferrer" ' f'style="color:#64748b;font-size:11px;text-decoration:none;">DOI: {doi}</a>' if doi else '' ) title_html = ( f'<a href="{url}" target="_blank" rel="noopener noreferrer" ' f'style="font-size:13.5px;font-weight:600;color:#2563eb;text-decoration:none;' f'line-height:1.5;display:block;margin-bottom:7px;">{title}</a>' if url else f'<span style="font-size:13.5px;font-weight:600;color:#1e293b;' f'display:block;margin-bottom:7px;">{title}</span>' ) html += f""" <div class="art-result-card" style="border:1px solid #e2e8f0; border-radius:8px;padding:14px 16px; margin-bottom:10px;background:#ffffff; box-shadow:0 1px 2px rgba(0,0,0,0.03);"> {title_html} <div style="display:flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:12px;color:#475569;"> {src_badge} <span><strong>Authors:</strong> {authors}</span> {'<span>&bull;</span><em style="color:#64748b;">' + journal + '</em>' if journal else ''} <span style="background:#eff6ff;color:#1e40af;padding:2px 8px; border-radius:4px;font-weight:600;font-size:11px;"> {date}</span> {reviewed_badge} {doi_link} </div> </div> """ html += "</div>" return html def fetch_multi_db_papers(query, selected_sources, user_name=""): """ Entry-point for the recent (past 6 months) multi-database literature search. """ six_months_ago = datetime.date.today() - datetime.timedelta(days=180) since_date = six_months_ago.strftime("%Y/%m/%d") since_date_dash = six_months_ago.strftime("%Y-%m-%d") return _run_multi_db_search(query, selected_sources, since_date, since_date_dash, "past 6 months", user_name) # ── Paged All-Time Literature Search ───────────────────────────────────────── LS_FETCH_SIZE = 50 LS_PAGE_SIZE = 20 LS_YEAR_MIN = 1900 LS_YEAR_MAX = datetime.date.today().year def _fetch_pubmed_paged(query, start_year, end_year, offset): results, exhausted = [], False try: query = normalize_boolean_query(query) query_enc = urllib.parse.quote(query) search_url = ( f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi" f"?db=pubmed&retmax={LS_FETCH_SIZE}&retstart={offset}" f"&retmode=json&sort=date&term={query_enc}" f"&mindate={start_year}/01/01&maxdate={end_year}/12/31" ) search_data = _safe_request(search_url) if not search_data: return results, True esresult = search_data.get('esearchresult', {}) total = int(esresult.get('count', 0)) ids = esresult.get('idlist', []) if not ids: return results, True exhausted = (offset + len(ids)) >= total summary_url = ( f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi" f"?db=pubmed&retmode=json&id={','.join(ids)}" ) summary_data = _safe_request(summary_url) if not summary_data: return results, exhausted result_dict = summary_data.get('result', {}) for uid in result_dict.get('uids', []): a = result_dict.get(uid, {}) raw_auth = a.get('authors', []) names = [x.get('name', '') for x in raw_auth[:3]] if len(raw_auth) > 3: names.append('et al.') results.append({ 'title': a.get('title', 'Untitled'), 'authors': ', '.join(names) if names else 'Unknown Authors', 'journal': a.get('fulljournalname', a.get('source', '')), 'date': a.get('pubdate', 'N/A'), 'url': f"https://pubmed.ncbi.nlm.nih.gov/{uid}/", 'doi': a.get('elocationid', '').replace('doi: ', '').strip(), 'source': 'PubMed', 'source_color': '#dc2626', 'source_bg': '#fef2f2', }) return results, exhausted except Exception: return results, True def _fetch_europe_pmc_paged(query, start_year, end_year, offset): results, exhausted = [], False try: query = normalize_boolean_query(query) page_num = offset // LS_FETCH_SIZE query_enc = urllib.parse.quote(query) url = ( f"https://www.ebi.ac.uk/europepmc/webservices/rest/search" f"?query={query_enc}&resultType=core&pageSize={LS_FETCH_SIZE}" f"&page={page_num}&format=json&sort=P_PDATE_D%20desc" f"&dateFrom={start_year}-01-01&dateTo={end_year}-12-31" ) data = _safe_request(url) if not data: return results, True hit_count = int(data.get('hitCount', 0)) articles = data.get('resultList', {}).get('result', []) if not articles: return results, True exhausted = (offset + len(articles)) >= hit_count for a in articles: auth_list = a.get('authorList', {}).get('author', []) names = [au.get('fullName', '') for au in auth_list[:3]] if len(auth_list) > 3: names.append('et al.') doi = a.get('doi', '') pmid = a.get('pmid', '') article_url = ( f"https://pubmed.ncbi.nlm.nih.gov/{pmid}/" if pmid else (f"https://doi.org/{doi}" if doi else f"https://europepmc.org/article/{a.get('source','')}/{a.get('id','')}") ) results.append({ 'title': a.get('title', 'Untitled').rstrip('.'), 'authors': ', '.join(names) if names else 'Unknown Authors', 'journal': a.get('journalTitle', ''), 'date': a.get('firstPublicationDate', a.get('pubYear', 'N/A')), 'url': article_url, 'doi': doi, 'source': 'Europe PMC', 'source_color': '#7c3aed', 'source_bg': '#f5f3ff', }) return results, exhausted except Exception: return results, True def _fetch_crossref_paged(query, start_year, end_year, offset): results, exhausted = [], False try: query_enc = urllib.parse.quote(query) url = ( f"https://api.crossref.org/works" f"?query={query_enc}" f"&filter=from-pub-date:{start_year}-01-01,until-pub-date:{end_year}-12-31" f"&rows={LS_FETCH_SIZE}&offset={offset}&sort=published&order=desc" f"&select=DOI,title,author,container-title,published,type" f"&mailto=biohub@example.com" ) data = _safe_request(url) if not data: return results, True msg = data.get('message', {}) total = msg.get('total-results', 0) items = msg.get('items', []) if not items: return results, True exhausted = (offset + len(items)) >= total for item in items: if item.get('type', '') not in ('journal-article', 'proceedings-article', 'posted-content'): continue titles = item.get('title', ['Untitled']) title = titles[0] if titles else 'Untitled' authors_raw = item.get('author', []) names = [] for au in authors_raw[:3]: fn = au.get('given', ''); ln = au.get('family', '') names.append(f"{fn} {ln}".strip() if fn or ln else au.get('name', '')) if len(authors_raw) > 3: names.append('et al.') journals = item.get('container-title', []) journal = journals[0] if journals else '' doi = item.get('DOI', '') parts = (item.get('published', {}).get('date-parts', [[]])[0] or []) pub_date = '-'.join(str(p) for p in parts) if parts else 'N/A' results.append({ 'title': title, 'authors': ', '.join(n for n in names if n) or 'Unknown Authors', 'journal': journal, 'date': pub_date, 'url': f"https://doi.org/{doi}" if doi else '', 'doi': doi, 'source': 'CrossRef', 'source_color': '#059669', 'source_bg': '#ecfdf5', }) return results, exhausted except Exception: return results, True def _fetch_semantic_scholar_paged(query, start_year, end_year, offset): results, exhausted = [], False try: query_enc = urllib.parse.quote(query) url = ( f"https://api.semanticscholar.org/graph/v1/paper/search" f"?query={query_enc}" f"&publicationDateOrYear={start_year}:{end_year}" f"&fields=title,authors,venue,year,publicationDate,externalIds,openAccessPdf" f"&limit={min(LS_FETCH_SIZE, 100)}&offset={offset}" ) data = _safe_request(url, headers={'x-api-key': ''}) if not data: return results, True total = data.get('total', 0) papers = data.get('data', []) if not papers: return results, True exhausted = (offset + len(papers)) >= total for p in papers: authors_raw = p.get('authors', []) names = [a.get('name', '') for a in authors_raw[:3]] if len(authors_raw) > 3: names.append('et al.') ext_ids = p.get('externalIds', {}) doi = ext_ids.get('DOI', '') paper_id = p.get('paperId', '') pdf_info = p.get('openAccessPdf') or {} article_url = ( pdf_info.get('url') or (f"https://doi.org/{doi}" if doi else '') or (f"https://www.semanticscholar.org/paper/{paper_id}" if paper_id else '') ) pub_date = p.get('publicationDate') or str(p.get('year', 'N/A')) results.append({ 'title': p.get('title', 'Untitled'), 'authors': ', '.join(n for n in names if n) or 'Unknown Authors', 'journal': p.get('venue', ''), 'date': pub_date, 'url': article_url, 'doi': doi, 'source': 'Semantic Scholar', 'source_color': '#d97706', 'source_bg': '#fffbeb', }) return results, exhausted except Exception: return results, True def _fetch_biorxiv_paged(query, start_year, end_year, cursor): results, exhausted = [], False try: start_dt = f"{start_year}-01-01" end_dt = f"{end_year}-12-31" # Use normalized query for keyword extraction norm_query = normalize_boolean_query(query) keywords = [w.strip('"').lower() for w in norm_query.split() if len(w) > 2 and w not in ('AND', 'OR', 'NOT')] for server in ['biorxiv', 'medrxiv']: url = f"https://api.biorxiv.org/details/{server}/{start_dt}/{end_dt}/{cursor}/json" data = _safe_request(url) if not data: continue collection = data.get('collection', []) if not collection: exhausted = True continue if len(collection) < 100: exhausted = True for item in collection: title = item.get('title', 'Untitled') abstract = item.get('abstract', '').lower() match = True for kw in keywords: if kw not in title.lower() and kw not in abstract: match = False break if not match: continue doi = item.get('doi', '') authors_str = item.get('authors', 'Unknown Authors') author_list = [a.strip() for a in authors_str.split(';')] names = author_list[:3] if len(author_list) > 3: names.append('et al.') results.append({ 'title': title, 'authors': '; '.join(names), 'journal': f"{server.capitalize()} (Preprint)", 'date': item.get('date', 'N/A'), 'url': f"https://doi.org/{doi}" if doi else f"https://www.{server}.org/", 'doi': doi, 'source': server.capitalize(), 'source_color': '#0891b2', 'source_bg': '#ecfeff', }) return results, exhausted except Exception: return results, True def _ls_fetch_batch(state): """Fetch one batch from all non-exhausted sources and merge into pool.""" topic = state['topic'] start_year = state['start_year'] end_year = state['end_year'] sources = state['sources'] exhausted = set(state['exhausted']) seen_dois = set(state['seen_dois']) seen_titles = set(state['seen_titles']) fetcher_map = { 'PubMed': lambda off: _fetch_pubmed_paged(topic, start_year, end_year, off), 'Europe PMC': lambda off: _fetch_europe_pmc_paged(topic, start_year, end_year, off), 'CrossRef': lambda off: _fetch_crossref_paged(topic, start_year, end_year, off), 'Semantic Scholar': lambda off: _fetch_semantic_scholar_paged(topic, start_year, end_year, off), 'bioRxiv / medRxiv': lambda off: _fetch_biorxiv_paged(topic, start_year, end_year, off), } new_results = [] for src_name, fetcher in fetcher_map.items(): if src_name not in sources or src_name in exhausted: continue offset = state['offsets'].get(src_name, 0) try: res, is_exhausted = fetcher(offset) if is_exhausted: exhausted.add(src_name) state['offsets'][src_name] = offset + LS_FETCH_SIZE new_results.extend(res) except Exception: exhausted.add(src_name) for r in new_results: doi = r.get('doi', '').strip().lower() title_key = r.get('title', '').strip().lower()[:80] if doi and doi in seen_dois: continue if title_key and title_key in seen_titles: continue if doi: seen_dois.add(doi) if title_key: seen_titles.add(title_key) state['pool'].append(r) state['pool'] = _sort_results(state['pool']) state['exhausted'] = list(exhausted) state['seen_dois'] = list(seen_dois) state['seen_titles'] = list(seen_titles) def _ls_render_page(state, user_name=""): """Render the current Literature Search page using the active user's reviewed state.""" state = state or _ls_empty_state() page = state.get('page', 1) pool = state.get('pool', []) start = (page - 1) * LS_PAGE_SIZE end = start + LS_PAGE_SIZE items = pool[start:end] # Always load the reviewed state here. This was previously omitted, which # caused Literature Search to fail with an undefined-variable error and # also broke the Mark as Read refresh path. user_name = _normalize_app_user(user_name) reviewed_dois, reviewed_links = load_reviewed_keys(user_name) if not items: return ("<div style='padding:40px;text-align:center;color:#64748b;" "font-size:13px;border:1px dashed #e2e8f0;border-radius:8px;" "background:#ffffff;'>No results on this page.</div>") html = "" for r in items: src_badge = _render_source_badge(r['source'], r['source_color'], r['source_bg']) title = r.get('title', 'Untitled') url = r.get('url', '') authors = r.get('authors', 'Unknown Authors') journal = r.get('journal', '') date = r.get('date', 'N/A') doi = _extract_doi(r.get('doi', '')) reviewed_badge = ( '<span style="background:#dcfce7;color:#15803d;padding:2px 8px;border-radius:9999px;' 'font-weight:700;font-size:11px;"> Read</span>' if (doi and doi in reviewed_dois) or (_normalize_reviewed_link(url) and _normalize_reviewed_link(url) in reviewed_links) else '' ) doi_link = ( f'<a href="https://doi.org/{doi}" target="_blank" rel="noopener noreferrer" ' f'style="color:#64748b;font-size:11px;text-decoration:none;">DOI: {doi}</a>' if doi else '' ) title_html = ( f'<a href="{url}" target="_blank" rel="noopener noreferrer" ' f'style="font-size:13.5px;font-weight:600;color:#2563eb;text-decoration:none;' f'line-height:1.5;display:block;margin-bottom:7px;">{title}</a>' if url else f'<span style="font-size:13.5px;font-weight:600;color:#1e293b;' f'display:block;margin-bottom:7px;">{title}</span>' ) html += f"""<div class="art-result-card" style="border:1px solid #e2e8f0; border-radius:8px;padding:14px 16px; margin-bottom:10px;background:#ffffff; box-shadow:0 1px 2px rgba(0,0,0,0.03);"> {title_html} <div style="display:flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:12px;color:#475569;"> {src_badge} <span><strong>Authors:</strong> {authors}</span> {'<span>&bull;</span><em style="color:#64748b;">' + journal + '</em>' if journal else ''} <span style="background:#eff6ff;color:#1e40af;padding:2px 8px;border-radius:4px; font-weight:600;font-size:11px;"> {date}</span> {reviewed_badge} {doi_link} </div> </div>""" return html def _ls_render_nav(state): page = state['page'] pool = state['pool'] exhausted = state['exhausted'] sources = state['sources'] total_pool = len(pool) max_known_page = max(1, (total_pool + LS_PAGE_SIZE - 1) // LS_PAGE_SIZE) all_exhausted = all(s in exhausted for s in sources) if sources else True has_more = not all_exhausted pages_to_show = list(range(1, min(max_known_page, 10) + 1)) show_ellipsis = (max_known_page > 10) or has_more btns = "" for p in pages_to_show: if p == page: btns += (f'<span style="display:inline-flex;align-items:center;justify-content:center;' f'min-width:32px;height:32px;padding:0 8px;border-radius:6px;' f'background:#2563eb;color:#fff;font-size:12px;font-weight:700;">{p}</span>') else: btns += (f'<span style="display:inline-flex;align-items:center;justify-content:center;' f'min-width:32px;height:32px;padding:0 8px;border-radius:6px;' f'background:#f1f5f9;color:#475569;font-size:12px;">{p}</span>') if show_ellipsis: btns += ('<span style="display:inline-flex;align-items:center;justify-content:center;' 'width:32px;height:32px;color:#94a3b8;font-size:16px;">…</span>') src_counts = {} for r in pool: s = r.get('source', '') src_counts[s] = src_counts.get(s, 0) + 1 badges = ' '.join( f'<span style="background:#f1f5f9;color:#475569;padding:2px 8px;border-radius:9999px;' f'font-size:11px;font-weight:600;">{s}: {c}</span>' for s, c in src_counts.items() ) status_line = ( f'<div style="font-size:11px;color:#94a3b8;text-align:center;margin-bottom:6px;">' f'Page {page} · {total_pool} results loaded' + (' · fetching more…' if has_more else ' · all sources loaded') + f'</div>' ) return f"""<div style="font-family:system-ui,sans-serif;padding:4px 0 8px;"> {status_line} <div style="display:flex;flex-wrap:wrap;justify-content:center;gap:4px;margin-bottom:8px;"> {btns} </div> <div style="display:flex;flex-wrap:wrap;justify-content:center;gap:5px;">{badges}</div> </div>""" def _ls_empty_state(): return { 'topic': '', 'sources': [], 'start_year': LS_YEAR_MIN, 'end_year': LS_YEAR_MAX, 'page': 1, 'pool': [], 'offsets': {}, 'exhausted': [], 'seen_dois': [], 'seen_titles': [], } def ls_init_search(query, sources, start_year, end_year, user_name=""): start_year = int(start_year) if start_year else LS_YEAR_MIN end_year = int(end_year) if end_year else LS_YEAR_MAX if not query or not query.strip(): err = ("<div style='color:#dc2626;font-size:13px;padding:12px;" "border:1px solid #fecaca;border-radius:8px;'>" " Please enter a valid search query.</div>") return err, "", _ls_empty_state() # If boolean query, restrict to PubMed if _is_boolean_query(query): sources = ['PubMed'] state = { 'topic': query.strip(), 'sources': list(sources), 'start_year': start_year, 'end_year': end_year, 'page': 1, 'pool': [], 'offsets': {}, 'exhausted': [], 'seen_dois': [], 'seen_titles': [], } _ls_fetch_batch(state) if len(state['pool']) < LS_PAGE_SIZE: _ls_fetch_batch(state) if not state['pool']: empty_html = ( "<div style='padding:28px;background:#ffffff;border:1px dashed #cbd5e1;" "border-radius:8px;text-align:center;color:#64748b;" "font-family:system-ui,sans-serif;'>" " No papers found for <strong style='color:#2563eb;'>&ldquo;" + query + "&rdquo;</strong> in the selected year range across chosen databases.</div>" ) return empty_html, "", state return _ls_render_page(state, user_name), _ls_render_nav(state), state def ls_prev_page(state, user_name=""): if not state or state['page'] <= 1: return _ls_render_page(state, user_name), _ls_render_nav(state), state state = {**state, 'page': state['page'] - 1} return _ls_render_page(state, user_name), _ls_render_nav(state), state def ls_next_page(state, user_name=""): if not state: return "", "", state state = dict(state) next_page = state['page'] + 1 needed = next_page * LS_PAGE_SIZE max_batches = 6 batches_done = 0 all_exhausted = lambda: all(s in state['exhausted'] for s in state['sources']) while len(state['pool']) < needed and not all_exhausted() and batches_done < max_batches: _ls_fetch_batch(state) batches_done += 1 if len(state['pool']) >= (next_page - 1) * LS_PAGE_SIZE + 1: state['page'] = next_page return _ls_render_page(state, user_name), _ls_render_nav(state), state # ── Database functions ──────────────────────────────────────────────────────── def search_supabase(species, tissue, tool, accession=""): if not supabase: return pd.DataFrame({"Error": ["Supabase keys are missing. Connection failed."]}) try: table_name = "sra_database" if tool == "SRA" else "geo_database" response = supabase.table(table_name).select("*").execute() raw_data = response.data if not raw_data: return pd.DataFrame({"Status": [f"No records found in {table_name}."]}) df = pd.DataFrame(raw_data) if 'created_at' in df.columns: df = df.drop(columns=['created_at']) if accession and accession.strip(): if "Accession" in df.columns: df = df[df["Accession"].astype(str).str.lower().str.strip() == accession.lower().strip()] if df.empty: return pd.DataFrame({"Status": [f"No matching record for Accession '{accession}'."]}) else: if "Organism" in df.columns: df = df[df["Organism"].apply(normalize_organism) == normalize_organism(species)] if "tissue" in df.columns: df = df[df["tissue"].astype(str).str.lower().str.strip() == tissue.lower().strip()] if df.empty: return pd.DataFrame({"Status": [f"No records for '{species}' in {tool}."]}) display_cols = [c for c in ALL_UNIQUE_COLUMNS if c in df.columns] return df[display_cols].fillna("N/A") except Exception as e: return pd.DataFrame({"Database Error": [f"Failed to fetch data: {str(e)}"]}) def load_entire_table(): if not supabase: return pd.DataFrame({"Error": ["Supabase connection is inactive."]}) try: sra_res = supabase.table("sra_database").select("*").execute() df_sra = pd.DataFrame(sra_res.data) if sra_res.data else pd.DataFrame() if 'created_at' in df_sra.columns: df_sra = df_sra.drop(columns=['created_at']) geo_res = supabase.table("geo_database").select("*").execute() df_geo = pd.DataFrame(geo_res.data) if geo_res.data else pd.DataFrame() if 'created_at' in df_geo.columns: df_geo = df_geo.drop(columns=['created_at']) if df_sra.empty and df_geo.empty: return pd.DataFrame(columns=ALL_UNIQUE_COLUMNS) combined_df = pd.concat([df_sra, df_geo], ignore_index=True) ordered_cols = [c for c in ALL_UNIQUE_COLUMNS if c in combined_df.columns] return combined_df[ordered_cols].fillna("N/A") except Exception as e: return pd.DataFrame({"Error": [str(e)]}) def generate_tools_launchpad_html(dataset_type="GEO"): tools = SRA_TOOLS_DATA if dataset_type == "SRA" else GEO_TOOLS_DATA icon = "" if dataset_type == "SRA" else "" label = "SRA Download & QC" if dataset_type == "SRA" else "GEO Analytical" accent = "#0891b2" if dataset_type == "SRA" else "#2563eb" html = f"""<div style="margin-top:16px;font-family:system-ui,sans-serif;"> <p style="color:#1e293b;font-weight:600;margin-bottom:16px;font-size:15px;">{icon} Biological Data Located. Launch a <strong>{label}</strong> Suite below:</p> <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:16px;">""" for tool in tools: html += f"""<div style="border:1px solid #e2e8f0;border-radius:8px;padding:16px;background:#ffffff;display:flex;flex-direction:column;justify-content:space-between;box-shadow:0 1px 3px rgba(0,0,0,0.06);"> <div> <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;gap:8px;"> <strong style="color:{accent};font-size:14px;font-weight:700;">{tool['Name']}</strong> <span style="font-size:11px;background:#f1f5f9;color:#475569;padding:3px 8px;border-radius:9999px;font-weight:500;border:1px solid #e2e8f0;white-space:nowrap;">{tool['Type']}</span> </div> <p style="font-size:12.5px;color:#475569;margin:0 0 14px;line-height:1.6;">{tool['Feature']}</p> </div> <a href="{tool['URL']}" target="_blank" style="display:block;text-align:center;background:{accent};color:#ffffff;text-decoration:none;padding:8px 12px;font-size:13px;font-weight:600;border-radius:6px;">Go to Tool</a> </div>""" html += "</div></div>" return html def handle_search_and_box(species, tissue, tool, accession): df_result = search_supabase(species, tissue, tool, accession) tools_launchpad = generate_tools_launchpad_html(dataset_type=tool) return df_result, gr.Column(visible=True), gr.HTML(value=f"<div>{tools_launchpad}</div>") def admin_search_supabase(species, tissue, tool, request: gr.Request): session_hash = getattr(request, "session_hash", None) if not is_senior_admin(session_hash): return pd.DataFrame({"Error": [" Senior admin access required."]}) return search_supabase(species, tissue, tool) def logout_admin(request: gr.Request): """Log out the current admin session and clear the selected app user.""" global _admin_active session_hash = getattr(request, "session_hash", None) if session_hash: _admin_sessions.pop(session_hash, None) _admin_roles.pop(session_hash, None) _admin_users.pop(session_hash, None) _admin_active = False return ( gr.update(visible=True), # login_panel gr.update(visible=True), # user_gate_panel gr.update(visible=False), # junior_access_panel gr.update(visible=False), # upload_panel "Logged out.", BLANK_TEMPLATE_DF, gr.update(visible=True), gr.update(visible=False), gr.update(value=generate_view_html()), False, gr.update(visible=False), gr.update(visible=False), get_reviewed_table_df(), get_reviewed_table_df(), gr.update(visible=False), gr.update(visible=False), gr.update(value="Set your user in the Administrative Portal."), gr.update(value="Current user: not selected"), gr.update(value="Current user: not selected"), "", ) def check_upload_credentials_generator(username, password, request: gr.Request): """Authenticate the senior administrator; ordinary users use the public user gate.""" global _admin_active session_hash = getattr(request, "session_hash", None) username = "" if username is None else str(username).strip() password = "" if password is None else str(password) role = None if AUTH_USER and AUTH_PASS and username == str(AUTH_USER).strip() and password == str(AUTH_PASS): role = "senior" if role and session_hash: _admin_active = True set_admin_active(session_hash, role) clear_current_app_user(session_hash) else: _admin_active = False if session_hash: _admin_sessions.pop(session_hash, None) _admin_roles.pop(session_hash, None) _admin_users.pop(session_hash, None) common = ( gr.Column(visible=True), # login_panel gr.Column(visible=True), # user_gate_panel gr.Column(visible=False), # junior_access_panel gr.Column(visible=False), # upload_panel "", BLANK_TEMPLATE_DF, gr.Column(visible=True), gr.Column(visible=False), gr.HTML(value=generate_view_html()), False, gr.Column(visible=False), gr.Column(visible=False), get_reviewed_table_df(), get_reviewed_table_df(), gr.update(visible=False), gr.update(visible=False), gr.update(value="Set your user in the Administrative Portal."), gr.update(value="Current user: not selected"), gr.update(value="Current user: not selected"), "", ) if not role: if not AUTH_USER or not AUTH_PASS: message = "Senior admin credentials are not configured. Public users can still create or log in as an app user below." else: message = "Invalid credentials. Access denied." common = list(common) common[4] = message return tuple(common) return ( gr.Column(visible=False), gr.Column(visible=True), gr.Column(visible=False), gr.Column(visible=False), f'{role.title()} admin authenticated. Create or log in as a user to continue.', BLANK_TEMPLATE_DF, gr.Column(visible=False), gr.Column(visible=False), gr.HTML(value=generate_view_html()), True, gr.Column(visible=False), gr.Column(visible=False), get_reviewed_table_df(), get_reviewed_table_df(), gr.update(visible=True), # PubCrawler tab available to both admin levels gr.update(visible=False), # PubCrawler term panel waits for user selection gr.update(value="Set your user in the Administrative Portal."), gr.update(value="Current user: not selected"), gr.update(value="Current user: not selected"), "", ) def upload_data_to_supabase(file_obj, species, tissue, dataset_type, request: gr.Request): session_hash = getattr(request, "session_hash", None) if not is_senior_admin(session_hash): return " Senior admin access required." if not supabase: return "Configuration Error: Supabase connection is inactive." if file_obj is None: return "Please upload a valid CSV or Excel file first." try: if file_obj.name.endswith('.csv'): uploaded_df = pd.read_csv(file_obj.name) elif file_obj.name.endswith(('.xls', '.xlsx')): uploaded_df = pd.read_excel(file_obj.name) else: return "Unsupported format. Please upload a .csv or .xlsx file." uploaded_df.columns = [c.strip() for c in uploaded_df.columns] table_name = "sra_database" if dataset_type == "SRA" else "geo_database" for target_col in EXACT_MATCH_COLUMNS: if target_col not in uploaded_df.columns: uploaded_df[target_col] = None db_ready_df = uploaded_df[EXACT_MATCH_COLUMNS].copy().dropna(subset=["Accession"]) canonical_organism = "Bos taurus" if normalize_organism(species) == "bos taurus" else species.strip() db_ready_df["Organism"] = canonical_organism db_ready_df["tissue"] = tissue.strip() db_ready_df["dataset"] = dataset_type.strip() db_ready_df = sanitize_dataframe(db_ready_df) new_records = db_ready_df.to_dict(orient="records") if not new_records: return "No rows with valid Accession numbers found." db_response = supabase.table(table_name).select("Accession,Organism,tissue").execute() existing = db_response.data if db_response.data else [] exact_keys = set() accession_only = {} for r in existing: acc = normalize_val(r.get("Accession")) org = normalize_organism(r.get("Organism", "")) tis = normalize_val(r.get("tissue", "")) exact_keys.add((acc, org, tis)) if acc not in accession_only: accession_only[acc] = [] accession_only[acc].append((r.get("Organism", ""), r.get("tissue", ""))) incoming_org_norm = normalize_organism(canonical_organism) incoming_tis_norm = normalize_val(tissue) true_dupes = [] cross_category_warnings = [] final_records = [] for r in new_records: acc = normalize_val(r.get("Accession")) key = (acc, incoming_org_norm, incoming_tis_norm) if key in exact_keys: true_dupes.append(acc) else: if acc in accession_only: for (ex_org, ex_tis) in accession_only[acc]: cross_category_warnings.append( f" • {acc} already exists as Organism='{ex_org}', Tissue='{ex_tis}'" ) final_records.append(r) msg_parts = [] if cross_category_warnings: warn_lines = "\n".join(cross_category_warnings) msg_parts.append( f" Warning — are you sure you inputted the right parameters?\n" f"The following accessions already exist in a different category:\n{warn_lines}" ) if true_dupes: msg_parts.append(f"Skipped {len(true_dupes)} exact duplicate(s) (same accession + organism + tissue).") if not final_records: msg_parts.append("No new records to insert after duplicate check.") return "\n".join(msg_parts) supabase.table(table_name).insert(final_records).execute() msg_parts.append(f" Inserted {len(final_records)} record(s) into {table_name}.") return "\n".join(msg_parts) except Exception as e: return f"Upload failed: {str(e)}" def handle_row_selection(evt: gr.SelectData, current_df): try: row_idx = evt.index[0] if "Accession" in current_df.columns: accession_id = str(current_df.iloc[row_idx].get("Accession", "")).strip() if accession_id and accession_id != "N/A": return accession_id, f"Selected: {accession_id}" return "", "Selected row has no valid Accession ID." except Exception as e: return "", f"Selection error: {str(e)}" def delete_record_from_supabase(accession_id, current_df, request: gr.Request): session_hash = getattr(request, "session_hash", None) if not is_senior_admin(session_hash): return " Senior admin access required.", current_df, accession_id if not supabase or not accession_id.strip() or accession_id == "N/A": return "No valid record selected.", current_df, accession_id try: response = supabase.table("sra_database").delete().eq("Accession", accession_id.strip()).execute() if not response.data: response = supabase.table("geo_database").delete().eq("Accession", accession_id.strip()).execute() if response.data: return f"Deleted: {accession_id}", load_entire_table(), "" return f"Record {accession_id} not found.", current_df, accession_id except Exception as e: return f"Deletion error: {str(e)}", current_df, accession_id def _df_to_html_table(df): if df is None or df.empty: return "<p style=\"color:#64748b;font-size:13px;\">No records found.</p>" cols = list(df.columns) header = "".join(f'<th style="background:#f8fafc;color:#475569;font-weight:600;font-size:12px;padding:10px 12px;border-bottom:1px solid #e2e8f0;text-align:left;white-space:nowrap;">{c}</th>' for c in cols) rows = "" for i, row in df.iterrows(): bg = "#ffffff" if i % 2 == 0 else "#f8fafc" cells = "".join(f'<td style="padding:9px 12px;font-size:12px;color:#334155;border-bottom:1px solid #f1f5f9;max-width:260px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{str(v)}</td>' for v in row) rows += f'<tr style="background:{bg};">{cells}</tr>' return f'''<div style="overflow-x:auto;border:1px solid #e2e8f0;border-radius:8px;"> <table style="width:100%;border-collapse:collapse;font-family:system-ui,sans-serif;"> <thead><tr>{header}</tr></thead> <tbody>{rows}</tbody> </table></div>''' def update_homepage_string(html_content, request: gr.Request): session_hash = getattr(request, "session_hash", None) if not is_senior_admin(session_hash): return " Senior admin access required.", generate_view_html() log_msg = save_homepage_content(html_content) return log_msg, generate_view_html() # ── Homepage Default Content ────────────────────────────────────────────────── HOMEPAGE_DEFAULT = """ <div style="font-family:'Inter',system-ui,sans-serif;color:#0f172a;max-width:900px;margin:0 auto;padding:20px 0 30px;"> <!-- Welcome Section --> <div style="text-align:center;margin-bottom:40px;background:linear-gradient(135deg,#eff6ff,#dbeafe);border-radius:16px;padding:32px 24px 28px;border:1px solid #bfdbfe;"> <h1 style="font-size:28px;font-weight:900;color:#1e3a8a;margin:0 0 8px;letter-spacing:-0.02em;"> Welcome to ReproOmics Hub </h1> <p style="font-size:18px;font-weight:600;color:#2563eb;margin:0 0 12px;"> Integrated Bioinformatics Platform for Animal Reproduction Research </p> <p style="font-size:14px;color:#475569;max-width:700px;margin:0 auto;line-height:1.7;"> ReproOmics Hub is an integrated bioinformatics platform developed to support research in <strong>Animal Reproductive Technologies (ART)</strong> with a primary focus on cattle and buffalo. The portal provides seamless access to public omics datasets, literature resources, AI-assisted analytical tools, and bioinformatics workflows to accelerate research in reproductive biology, embryo development, fertility, and livestock improvement. </p> </div> <!-- Quick Links --> <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px;"> <a href="/?__tab=1" style="text-decoration:none;background:#ffffff;border:1px solid #e2e8f0;border-radius:10px;padding:16px 18px;transition:all 0.15s;box-shadow:0 1px 3px rgba(0,0,0,0.04);display:flex;align-items:center;gap:10px;"> <span style="font-size:13px;font-weight:600;color:#0f172a;">Query Database Hub</span> </a> <a href="/?__tab=2" style="text-decoration:none;background:#ffffff;border:1px solid #e2e8f0;border-radius:10px;padding:16px 18px;transition:all 0.15s;box-shadow:0 1px 3px rgba(0,0,0,0.04);display:flex;align-items:center;gap:10px;"> <span style="font-size:13px;font-weight:600;color:#0f172a;">Literature Finder</span> </a> <a href="/?__tab=3" style="text-decoration:none;background:#ffffff;border:1px solid #e2e8f0;border-radius:10px;padding:16px 18px;transition:all 0.15s;box-shadow:0 1px 3px rgba(0,0,0,0.04);display:flex;align-items:center;gap:10px;"> <span style="font-size:13px;font-weight:600;color:#0f172a;">Literature Search (All Time)</span> </a> <a href="/?__tab=4" style="text-decoration:none;background:#ffffff;border:1px solid #e2e8f0;border-radius:10px;padding:16px 18px;transition:all 0.15s;box-shadow:0 1px 3px rgba(0,0,0,0.04);display:flex;align-items:center;gap:10px;"> <span style="font-size:13px;font-weight:600;color:#0f172a;">AI / ML Tools</span> </a> </div> </div> """ # ── Reviewed-Article helpers (kept for admin DOI box) ────────────────────────────────── _admin_active = False _reviewed_cache_by_user: dict[str, set] = {} _reviewed_link_cache_by_user: dict[str, set] = {} _supabase_reviewed_ok: bool | None = None _reviewed_schema_error = False def _check_reviewed_table(): global _supabase_reviewed_ok, _reviewed_schema_error if _supabase_reviewed_ok is not None: return _supabase_reviewed_ok if not supabase: _supabase_reviewed_ok = False return False try: supabase.table("reviewed_articles").select("doi,user").limit(1).execute() _supabase_reviewed_ok = True except Exception: _supabase_reviewed_ok = False _reviewed_schema_error = True return _supabase_reviewed_ok def _normalize_reviewed_link(link): return str(link or '').strip().rstrip('/').lower() def load_reviewed_keys(user_name=''): """Return user-specific reviewed DOI and paper-link sets.""" user_name = _normalize_app_user(user_name) dois = set() links = set() if not user_name: return dois, links if _check_reviewed_table(): try: res = ( supabase.table('reviewed_articles') .select('doi,link') .eq('user', user_name) .execute() ) for row in (res.data or []): doi = _extract_doi(row.get('doi', '')) link = _normalize_reviewed_link(row.get('link', '')) if doi: dois.add(doi) if link: links.add(link) return dois, links except Exception: pass dois.update(_reviewed_cache_by_user.get(user_name, set())) links.update(_normalize_reviewed_link(x) for x in _reviewed_link_cache_by_user.get(user_name, set())) links.discard('') return dois, links def _is_reviewed_paper(doi='', link='', user_name=''): doi_key = _extract_doi(doi) link_key = _normalize_reviewed_link(link) reviewed_dois, reviewed_links = load_reviewed_keys(user_name) return bool((doi_key and doi_key in reviewed_dois) or (link_key and link_key in reviewed_links)) def load_reviewed_dois(user_name=''): reviewed_dois, _ = load_reviewed_keys(user_name) return reviewed_dois def save_reviewed_article(article_id, user_name, paper_link=''): article_id = (article_id or '').strip().lower() user_name = _normalize_app_user(user_name) paper_link = (paper_link or '').strip() if not article_id: return 'No identifier provided' if not user_name: return 'Please select a user first.' if not _check_reviewed_table(): return 'reviewed_articles table is missing or does not have the required user column.' try: existing = ( supabase.table('reviewed_articles') .select('doi,user') .eq('doi', article_id) .eq('user', user_name) .limit(1) .execute() ) if existing.data: return 'Already marked as reviewed for this user.' payload = {'doi': article_id, 'user': user_name} if paper_link: payload['link'] = paper_link try: supabase.table('reviewed_articles').insert(payload).execute() except Exception: if paper_link: return 'Could not save the paper link. Add a link column to reviewed_articles and try again.' raise _reviewed_cache_by_user.setdefault(user_name, set()).add(article_id) return 'Marked as reviewed' except Exception: return 'Could not save the reviewed article. Check the reviewed_articles table schema and permissions.' def save_reviewed_paper_link(paper_link, user_name): """Mark a direct research-paper URL as read for the current app user.""" user_name = _normalize_app_user(user_name) paper_link = str(paper_link or '').strip() if not user_name: return 'Please select a user first.' if not paper_link: return 'Please enter a research paper link.' parsed = urllib.parse.urlparse(paper_link) if parsed.scheme.lower() not in ('http', 'https') or not parsed.netloc: return 'Please enter a valid http(s) research paper link.' doi = _extract_doi(paper_link) if doi: return save_reviewed_article(doi, user_name, paper_link) if not _check_reviewed_table(): return 'reviewed_articles table is missing or does not have the required user column.' try: existing = ( supabase.table('reviewed_articles') .select('doi,user,link') .eq('user', user_name) .eq('link', paper_link) .limit(1) .execute() ) if existing.data: return 'Already marked as reviewed for this user.' supabase.table('reviewed_articles').insert({ 'doi': None, 'user': user_name, 'link': paper_link, }).execute() _reviewed_link_cache_by_user.setdefault(user_name, set()).add(paper_link) return 'Marked as reviewed' except Exception: return 'Could not save the paper link. Add a link column to reviewed_articles and allow DOI to be blank.' def remove_reviewed_article(article_id, user_name): article_id = (article_id or '').strip().lower() user_name = _normalize_app_user(user_name) if not article_id: return 'No identifier provided' if not user_name: return 'Please select a user first.' if not _check_reviewed_table(): return 'reviewed_articles table is missing or does not have the required user column.' try: if article_id.startswith(('http://', 'https://')): supabase.table('reviewed_articles').delete().eq('link', article_id).eq('user', user_name).execute() _reviewed_link_cache_by_user.setdefault(user_name, set()).discard(article_id) else: supabase.table('reviewed_articles').delete().eq('doi', article_id).eq('user', user_name).execute() _reviewed_cache_by_user.setdefault(user_name, set()).discard(article_id) return 'Removed from reviewed' except Exception: return 'Could not remove the reviewed article. Check the reviewed_articles table schema and permissions.' def mark_article_api(doi, action, session_hash=None): if not session_hash or session_hash not in _admin_sessions: return "Admin login required. Please log in first." role = get_admin_role(session_hash) if action == "unmark" and role != "senior": return "Senior admin access required to remove reviewed articles." if role not in ("user", "junior", "senior"): return "Please create or log in as a user first." user_name = get_current_app_user(session_hash) if not user_name: return "Please create or log in as a user first." article_id = (doi or "").strip().lower() if not article_id: return "No identifier provided" if action == "mark": return save_reviewed_article(article_id, user_name) elif action == "unmark": return remove_reviewed_article(article_id, user_name) else: return "Unknown action" def list_reviewed_html(user_name=''): rows_df = get_reviewed_table_df(user_name) if rows_df.empty: return "<p style='color:#94a3b8;font-size:12px;'>No articles marked yet.</p>" html = "" for _, r in rows_df.iterrows(): article_id = str(r.get('DOI', '')) at = str(r.get('Reviewed At', '') or '')[:10] display = article_id[:80] + ('...' if len(article_id) > 80 else '') link = f"https://doi.org/{article_id}" if not article_id.startswith('http') else article_id html += ( f"<div style='display:flex;align-items:center;gap:8px;padding:5px 8px;" f"margin-bottom:5px;background:#f0fdf4;border:1px solid #86efac;" f"border-radius:6px;font-size:11px;'>" f"<a href='{link}' target='_blank' rel='noopener noreferrer' " f"style='color:#2563eb;text-decoration:none;flex:1;word-break:break-all;'>{display}</a>" + (f"<span style='color:#94a3b8;white-space:nowrap;'>{at}</span>" if at else "") + f"</div>" ) return html def manual_mark_doi(doi, request: gr.Request): """Manually mark a DOI as read for the current authenticated app user.""" if not doi or not doi.strip(): return "Please enter a valid DOI." session_hash = getattr(request, "session_hash", None) if not session_hash: return "Could not determine your session. Please reload the page and log in again." return mark_article_api(doi.strip(), "mark", session_hash) # ── Theme ───────────────────────────────────────────────────────────────────── light_theme = gr.themes.Base( primary_hue=gr.themes.colors.blue, neutral_hue=gr.themes.colors.slate, font=gr.themes.GoogleFont("Inter"), ).set( body_background_fill="#eef2f7", body_background_fill_dark="#eef2f7", body_text_color="#0f172a", body_text_color_dark="#0f172a", block_background_fill="#ffffff", block_background_fill_dark="#ffffff", block_border_color="#dde3ee", block_border_color_dark="#dde3ee", block_border_width="1px", block_label_text_color="#475569", block_label_text_color_dark="#475569", block_label_text_weight="600", block_label_text_size="13px", block_title_text_color="#0f172a", block_title_text_color_dark="#0f172a", block_title_text_weight="700", block_shadow="0 1px 3px rgba(15,23,42,.07),0 1px 2px rgba(15,23,42,.04)", input_background_fill="#ffffff", input_background_fill_dark="#ffffff", input_border_color="#dde3ee", input_border_color_dark="#dde3ee", input_border_width="1.5px", input_placeholder_color="#94a3b8", input_placeholder_color_dark="#94a3b8", input_shadow="none", input_shadow_focus="0 0 0 3px rgba(29,78,216,.13)", checkbox_background_color="#ffffff", checkbox_background_color_dark="#ffffff", checkbox_border_color="#dde3ee", checkbox_border_color_hover="#93c5fd", checkbox_border_color_selected="#1d4ed8", checkbox_background_color_selected="#1d4ed8", button_primary_background_fill="linear-gradient(135deg,#2563eb,#1d4ed8)", button_primary_background_fill_dark="linear-gradient(135deg,#2563eb,#1d4ed8)", button_primary_background_fill_hover="linear-gradient(135deg,#1d4ed8,#1e40af)", button_primary_text_color="#ffffff", button_primary_text_color_dark="#ffffff", button_primary_border_color="transparent", button_secondary_background_fill="#ffffff", button_secondary_background_fill_dark="#ffffff", button_secondary_background_fill_hover="#eff6ff", button_secondary_text_color="#475569", button_secondary_text_color_dark="#475569", button_secondary_border_color="#dde3ee", button_secondary_border_color_dark="#dde3ee", button_secondary_border_color_hover="#93c5fd", button_large_padding="10px 20px", button_small_padding="6px 14px", button_large_text_size="14px", button_small_text_size="12px", table_even_background_fill="#ffffff", table_even_background_fill_dark="#ffffff", table_odd_background_fill="#fafbfd", table_odd_background_fill_dark="#fafbfd", table_border_color="#dde3ee", table_border_color_dark="#dde3ee", border_color_primary="#dde3ee", color_accent="#1d4ed8", color_accent_soft="#eff6ff", ) css = """ /* ═══════════════════════════════════════════════════════════════ ReproOmics Hub — Design System ═══════════════════════════════════════════════════════════════ */ /* --- Reset & color-scheme ------------------------------------ */ *, *::before, *::after { color-scheme: light !important; box-sizing: border-box; } /* --- CSS Variables ------------------------------------------- */ .gradio-container { --c-bg: #eef2f7; --c-surface: #ffffff; --c-primary: #1d4ed8; --c-primary-h:#1e40af; --c-primary-l:#eff6ff; --c-primary-r:#bfdbfe; --c-accent: #7c3aed; --c-success: #059669; --c-warn: #d97706; --c-danger: #dc2626; --c-text: #0f172a; --c-text2: #475569; --c-text3: #94a3b8; --c-border: #dde3ee; --sh-sm: 0 1px 3px rgba(15,23,42,.07),0 1px 2px rgba(15,23,42,.04); --sh-md: 0 4px 14px rgba(15,23,42,.09),0 2px 4px rgba(15,23,42,.04); --sh-lg: 0 8px 28px rgba(15,23,42,.11),0 4px 8px rgba(15,23,42,.05); --r: 10px; --r-sm: 6px; --r-lg: 16px; --tr: .18s cubic-bezier(.4,0,.2,1); } /* --- Body / Root --------------------------------------------- */ .gradio-container, .gradio-container.dark, body, html { background: linear-gradient(135deg,#eef2f7 0%,#e8edf6 100%) !important; color: var(--c-text) !important; font-family: 'Inter','Segoe UI',system-ui,sans-serif !important; } /* --- Typography --------------------------------------------- */ .gradio-container h1, .gradio-container h2, .gradio-container h3, .gradio-container h4 { color: var(--c-text) !important; font-weight: 800 !important; letter-spacing: -0.02em !important; } .gradio-container label, .gradio-container .block label span, .gradio-container p, .gradio-container span { color: var(--c-text2) !important; } /* --- Inputs / Textareas ------------------------------------- */ .gradio-container input, .gradio-container textarea, .gradio-container select { background: var(--c-surface) !important; color: var(--c-text) !important; border: 1.5px solid var(--c-border) !important; border-radius: var(--r-sm) !important; transition: border-color var(--tr), box-shadow var(--tr) !important; font-size: 13px !important; } .gradio-container input:focus, .gradio-container textarea:focus { border-color: var(--c-primary) !important; box-shadow: 0 0 0 3px rgba(29,78,216,.13) !important; outline: none !important; } .gradio-container .textbox textarea { background: var(--c-surface) !important; color: var(--c-text) !important; border-color: var(--c-border) !important; } /* --- Dropdown options ---------------------------------------- */ .gradio-container .options, .gradio-container ul.options, .gradio-container [class*="options"] { background: var(--c-surface) !important; border: 1px solid var(--c-border) !important; box-shadow: var(--sh-lg) !important; border-radius: var(--r-sm) !important; } .gradio-container .options li, .gradio-container [class*="options"] li { color: var(--c-text) !important; background: var(--c-surface) !important; transition: background var(--tr) !important; font-size: 13px !important; } .gradio-container .options li:hover, .gradio-container [class*="options"] li:hover { background: var(--c-primary-l) !important; color: var(--c-primary) !important; } /* --- Radio / Checkbox ---------------------------------------- */ .gradio-container .wrap label { background: var(--c-surface) !important; border: 1.5px solid var(--c-border) !important; color: var(--c-text2) !important; border-radius: var(--r-sm) !important; transition: all var(--tr) !important; font-size: 13px !important; } .gradio-container .wrap label:hover { border-color: var(--c-primary-r) !important; background: var(--c-primary-l) !important; } .gradio-container .wrap label.selected, .gradio-container .wrap input[type="radio"]:checked + span { border-color: var(--c-primary) !important; color: var(--c-primary) !important; background: var(--c-primary-l) !important; font-weight: 700 !important; box-shadow: 0 0 0 2px rgba(29,78,216,.12) !important; } /* --- Blocks (component containers) -------------------------- */ .gradio-container .block { background: var(--c-surface) !important; border: 1px solid var(--c-border) !important; border-radius: var(--r) !important; box-shadow: var(--sh-sm) !important; transition: box-shadow var(--tr) !important; } /* Layout containers: fully transparent */ .gradio-container .gap, .gradio-container .gap > .block > .gap, .gradio-container fieldset, .gradio-container .form { background: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; } .gradio-container .gap:hover, .gradio-container .gap > .block:hover { background: transparent !important; } /* --- Tables -------------------------------------------------- */ .gradio-container table { background: var(--c-surface) !important; border-radius: var(--r) !important; overflow: hidden !important; box-shadow: var(--sh-sm) !important; border: 1px solid var(--c-border) !important; } .gradio-container table th { background: linear-gradient(to bottom,#f1f5fb,#eaeff6) !important; color: var(--c-text2) !important; border-bottom: 2px solid var(--c-border) !important; font-weight: 700 !important; font-size: 12px !important; letter-spacing: .04em !important; text-transform: uppercase !important; padding: 10px 14px !important; } .gradio-container table td { background: var(--c-surface) !important; color: var(--c-text) !important; border-bottom: 1px solid #f1f5f9 !important; padding: 9px 14px !important; font-size: 13px !important; transition: background var(--tr) !important; } .gradio-container table tr:nth-child(odd) td { background: #fafbfd !important; } .gradio-container table tr:hover td, .gradio-container table tr.hover td, .gradio-container tbody tr:hover td { background: #dbeafe !important; color: #1e40af !important; } /* --- Tabs ---------------------------------------------------- */ .gradio-container .tabs .tab-nav, div[class*="tab-nav"], .tab-nav { background: #e8edf6 !important; border-bottom: none !important; padding: 6px 10px 0 !important; gap: 3px !important; border-radius: var(--r-lg) var(--r-lg) 0 0 !important; } .gradio-container .tabs button, .gradio-container [class*="tab-nav"] button, .gradio-container [role="tab"], button[class*="tab"], div[class*="tab-nav"] button { color: var(--c-text2) !important; background: transparent !important; border: none !important; border-radius: var(--r-sm) var(--r-sm) 0 0 !important; font-weight: 500 !important; font-size: 13px !important; padding: 9px 16px !important; transition: all var(--tr) !important; letter-spacing: .01em !important; } .gradio-container .tabs button:hover, div[class*="tab-nav"] button:hover, .gradio-container [role="tab"]:hover { background: rgba(255,255,255,.7) !important; color: var(--c-text) !important; } .gradio-container .tabs button.selected, div[class*="tab-nav"] button.selected, .gradio-container [role="tab"][aria-selected="true"] { background: var(--c-surface) !important; color: var(--c-primary) !important; font-weight: 700 !important; box-shadow: 0 -2px 0 var(--c-primary) inset, var(--sh-sm) !important; } .gradio-container .tabs button.selected:hover, .gradio-container [role="tab"][aria-selected="true"]:hover { background: var(--c-surface) !important; color: var(--c-primary) !important; } /* --- Buttons ------------------------------------------------- */ .gradio-container button.primary, .gradio-container button[variant="primary"] { background: linear-gradient(135deg,#2563eb,#1d4ed8) !important; color: #fff !important; border: none !important; font-weight: 700 !important; border-radius: var(--r-sm) !important; box-shadow: 0 2px 8px rgba(29,78,216,.30) !important; transition: all var(--tr) !important; letter-spacing: .01em !important; } .gradio-container button.primary:hover { background: linear-gradient(135deg,#1d4ed8,#1e40af) !important; box-shadow: 0 4px 16px rgba(29,78,216,.40) !important; transform: translateY(-1px) !important; } .gradio-container button.primary:active { transform: translateY(0) !important; } .gradio-container button.secondary { background: var(--c-surface) !important; color: var(--c-text2) !important; border: 1.5px solid var(--c-border) !important; border-radius: var(--r-sm) !important; font-weight: 600 !important; transition: all var(--tr) !important; } .gradio-container button.secondary:hover { border-color: var(--c-primary-r) !important; color: var(--c-primary) !important; background: var(--c-primary-l) !important; } .gradio-container button.stop { background: linear-gradient(135deg,#ef4444,#dc2626) !important; color: #fff !important; border: none !important; font-weight: 700 !important; border-radius: var(--r-sm) !important; box-shadow: 0 2px 8px rgba(220,38,38,.28) !important; } /* --- Upload zone -------------------------------------------- */ .gradio-container .upload-container, .gradio-container [class*="upload"] { background: #fafbfd !important; border: 2px dashed var(--c-border) !important; border-radius: var(--r) !important; color: var(--c-text3) !important; transition: all var(--tr) !important; } .gradio-container .upload-container:hover, .gradio-container [class*="upload"]:hover { border-color: var(--c-primary) !important; background: var(--c-primary-l) !important; } /* --- Scrollbar ---------------------------------------------- */ ::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: #c7d2e8; border-radius: 99px; } ::-webkit-scrollbar-thumb:hover { background: #a0aec0; } /* --- Misc ---------------------------------------------------- */ footer { display: none !important; } #homepage-canvas-editor { color: var(--c-text) !important; background: #fafbfd !important; } /* --- Query Hub panels --------------------------------------- */ #qt-search-panel { animation: qtFadeIn .3s ease both; } #qt-results-panel { animation: qtSlideIn .38s cubic-bezier(.4,0,.2,1) both; } @keyframes qtFadeIn { from { opacity:0; transform:scale(.98); } to { opacity:1; transform:scale(1); } } @keyframes qtSlideIn { from { opacity:0; transform:translateX(32px); } to { opacity:1; transform:translateX(0); } } #qt-search-panel > div { max-width:500px !important; margin:0 auto !important; } #qt-form-inner { max-width:500px !important; } #qt-search-panel > div > div { max-width:460px !important; margin:0 auto !important; } /* --- Panel card --------------------------------------------- */ .panel-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r); padding: 22px; box-shadow: var(--sh-sm); } """ # ── Shared app-user management ──────────────────────────────────────────────── def _normalize_app_user(user_name): return ' '.join(str(user_name or '').split())[:100] def _user_gate_failure(message): return ( message, '', gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), get_reviewed_table_df(), get_reviewed_table_df(), gr.update(visible=False), gr.update(visible=False), get_pubcrawler_terms_df(''), gr.update(value='Set your user in the Administrative Portal.'), '<div style=\"padding:28px;border:1px dashed #cbd5e1;background:#ffffff;border-radius:10px;text-align:center;color:#64748b;font-family:system-ui,sans-serif;\">Set your user in the Administrative Portal.</div>', gr.update(value='Current user: not selected'), gr.update(value='Current user: not selected'), ) def _user_registry_ok(): if not supabase: return False try: supabase.table('app_users').select('name').limit(1).execute() return True except Exception: return False def _find_app_user(user_name): user_name = _normalize_app_user(user_name) if not user_name or not supabase: return None try: res = supabase.table('app_users').select('name').ilike('name', user_name).limit(1).execute() return (res.data or [None])[0] except Exception: return None def _activate_app_user_session(user_name, request, message): session_hash = getattr(request, 'session_hash', None) user_name = _normalize_app_user(user_name) if not session_hash: return _user_gate_failure('Could not identify this browser session. Refresh the page and try again.') # App users do not need an admin password. Preserve senior privileges only # when the session has separately authenticated with the senior credentials. if session_hash not in _admin_sessions: set_admin_active(session_hash, 'user') elif get_admin_role(session_hash) not in ('senior', 'user', 'junior'): set_admin_active(session_hash, 'user') set_current_app_user(session_hash, user_name) role = get_admin_role(session_hash) show_junior = role in ('user', 'junior') show_senior = role == 'senior' reviewed = get_reviewed_table_df(user_name) pubcrawler_terms = get_pubcrawler_terms_df(user_name) pubcrawler_articles = get_pubcrawler_articles_html(request, user_name) display = f'Current user: **{html_lib.escape(user_name)}**' return ( message, user_name, gr.update(visible=False), gr.update(visible=show_junior), gr.update(visible=show_senior), gr.update(visible=True), gr.update(visible=True), reviewed, reviewed, gr.update(visible=True), # pm_doi_col gr.update(visible=True), # ls_doi_col pubcrawler_terms, gr.update(value=display), pubcrawler_articles, gr.update(value=display), gr.update(value=display), ) def create_app_user(user_name, request: gr.Request): session_hash = getattr(request, 'session_hash', None) if not session_hash: return _user_gate_failure('Could not identify this browser session. Refresh the page and try again.') if session_hash not in _admin_sessions: set_admin_active(session_hash, 'user') user_name = _normalize_app_user(user_name) if not user_name: return _user_gate_failure('Enter a user name.') if not supabase: return _user_gate_failure('Supabase connection is unavailable.') if not _user_registry_ok(): return _user_gate_failure('User registry table is missing. Create the app_users table in Supabase first.') if _find_app_user(user_name): return _user_gate_failure('user already taken') try: supabase.table('app_users').insert({'name': user_name}).execute() except Exception: if _find_app_user(user_name): return _user_gate_failure('user already taken') return _user_gate_failure('Could not create user. Check the app_users table and its permissions.') return _activate_app_user_session(user_name, request, f'User created: **{html_lib.escape(user_name)}**') def login_as_app_user(user_name, request: gr.Request): session_hash = getattr(request, 'session_hash', None) if not session_hash: return _user_gate_failure('Could not identify this browser session. Refresh the page and try again.') if session_hash not in _admin_sessions: set_admin_active(session_hash, 'user') user_name = _normalize_app_user(user_name) if not user_name: return _user_gate_failure('Enter a user name.') if not supabase: return _user_gate_failure('Supabase connection is unavailable.') if not _user_registry_ok(): return _user_gate_failure('User registry table is missing. Create the app_users table in Supabase first.') existing = _find_app_user(user_name) if not existing: return _user_gate_failure('User not found. Use Create User for a new user.') canonical = _normalize_app_user(existing.get('name', user_name)) return _activate_app_user_session(canonical, request, f'Logged in as user: **{html_lib.escape(canonical)}**') # ── PubCrawler term management (per-user access) ───────────────────────────── def _pubcrawler_admin_ok(request: gr.Request): session_hash = getattr(request, 'session_hash', None) return bool(session_hash and session_hash in _admin_sessions and get_current_app_user(session_hash) and (get_admin_role(session_hash) in ('senior', 'junior', 'user'))) def _pubcrawler_current_user(request: gr.Request): session_hash = getattr(request, 'session_hash', None) return get_current_app_user(session_hash) def get_pubcrawler_terms_df(user_name=''): """Load only PubCrawler terms belonging to the supplied app user. Matching is normalized case-insensitively so records saved in an earlier session with harmless capitalization/whitespace differences still appear. """ columns = ['ID', 'Term'] user_name = _normalize_app_user(user_name) if not user_name or not supabase: return pd.DataFrame(columns=columns) try: res = ( supabase.table('pubcrawler') .select('id,term,user') .order('id', desc=True) .execute() ) wanted = user_name.casefold() rows = [] for row in (res.data or []): stored_user = _normalize_app_user(row.get('user', '')) if stored_user.casefold() == wanted: rows.append({'ID': row.get('id'), 'Term': row.get('term', '')}) return pd.DataFrame(rows, columns=columns) except Exception: return pd.DataFrame(columns=columns) def save_pubcrawler_term(user_name, term, request: gr.Request): if not _pubcrawler_admin_ok(request): return 'Admin login and user selection are required.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) user_name = _pubcrawler_current_user(request) term = ' '.join(str(term or '').split()) if not user_name: return 'Please select a user first.', get_pubcrawler_terms_df(), str(term or ''), '' if not term: return 'Enter a term before saving.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) if not supabase: return 'Supabase connection is unavailable.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) try: existing = ( supabase.table('pubcrawler') .select('id') .eq('term', term) .eq('user', user_name) .limit(1) .execute() ) if existing.data: return 'That term is already saved for this user.', get_pubcrawler_terms_df(user_name), term, get_pubcrawler_articles_html(request, user_name) supabase.table('pubcrawler').insert({'term': term, 'user': user_name}).execute() return f'Saved PubCrawler term: **{html_lib.escape(term)}**', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) except Exception as e: return f'Could not save term: {e}', get_pubcrawler_terms_df(user_name), term, get_pubcrawler_articles_html(request, user_name) def pubcrawler_row_selection(evt: gr.SelectData, current_df): try: row_idx = evt.index[0] row = current_df.iloc[row_idx] row_id = str(row.get('ID', '')).strip() term = str(row.get('Term', '')).strip() return row_id, f'Selected term: {term}' if term else 'No term selected.' except Exception as e: return '', f'Selection error: {e}' def get_pubcrawler_articles_html(request: gr.Request, user_name=''): """Search only the current user's saved PubCrawler terms across the literature sources for the past 30 days.""" if not _pubcrawler_admin_ok(request): return "<div style=\"padding:18px;border:1px solid #fecaca;background:#fef2f2;border-radius:8px;color:#b91c1c;font-size:13px;\"> Admin login required. Please log in first.</div>" user_name = _normalize_app_user(user_name) if not user_name: return "<div style=\"padding:28px;border:1px dashed #cbd5e1;background:#ffffff;border-radius:10px;text-align:center;color:#64748b;font-family:system-ui,sans-serif;\"> Enter your name and click Set User before refreshing articles.</div>" if not supabase: return "<div style=\"padding:18px;border:1px solid #fecaca;background:#fef2f2;border-radius:8px;color:#b91c1c;font-size:13px;\"> Supabase connection is unavailable.</div>" terms_df = get_pubcrawler_terms_df(user_name) terms = [] if not terms_df.empty: terms = [str(x).strip() for x in terms_df['Term'].tolist() if str(x).strip()] if not terms: return "<div style=\"padding:28px;border:1px dashed #cbd5e1;background:#ffffff;border-radius:10px;text-align:center;color:#64748b;font-family:system-ui,sans-serif;\"> No PubCrawler terms have been saved yet.</div>" since = datetime.date.today() - datetime.timedelta(days=30) since_date = since.strftime('%Y/%m/%d') since_dash = since.strftime('%Y-%m-%d') all_results = [] term_logs = [] for term in terms: source_map = { 'PubMed': lambda t=term: _fetch_pubmed(t, since_date, max_results=200), 'Europe PMC': lambda t=term: _fetch_europe_pmc(t, since_dash, max_results=200), 'CrossRef': lambda t=term: _fetch_crossref(t, since_dash, max_results=100), 'Semantic Scholar': lambda t=term: _fetch_semantic_scholar(t, since_dash, max_results=100), 'bioRxiv / medRxiv': lambda t=term: _fetch_biorxiv(t, since_dash, max_results=100), } for source_name, fetch_fn in source_map.items(): try: results, log = fetch_fn() for result in results: result = dict(result) result['_crawler_term'] = term all_results.append(result) if results: term_logs.append(f"{term}: {source_name} {len(results)}") except Exception as e: term_logs.append(f"{term}: {source_name} error") if not all_results: return f""" <div style=\"padding:28px;border:1px dashed #cbd5e1;background:#ffffff;border-radius:10px;text-align:center;color:#64748b;font-family:system-ui,sans-serif;\"> No publications matching the saved PubCrawler terms were found in the past 30 days. </div>""" # Deduplicate while retaining all saved terms that matched each article. merged = {} for r in all_results: doi = _extract_doi(r.get('doi', '')) title_key = str(r.get('title', '')).strip().lower() key = ('doi', doi.lower()) if doi else ('title', title_key[:140]) if key not in merged: merged[key] = dict(r) merged[key]['_crawler_terms'] = [r.get('_crawler_term', '')] else: hit = r.get('_crawler_term', '') if hit and hit not in merged[key]['_crawler_terms']: merged[key]['_crawler_terms'].append(hit) if not merged[key].get('doi') and doi: merged[key]['doi'] = doi results = _sort_results(list(merged.values())) reviewed_dois, reviewed_links = load_reviewed_keys(user_name) source_counts = {} for r in results: src = r.get('source', 'Unknown') source_counts[src] = source_counts.get(src, 0) + 1 count_badges = ''.join( f"<span style=\"background:#f1f5f9;color:#475569;padding:3px 9px;border-radius:9999px;font-size:11px;font-weight:600;\">{html_lib.escape(src)}: {cnt}</span>" for src, cnt in source_counts.items() ) html = f""" <div style=\"font-family:system-ui,sans-serif;\"> <div style=\"background:#f8fafc;border:1px solid #e2e8f0;border-radius:10px;padding:14px 18px;margin-bottom:16px;\"> <div style=\"display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;\"> <div style=\"font-size:14px;font-weight:700;color:#0f172a;\"> {len(results)} unique publications · past 30 days</div> <div style=\"display:flex;gap:6px;flex-wrap:wrap;\">{count_badges}</div> </div> <div style=\"font-size:11px;color:#94a3b8;margin-top:8px;\">Searching {len(terms)} saved PubCrawler term(s); duplicates merged.</div> </div> """ for r in results: title = html_lib.escape(str(r.get('title', 'Untitled'))) url = html_lib.escape(str(r.get('url', '') or '')) authors = html_lib.escape(str(r.get('authors', 'Unknown Authors'))) journal = html_lib.escape(str(r.get('journal', ''))) date = html_lib.escape(str(r.get('date', 'N/A'))) doi = _extract_doi(r.get('doi', '')) doi_esc = html_lib.escape(doi) src = html_lib.escape(str(r.get('source', 'Unknown'))) src_color = r.get('source_color', '#2563eb') src_bg = r.get('source_bg', '#eff6ff') terms_hit = r.get('_crawler_terms', []) or [] term_html = ''.join( f"<span style=\"background:#eef2ff;color:#4338ca;padding:2px 7px;border-radius:9999px;font-size:10px;font-weight:600;\">{html_lib.escape(t)}</span>" for t in terms_hit ) reviewed_badge = ( '<span style=\"background:#dcfce7;color:#15803d;padding:2px 8px;border-radius:9999px;font-size:10px;font-weight:700;\"> Read</span>' if (doi and doi in reviewed_dois) or (_normalize_reviewed_link(url) and _normalize_reviewed_link(url) in reviewed_links) else '' ) title_html = ( f'<a href=\"{url}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"font-size:14px;font-weight:700;color:#2563eb;text-decoration:none;line-height:1.5;display:block;margin-bottom:8px;\">{title}</a>' if url else f'<div style=\"font-size:14px;font-weight:700;color:#0f172a;line-height:1.5;margin-bottom:8px;\">{title}</div>' ) html += f""" <div style=\"border:1px solid #e2e8f0;border-radius:10px;padding:14px 16px;margin-bottom:10px;background:#ffffff;\"> {title_html} <div style=\"display:flex;flex-wrap:wrap;align-items:center;gap:7px;margin-bottom:7px;\"> <span style=\"background:{src_bg};color:{src_color};padding:2px 7px;border-radius:9999px;font-size:10px;font-weight:700;\">{src}</span> {reviewed_badge} {term_html} <span style=\"font-size:11px;color:#64748b;\"> {date}</span> </div> <div style=\"font-size:12px;color:#475569;line-height:1.6;\"> <strong>Authors:</strong> {authors} {f' <span style=\"color:#94a3b8;\">•</span> <em>{journal}</em>' if journal else ''} </div> {f'<div style=\"font-size:11px;color:#64748b;margin-top:5px;\">DOI: <a href=\"https://doi.org/{doi_esc}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color:#2563eb;text-decoration:none;\">{doi_esc}</a></div>' if doi else ''} </div> """ html += "</div>" return html def refresh_pubcrawler_articles(user_name, request: gr.Request): user_name = _pubcrawler_current_user(request) return get_pubcrawler_articles_html(request, user_name) def delete_pubcrawler_term(selected_id, user_name, request: gr.Request): """Delete only a selected PubCrawler term belonging to the current app user.""" user_name = _pubcrawler_current_user(request) if not _pubcrawler_admin_ok(request): return 'Admin login and user selection are required.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) if not user_name: return 'Please select a user first.', get_pubcrawler_terms_df(), '', '' if not selected_id: return 'Select a term first.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) if not supabase: return 'Supabase connection is unavailable.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) try: supabase.table('pubcrawler').delete().eq('id', int(selected_id)).eq('user', user_name).execute() return 'PubCrawler term removed.', get_pubcrawler_terms_df(user_name), '', get_pubcrawler_articles_html(request, user_name) except Exception as e: return f'Could not remove term: {e}', get_pubcrawler_terms_df(user_name), str(selected_id), get_pubcrawler_articles_html(request, user_name) # ── Layout ──────────────────────────────────────────────────────────────────── ALL_SOURCES = ['PubMed', 'Europe PMC', 'CrossRef', 'Semantic Scholar', 'bioRxiv / medRxiv'] with gr.Blocks() as demo: # ── Institute header ────────────────────────────────────────────────────── gr.HTML(""" <div style="background:#ffffff;border-bottom:2px solid #1e3a8a;margin-bottom:4px;padding:16px 32px 14px;font-family:'Segoe UI',system-ui,sans-serif;"> <div style="display:flex;align-items:center;justify-content:center;gap:40px;"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJcAAADICAIAAABqJeQMAAAQAElEQVR4AdS9B4AVRbY/fE5Vdfe9kxgYco6SMyogKApiwowRc1hX1w2GVXcNa845RxSzmCMqCioiSbLknPPkmbu7u8L36xlEVHzrfv/dt/b/aM3Wrq06dOrmqq3k+Ua2j2OhsdWi1qzRRlY2z2WwcRqitc8a6yLqs1SHaxgA3zlRnM1Wxi7ImE8VVOs64OIpjU4sZOxvHYc2kMIqrwzADstkwds5Z52ITGaerM2FWxxprVFcYnTU2iynoN7HVkbE1xf3Xlyg22hrjbKasroyq0c5kqiy0Bf6/Zz6CkmxoTawNdFBtXFSeqciaMJuNokhDIaEzWWuhHa11ZVVpNlsNCnFUbaMMGsZp0MdoHGrgx7HBlGwYRzrMZEJrdbXWkXVVcSg8FliXmTHHknGs/SCIdIzaWMNMksgZYkfOOWA6wV4qiMka4RwTMzuWxoJ+gkkogp1zcRxLpciTkdGeUuAS8yULY0yQ8jwphRAqSLEUsTaowzAWihM0UPh/AYQkwQJiCk+B36wOfd93ltEGQAOoBTNBX8xRDOmUdsYLV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C3FZw3uW30d7Xjq9LwTzU9YJf+fn6o/4K26HnXz4spHWFS3P/+MEj+PHNwnae63//ji2q/Ln2kH7sfXQ0WX7o7P1/6zPPZ2H+Z8nRa9W3FjzPYPFEG+8vEdZCGcHaX7+E3YisIKOYrkwpGutdd6Ge8YLnaYcn6//Lfz+kj36v9Lv88dfmfbyXXydH7xnsvP3+SbB/MgY15ePEvuCuH/2SLL1W1UaDE3t0LJc2bqX5haX6dCz71t+oLYC1RcPisWkd7O/HNDbctIga3X7tjTf+2jmhSyfbk5O8kbWt55/3bGv+WeD3wJhtB0cA1WAl8gc3k7pzP87AIPmuKA03h3QlWui/L6PpDMbDi7bAP28HsRWNfPN8g1tPJj6Bh/eaq1D79HdN3iBj5dhHxq6JhXWCBjLCJZbHtw9c8YirJZx8gtYpmx/qJZdz8dQx5tL/9pP32s+5nDfKgsdf1x/4trPxMwVp/UjXVEXHHCnP6Mn/vHFYLazn1UfCJj71Hz8l1Jj1q/2Rco/OkfPqD9s+Vt7PwzpKbhyqZOPAjj2P8kX5NDlRwVNx/PE65n0uZP7/A8n5ss85kK8LAAAAAElFTkSuQmCC" style="height:90px;width:auto;object-fit:contain;flex-shrink:0;" alt="ICAR Logo"/> <div style="text-align:center;min-width:200px;"> <div style="font-size:16px;font-weight:700;color:#1a6b35;margin-bottom:3px;"> भाकृअनुप-राष्ठ्रीय डेरी अनुसंधान संस्थान </div> <div style="font-size:22px;font-weight:900;color:#1e3a8a;line-height:1.2;margin-bottom:4px;"> ICAR – National Dairy Research Institute </div> <div style="font-size:12px;font-weight:600;color:#475569;letter-spacing:0.1em;margin-bottom:6px;"> KARNAL, HARYANA </div> <div style="border-top:1.5px solid #1e3a8a;margin:0 auto 6px;width:85%;"></div> <div style="font-size:11px;color:#94a3b8;letter-spacing:0.04em;"> ReproOmics Hub — Bioinformatics Hub for Animal Reproduction Research </div> </div> </div> </div> """) # ── Paper Alert ── gr.HTML(value=generate_paper_alert_html(), elem_id="paper-alert-host") # ── Shared state ── is_authenticated = gr.State(False) current_user_state = gr.State("") selected_accession = gr.State("") hidden_canvas_data = gr.Textbox(visible=False) # ── Hidden textbox for session_hash ── session_hash_state = gr.Textbox(visible=False, value="") # ── JavaScript to set session_hash_state ── gr.HTML(""" <style> #paper-alert-host { min-height:0 !important; height:0 !important; margin:0 !important; padding:0 !important; border:0 !important; background:transparent !important; } #session-hash-js-host { display:none !important; } </style> <script> (function() { if (!window.__gradioSessionHash) { window.__gradioSessionHash = (Math.random().toString(36) + Date.now().toString(36)).slice(2); } function setSessionHash() { var inputs = document.querySelectorAll('input[type="text"]'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].id && inputs[i].id.includes('session_hash_state')) { inputs[i].value = window.__gradioSessionHash; var event = new Event('input', { bubbles: true }); inputs[i].dispatchEvent(event); break; } } } setTimeout(setSessionHash, 500); })(); </script> """, elem_id="session-hash-js-host") with gr.Tabs(): # ── TAB 1: Home ──────────────────────────────────────────────────────── with gr.TabItem("Home"): with gr.Column(visible=True) as home_locked_panel: home_view_component = gr.HTML(value=generate_view_html()) gr.HTML(HOME_CONTACT_HTML) with gr.Column(visible=False) as home_editor_panel: gr.Markdown("## Homepage Canvas Editor") home_editor_component = gr.HTML(value=generate_editor_html()) with gr.Row(): save_home_btn = gr.Button(" Save Homepage", variant="primary", scale=2) home_save_status = gr.Markdown("*Click Save to write changes.*") # ── TAB 2: Query Database Hub ────────────────────────────────────────── with gr.TabItem("Query Database Hub"): with gr.Column(elem_id="qt-search-panel", visible=True) as qt_search_panel: gr.HTML(""" <div style="text-align:center;padding:28px 0 8px;font-family:'Inter',system-ui,sans-serif;"> <div style="display:inline-flex;align-items:center;justify-content:center; width:52px;height:52px;border-radius:16px; background:linear-gradient(135deg,#eff6ff,#dbeafe); box-shadow:0 4px 14px rgba(29,78,216,.18);margin-bottom:14px;"> <span style="font-size:26px;line-height:1;"></span> </div> <h2 style="font-size:20px;font-weight:800;color:#0f172a;margin:0 0 6px;letter-spacing:-.02em;"> Query Biological Records </h2> <p style="font-size:13px;color:#64748b;margin:0;max-width:360px;margin:0 auto;"> Select filters and click Search to retrieve data from GEO or SRA. </p> </div>""") with gr.Column(scale=1, min_width=300, elem_id="qt-form-inner"): species_input = gr.Dropdown(choices=["Bos taurus", "Buffalo"], label="Animal Type", value="Bos taurus") tissue_input = gr.Dropdown(choices=["Oocyte", "Blastocyst", "Sperm"], label="Tissue Type", value="Oocyte") tool_input = gr.Radio(choices=["GEO", "SRA"], label="Source Filter", value="SRA") accession_input = gr.Textbox(label="Accession Number (optional)", placeholder="e.g. SRX12345, GSM6789...") search_btn = gr.Button(" Search Records", variant="primary") with gr.Column(elem_id="qt-results-panel", visible=False) as qt_results_panel: with gr.Row(): new_search_btn = gr.Button("← New Search", variant="secondary", scale=1) gr.HTML("<div></div>", elem_id="qt-spacer") with gr.Row(): with gr.Column(scale=1, min_width=220): species_input2 = gr.Dropdown(choices=["Bos taurus", "Buffalo"], label="Animal Type", value="Bos taurus") tissue_input2 = gr.Dropdown(choices=["Oocyte", "Blastocyst", "Sperm"], label="Tissue Type", value="Oocyte") tool_input2 = gr.Radio(choices=["GEO", "SRA"], label="Source Filter", value="SRA") accession_input2 = gr.Textbox(label="Accession Number (optional)", placeholder="e.g. SRX12345, GSM6789...") search_btn2 = gr.Button(" Search Again", variant="primary") with gr.Column(scale=4): output_table = gr.Dataframe(value=BLANK_TEMPLATE_DF, interactive=False, wrap=False) with gr.Column(visible=False) as query_box_container: gr.Markdown("### Analytical Tools Launcher") query_custom_box = gr.HTML() def do_search(species, tissue, tool, accession): df = search_supabase(species, tissue, tool, accession) tools_html = generate_tools_launchpad_html(dataset_type=tool) return ( gr.Column(visible=False), gr.Column(visible=True), df, gr.Column(visible=True), gr.HTML(value=tools_html), species, tissue, tool, accession ) def do_reset(): return ( gr.Column(visible=True), gr.Column(visible=False), ) search_btn.click( fn=do_search, inputs=[species_input, tissue_input, tool_input, accession_input], outputs=[qt_search_panel, qt_results_panel, output_table, query_box_container, query_custom_box, species_input2, tissue_input2, tool_input2, accession_input2] ) search_btn2.click( fn=do_search, inputs=[species_input2, tissue_input2, tool_input2, accession_input2], outputs=[qt_search_panel, qt_results_panel, output_table, query_box_container, query_custom_box, species_input2, tissue_input2, tool_input2, accession_input2] ) new_search_btn.click( fn=do_reset, inputs=[], outputs=[qt_search_panel, qt_results_panel] ) # ── TAB 3: Literature Finder (past 6 months) ────────────────────────── with gr.TabItem("Literature Finder"): gr.HTML(""" <div style="text-align:center;padding:28px 0 8px;font-family:'Inter',system-ui,sans-serif;"> <div style="display:inline-flex;align-items:center;justify-content:center; width:52px;height:52px;border-radius:16px; background:linear-gradient(135deg,#faf5ff,#ede9fe); box-shadow:0 4px 14px rgba(124,58,237,.18);margin-bottom:14px;"> <span style="font-size:26px;line-height:1;"></span> </div> <h2 style="font-size:20px;font-weight:800;color:#0f172a;margin:0 0 6px;letter-spacing:-.02em;"> Multi-Database Literature Search </h2> <p style="font-size:13px;color:#64748b;margin:0 auto;max-width:500px;"> Past 6 months · PubMed · Europe PMC · CrossRef · Semantic Scholar · bioRxiv/medRxiv · Deduplicated &amp; sorted by date. </p> </div>""") with gr.Row(): with gr.Column(scale=1, min_width=300): pm_topic_input = gr.Textbox( label="Search Topic / Keywords", placeholder="e.g. bovine oocyte transcriptomics, blastocyst CRISPR, sperm RNA-seq..." ) pm_sources_input = gr.CheckboxGroup( choices=ALL_SOURCES, value=ALL_SOURCES, label="Databases to Search", ) gr.Markdown("### Search by DOI") pm_doi_search_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1016/j.example.2026.123456") pm_doi_search_btn = gr.Button("Search DOI", variant="secondary") pm_search_btn = gr.Button(" Search All Databases", variant="primary") # ── Source legend ── gr.HTML(""" <div style="font-family:'Inter',system-ui,sans-serif;"> <div style="font-size:10px;font-weight:800;color:#94a3b8;letter-spacing:.1em;text-transform:uppercase;margin:0 0 10px;">Database Legend</div> <div style="display:flex;flex-direction:column;gap:7px;font-size:12px;"> <div style="display:flex;align-items:center;gap:8px;"><span style="width:8px;height:8px;border-radius:50%;background:#dc2626;flex-shrink:0;display:inline-block;"></span><div><strong style="color:#0f172a;">PubMed</strong> <span style="color:#64748b;">— NCBI biomedical literature</span></div></div> <div style="display:flex;align-items:center;gap:8px;"><span style="width:8px;height:8px;border-radius:50%;background:#7c3aed;flex-shrink:0;display:inline-block;"></span><div><strong style="color:#0f172a;">Europe PMC</strong> <span style="color:#64748b;">— EBI life-science + open access</span></div></div> <div style="display:flex;align-items:center;gap:8px;"><span style="width:8px;height:8px;border-radius:50%;background:#059669;flex-shrink:0;display:inline-block;"></span><div><strong style="color:#0f172a;">CrossRef</strong> <span style="color:#64748b;">— DOI registry; broad coverage</span></div></div> <div style="display:flex;align-items:center;gap:8px;"><span style="width:8px;height:8px;border-radius:50%;background:#d97706;flex-shrink:0;display:inline-block;"></span><div><strong style="color:#0f172a;">Semantic Scholar</strong> <span style="color:#64748b;">— AI-enriched citation graph</span></div></div> <div style="display:flex;align-items:center;gap:8px;"><span style="width:8px;height:8px;border-radius:50%;background:#0891b2;flex-shrink:0;display:inline-block;"></span><div><strong style="color:#0f172a;">bioRxiv / medRxiv</strong> <span style="color:#64748b;">— Preprints</span></div></div> </div></div> """) with gr.Column(scale=3, min_width=400): pm_output_html = gr.HTML( value="<div style='color:#64748b;font-size:13px;text-align:center;padding:60px 0;border:1px dashed #e2e8f0;border-radius:8px;background:#ffffff;'>Select databases and enter a topic to begin searching…</div>" ) # ── Admin DOI box (visible only when authenticated) ── with gr.Column(scale=1, min_width=220, visible=False) as pm_doi_col: with gr.Group(): gr.HTML(""" <div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;"> <span style="font-size:18px;"></span> <h4 style="margin:0;font-size:13px;font-weight:800;color:#0f172a;">Admin — Mark DOI as Read</h4> </div> <p style="font-size:11px;color:#64748b;margin:0 0 10px;">Paste a DOI and mark it as reviewed. Stored in Supabase.</p> """) pm_doi_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1093/nar/gkac123") pm_doi_btn = gr.Button("Mark as Read", variant="primary", size="sm") pm_doi_status = gr.Markdown("") pm_search_btn.click( fn=fetch_multi_db_papers, inputs=[pm_topic_input, pm_sources_input, current_user_state], outputs=pm_output_html ) pm_doi_search_btn.click( fn=search_by_doi, inputs=[pm_doi_search_input, current_user_state], outputs=pm_output_html ) def manual_mark_doi_only(doi, user_name, request: gr.Request): return manual_mark_doi(doi, request) def manual_mark_doi_and_refresh(doi, user_name, query, selected_sources, request: gr.Request): msg = manual_mark_doi(doi, request) current_user = get_current_app_user(getattr(request, 'session_hash', None)) or _normalize_app_user(user_name) refreshed = fetch_multi_db_papers(query, selected_sources, current_user) return msg, refreshed pm_doi_btn.click( fn=manual_mark_doi_and_refresh, inputs=[pm_doi_input, current_user_state, pm_topic_input, pm_sources_input], outputs=[pm_doi_status, pm_output_html] ) # Remove all mark/review UI and JavaScript. # ── TAB 4: Literature Search (Paged, Year-Range, All-Time) ──────────── with gr.TabItem("Literature Search"): gr.HTML(""" <div style="text-align:center;padding:28px 0 8px;font-family:'Inter',system-ui,sans-serif;"> <div style="display:inline-flex;align-items:center;justify-content:center; width:52px;height:52px;border-radius:16px; background:linear-gradient(135deg,#ecfdf5,#d1fae5); box-shadow:0 4px 14px rgba(5,150,105,.18);margin-bottom:14px;"> <span style="font-size:26px;line-height:1;"></span> </div> <h2 style="font-size:20px;font-weight:800;color:#0f172a;margin:0 0 6px;letter-spacing:-.02em;"> Literature Search — All Time </h2> <p style="font-size:13px;color:#64748b;margin:0 auto;max-width:500px;"> Full year-range search across all databases. Page-by-page loading, deduplicated, newest-first. </p> </div>""") ls_state = gr.State(_ls_empty_state()) with gr.Row(): # ── Left sidebar ────────────────────────────────────────── with gr.Column(scale=1, min_width=310): ls_topic_input = gr.Textbox( label="Search Topic / Keywords", placeholder="e.g. CRISPR gene editing, bovine embryo transfer…" ) # ── Native year-range sliders (reliable Gradio state) ── ls_year_from = gr.Slider( minimum=1900, maximum=2026, value=1900, step=1, label="From year" ) ls_year_to = gr.Slider( minimum=1900, maximum=2026, value=2026, step=1, label="To year" ) ls_sources_input = gr.CheckboxGroup( choices=ALL_SOURCES, value=ALL_SOURCES, label="Databases to Search", ) ls_search_btn = gr.Button(" Search", variant="primary") gr.Markdown("### Search by DOI") ls_doi_search_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1016/j.example.2026.123456") ls_doi_search_btn = gr.Button("Search DOI", variant="secondary") gr.HTML(""" <div style="margin-top:14px;background:#f8fafc;border:1px solid #e2e8f0; border-radius:8px;padding:12px 14px;font-family:system-ui,sans-serif;"> <p style="font-size:11px;font-weight:700;color:#94a3b8;margin:0 0 8px; letter-spacing:0.06em;">DATABASE LEGEND</p> <div style="display:flex;flex-direction:column;gap:5px;font-size:11.5px;color:#334155;"> <span><span style="display:inline-block;width:9px;height:9px;border-radius:50%;background:#dc2626;margin-right:5px;"></span><strong>PubMed</strong> — NCBI biomedical literature</span> <span><span style="display:inline-block;width:9px;height:9px;border-radius:50%;background:#7c3aed;margin-right:5px;"></span><strong>Europe PMC</strong> — EBI life-science + open access</span> <span><span style="display:inline-block;width:9px;height:9px;border-radius:50%;background:#059669;margin-right:5px;"></span><strong>CrossRef</strong> — DOI registry; broad coverage</span> <span><span style="display:inline-block;width:9px;height:9px;border-radius:50%;background:#d97706;margin-right:5px;"></span><strong>Semantic Scholar</strong> — AI-enriched citation graph</span> <span><span style="display:inline-block;width:9px;height:9px;border-radius:50%;background:#0891b2;margin-right:5px;"></span><strong>bioRxiv / medRxiv</strong> — Preprints</span> </div> </div> """) # ── Results column ──────────────────────────────────────── with gr.Column(scale=3, min_width=400): ls_nav_html = gr.HTML(value="") ls_output_html = gr.HTML( value="<div style='color:#64748b;font-size:13px;text-align:center;" "padding:60px 0;border:1px dashed #e2e8f0;border-radius:8px;" "background:#ffffff;'>Enter a topic and click Search to begin…</div>" ) with gr.Row(): ls_prev_btn = gr.Button("← Prev", variant="secondary", size="sm") ls_next_btn = gr.Button("Next →", variant="primary", size="sm") # ── Admin DOI box (visible only when authenticated) ── with gr.Column(scale=1, min_width=220, visible=False) as ls_doi_col: with gr.Group(): gr.HTML(""" <div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;"> <span style="font-size:18px;"></span> <h4 style="margin:0;font-size:13px;font-weight:800;color:#0f172a;">Admin — Mark DOI as Read</h4> </div> <p style="font-size:11px;color:#64748b;margin:0 0 10px;">Paste a DOI and mark it as reviewed. Stored in Supabase.</p> """) ls_doi_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1093/nar/gkac123") ls_doi_btn = gr.Button("Mark as Read", variant="primary", size="sm") ls_doi_status = gr.Markdown("") # ── Event wiring ────────────────────────────────────────────── ls_search_btn.click( fn=ls_init_search, inputs=[ls_topic_input, ls_sources_input, ls_year_from, ls_year_to, current_user_state], outputs=[ls_output_html, ls_nav_html, ls_state], ) ls_doi_search_btn.click( fn=search_by_doi, inputs=[ls_doi_search_input, current_user_state], outputs=ls_output_html ) ls_prev_btn.click( fn=ls_prev_page, inputs=[ls_state, current_user_state], outputs=[ls_output_html, ls_nav_html, ls_state], ) ls_next_btn.click( fn=ls_next_page, inputs=[ls_state, current_user_state], outputs=[ls_output_html, ls_nav_html, ls_state], ) def ls_mark_doi_and_refresh(doi, user_name, state, request: gr.Request): # Mark the DOI for the active app user, then immediately re-render # the current Literature Search results so the Read badge appears. msg = manual_mark_doi(doi, request) current_user = get_current_app_user(getattr(request, 'session_hash', None)) or _normalize_app_user(user_name) return msg, _ls_render_page(state, current_user), _ls_render_nav(state), state ls_doi_btn.click( fn=ls_mark_doi_and_refresh, inputs=[ls_doi_input, current_user_state, ls_state], outputs=[ls_doi_status, ls_output_html, ls_nav_html, ls_state] ) # Remove all mark/review UI and JavaScript. # ── TAB 5: AI Tools Directory ────────────────────────────────────────── with gr.TabItem("AI Tools"): gr.HTML(""" <div style="text-align:center;padding:28px 0 20px;font-family:'Inter',system-ui,sans-serif;"> <div style="display:inline-flex;align-items:center;justify-content:center; width:52px;height:52px;border-radius:16px; background:linear-gradient(135deg,#fefce8,#fde68a); box-shadow:0 4px 14px rgba(217,119,6,.2);margin-bottom:14px;"> <span style="font-size:26px;line-height:1;"></span> </div> <h2 style="font-size:20px;font-weight:800;color:#0f172a;margin:0 0 6px;letter-spacing:-.02em;"> AI / ML / DL Tools </h2> <p style="font-size:13px;color:#64748b;margin:0 auto 4px;max-width:520px;"> Curated AI, Machine Learning &amp; Deep Learning tools for cattle &amp; buffalo reproduction research. Click any card to open the tool or source paper. </p> </div> <style> .ai-tools-section-title { font-size: 13px; font-weight: 800; color: #94a3b8; letter-spacing: 0.1em; text-transform: uppercase; padding: 24px 0 10px; border-bottom: 1px solid #e2e8f0; margin-bottom: 16px; } .ai-tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 8px; } .ai-tool-card { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px 18px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); transition: box-shadow 0.15s, border-color 0.15s, transform 0.12s; cursor: pointer; } .ai-tool-card:hover { box-shadow: 0 4px 16px rgba(37,99,235,0.12); border-color: #93c5fd; transform: translateY(-2px); text-decoration: none; } .ai-tool-card .card-name { font-size: 13.5px; font-weight: 700; color: #2563eb; line-height: 1.4; } .ai-tool-card .card-desc { font-size: 12px; color: #475569; line-height: 1.55; flex-grow: 1; } .ai-tool-card .card-footer { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; } .card-badge { font-size: 10.5px; font-weight: 600; padding: 2px 8px; border-radius: 9999px; white-space: nowrap; } .badge-type { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; } .badge-spp { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; } .badge-link { background: #f8fafc; color: #64748b; border: 1px solid #e2e8f0; margin-left: auto; font-size: 11px; } </style> <div style="padding: 20px 4px 0; font-family: system-ui, sans-serif;"> <div style="text-align:center; margin-bottom: 28px;"> <div style="font-size:26px; margin-bottom:6px;"></div> <h2 style="font-size:18px; font-weight:800; color:#0f172a; margin:0 0 6px;">AI / ML / DL Tools for Cattle & Buffalo Reproduction</h2> <p style="font-size:13px; color:#64748b; margin:0;">Click any card to open the source paper or tool.</p> </div> <!-- ── OOCYTE ASSESSMENT / GRADING ───────────────────────────────────── --> <div class="ai-tools-section-title"> Oocyte Assessment / Grading</div> <div class="ai-tools-grid"> <a class="ai-tool-card" href="https://pubmed.ncbi.nlm.nih.gov/37679441/" target="_blank" rel="noopener noreferrer"> <div class="card-name">DeepLabV3Plus + SqueezeNet Pipeline</div> <div class="card-desc">Combines DeepLabV3Plus segmentation with a refined SqueezeNet classifier; 96% validation accuracy for oocyte meiotic-stage classification.</div> <div class="card-footer"> <span class="card-badge badge-type">CNN Segmentation + Classification</span> <span class="card-badge badge-spp">Human</span> <span class="card-badge badge-link">Targosz et al., 2023 ↗</span> </div> </a> <a class="ai-tool-card" href="https://pubmed.ncbi.nlm.nih.gov/37271037/" target="_blank" rel="noopener noreferrer"> <div class="card-name">CNN-Based Oocyte Competence Scoring</div> <div class="card-desc">Semi-automatic CNN-based system for bovine oocyte competence, labelling images post hoc by resulting blastocyst outcomes.</div> <div class="card-footer"> <span class="card-badge badge-type">Semi-Automatic CNN</span> <span class="card-badge badge-spp">Bovine</span> <span class="card-badge badge-link">Costa et al., 2023 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.nature.com/articles/s41598-025-00001-0" target="_blank" rel="noopener noreferrer"> <div class="card-name">ML + Microfluidic Integration</div> <div class="card-desc">Multiple supervised ML models (RF, XGBoost, SVM, LightGBM, KNN, Naïve Bayes, LR) evaluated for oocyte quality prediction integrated with microfluidic chip data.</div> <div class="card-footer"> <span class="card-badge badge-type">RF · XGBoost · SVM · LightGBM</span> <span class="card-badge badge-spp">Human</span> <span class="card-badge badge-link">Sci. Reports, 2025 ↗</span> </div> </a> </div> <!-- ── EMBRYO / BLASTOCYST GRADING ───────────────────────────────────── --> <div class="ai-tools-section-title"> Embryo / Blastocyst Grading</div> <div class="ai-tools-grid"> <a class="ai-tool-card" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6308431/" target="_blank" rel="noopener noreferrer"> <div class="card-name">Blasto3Q</div> <div class="card-desc">Fully automated ANN-based bovine blastocyst grading per IETS standard (Grade 1/2/3); 76.4% accuracy; MATLAB + multiplatform web interface.</div> <div class="card-footer"> <span class="card-badge badge-type">Genetic Algorithm + ANN</span> <span class="card-badge badge-spp">Bovine</span> <span class="card-badge badge-link">PMC6308431 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.vitrolife.com/products/time-lapse-systems/idascore/" target="_blank" rel="noopener noreferrer"> <div class="card-name">iDAScore (Vitrolife)</div> <div class="card-desc">Fully automated time-lapse analysis; ranks embryos by likelihood of fetal heartbeat at day 2/3/blastocyst stage. Widely cited in bovine ET literature.</div> <div class="card-footer"> <span class="card-badge badge-type">Deep Learning · Time-Lapse</span> <span class="card-badge badge-spp">Human (cited in bovine ET)</span> <span class="card-badge badge-link">Vitrolife ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10414680/" target="_blank" rel="noopener noreferrer"> <div class="card-name">EmbryoScope / Primo Vision / Eeva</div> <div class="card-desc">Time-lapse incubation systems with integrated kinetics and cleavage-symmetry evaluation software; Primo Vision used to record bovine blastulation timing (tSB, tB).</div> <div class="card-footer"> <span class="card-badge badge-type">Built-in DL/ML + Imaging Hardware</span> <span class="card-badge badge-spp">Human · Bovine IVP</span> <span class="card-badge badge-link">PMC10414680 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.jivf.com/article/S2405-8394(25)00001-0/fulltext" target="_blank" rel="noopener noreferrer"> <div class="card-name">ML Embryo Stage / Transferability Classifier</div> <div class="card-desc">81.7% agreement with expert embryologists on developmental stage; 95.2% agreement on transferability decision.</div> <div class="card-footer"> <span class="card-badge badge-type">Multi-class ML Classifier</span> <span class="card-badge badge-spp">Bovine</span> <span class="card-badge badge-link">J. IVF-Worldwide, 2025 ↗</span> </div> </a> <a class="ai-tool-card" href="https://arxiv.org/abs/1908.09637" target="_blank" rel="noopener noreferrer"> <div class="card-name">Multi-Task DL + Dynamic Programming</div> <div class="card-desc">2D CNN per time-lapse frame with dynamic-programming post-processing enforcing monotonic cell-count progression for embryo cell-stage classification.</div> <div class="card-footer"> <span class="card-badge badge-type">CNN + Dynamic Programming</span> <span class="card-badge badge-spp">Bovine · Mouse</span> <span class="card-badge badge-link">arXiv:1908.09637 ↗</span> </div> </a> <a class="ai-tool-card" href="https://arxiv.org/abs/2502.07360" target="_blank" rel="noopener noreferrer"> <div class="card-name">Supervised Contrastive Learning Model</div> <div class="card-desc">Benchmarked on public Bovine Embryo CS dataset and NYU Mouse Embryo dataset for cell-stage classification using contrastive CNN.</div> <div class="card-footer"> <span class="card-badge badge-type">Contrastive CNN</span> <span class="card-badge badge-spp">Bovine · Mouse</span> <span class="card-badge badge-link">arXiv:2502.07360 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.nature.com/articles/s41598-025-00001-0" target="_blank" rel="noopener noreferrer"> <div class="card-name">CNN Oocyte / Embryo Scoring (Mana et al.)</div> <div class="card-desc">CNN-based scoring of 269 oocytes and 269 corresponding embryos from 104 women; preliminary high-quality embryo classification study.</div> <div class="card-footer"> <span class="card-badge badge-type">CNN</span> <span class="card-badge badge-spp">Human</span> <span class="card-badge badge-link">Sci. Reports, 2025 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.nature.com/articles/s41598-025-00001-0" target="_blank" rel="noopener noreferrer"> <div class="card-name">ML Live-Birth Prediction (Miyagi et al.)</div> <div class="card-desc">Multiple ML algorithms compared (LR, Naïve Bayes, KNN, RF, Neural Network, SVM) for predicting probability of live birth from blastocyst-stage images.</div> <div class="card-footer"> <span class="card-badge badge-type">LR · NB · KNN · RF · SVM · NN</span> <span class="card-badge badge-spp">Human</span> <span class="card-badge badge-link">Sci. Reports, 2025 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.nature.com/articles/s41598-025-00001-0" target="_blank" rel="noopener noreferrer"> <div class="card-name">AI Pregnancy-Probability Platform (Khosravi et al.)</div> <div class="card-desc">AI platform trained on embryologist-scored blastocyst images; predicted pregnancy chance 13.8–66.3% depending on blastocyst/patient factors.</div> <div class="card-footer"> <span class="card-badge badge-type">Deep Learning</span> <span class="card-badge badge-spp">Human</span> <span class="card-badge badge-link">Sci. Reports, 2025 ↗</span> </div> </a> </div> <!-- ── SPERM / SEMEN ANALYSIS ─────────────────────────────────────────── --> <div class="ai-tools-section-title"> Sperm / Semen Analysis (CASA + AI)</div> <div class="ai-tools-grid"> <a class="ai-tool-card" href="https://pubmed.ncbi.nlm.nih.gov/36244251/" target="_blank" rel="noopener noreferrer"> <div class="card-name">BGM — Open-Access CASA Software</div> <div class="card-desc">Open-access CASA software validated against commercial Hamilton-Thorne (HTM) system for cattle and buffalo sperm motility/kinematics. Most directly relevant tool for cattle + buffalo work.</div> <div class="card-footer"> <span class="card-badge badge-type">Open-Source CASA (ImageJ-based)</span> <span class="card-badge badge-spp">Cattle · Buffalo</span> <span class="card-badge badge-link">PubMed 36244251 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.researchgate.net/publication/356100000" target="_blank" rel="noopener noreferrer"> <div class="card-name">BSPMCsvm3casa</div> <div class="card-desc">SVM-based bull sperm motility classifier using three CASA kinematic parameters (VCL, VSL, LIN); outperforms prior static-threshold classification methods.</div> <div class="card-footer"> <span class="card-badge badge-type">SVM</span> <span class="card-badge badge-spp">Bovine (Bull)</span> <span class="card-badge badge-link">ResearchGate, 2021 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.researchgate.net/publication/356100001" target="_blank" rel="noopener noreferrer"> <div class="card-name">Tracking-Grid + Mean-Angle Motion Tracker</div> <div class="card-desc">Predicts position of sperm with failed detection using mean motion angle + Tracking-Grid; 5% fewer ID-switches and +15.6 MOTAL points vs Deep SORT baseline.</div> <div class="card-footer"> <span class="card-badge badge-type">Custom MOT Algorithm</span> <span class="card-badge badge-spp">Bovine (Bull)</span> <span class="card-badge badge-link">ResearchGate, 2021 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.hamiltonthorne.com/" target="_blank" rel="noopener noreferrer"> <div class="card-name">Hamilton-Thorne CASA (IVOS / HTM Series)</div> <div class="card-desc">Industry-standard CASA combining camera, microscope, and pixel-recognition software for motility/velocity/morphology evaluation across cattle and buffalo.</div> <div class="card-footer"> <span class="card-badge badge-type">Commercial CASA Hardware + Software</span> <span class="card-badge badge-spp">Cattle · Buffalo · Multi-species</span> <span class="card-badge badge-link">hamiltonthorne.com ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.biorxiv.org/content/10.1101/2025.01.01.000000" target="_blank" rel="noopener noreferrer"> <div class="card-name">DL Bovine Sperm Morphology Classifier (IFC)</div> <div class="card-desc">Deep learning morphology analysis trained on ~1.8 million imaging flow cytometry images across 6 bulls, fresh and frozen-thawed semen.</div> <div class="card-footer"> <span class="card-badge badge-type">CNN on Label-Free IFC Images</span> <span class="card-badge badge-spp">Bovine</span> <span class="card-badge badge-link">Frontiers Vet Sci, 2026 ↗</span> </div> </a> <a class="ai-tool-card" href="https://www.sciencedirect.com/search?query=AI+bull+sperm+morphology" target="_blank" rel="noopener noreferrer"> <div class="card-name">AI Bull Sperm Morphology Evaluation System</div> <div class="card-desc">AI algorithm benchmarked against manual morphology assessment in bull semen analysis; confirmed potential applicability for automated sperm morphology evaluation.</div> <div class="card-footer"> <span class="card-badge badge-type">Deep Learning Image Classifier</span> <span class="card-badge badge-spp">Bovine (Bull)</span> <span class="card-badge badge-link">ScienceDirect, 2025 ↗</span> </div> </a> </div> <div style="height: 32px;"></div> </div> """) # ── TAB 6: PubCrawler ─────────────────────────────────────────────────── # Available to both senior and junior admins after a shared app user is selected. with gr.TabItem("PubCrawler", visible=False) as pubcrawler_tab: gr.HTML(""" <div style="padding:24px 0 12px;font-family:'Inter',system-ui,sans-serif;"> <h2 style="font-size:20px;font-weight:800;color:#0f172a;margin:0 0 6px;">PubCrawler</h2> <p style="font-size:13px;color:#64748b;margin:0;max-width:680px;"> PubCrawler uses the same app user selected in the Administrative Portal. Only that user's saved terms are loaded. </p> </div>""") pubcrawler_user_display = gr.Markdown("Set your user in the Administrative Portal.") gr.HTML(""" <div style="margin:8px 0 14px;padding:10px 12px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;font-size:12px;color:#475569;"> Search additional biomedical literature directly in <a href="https://www.ncbi.nlm.nih.gov/" target="_blank" rel="noopener noreferrer" style="color:#2563eb;font-weight:600;text-decoration:none;">NCBI</a> or <a href="https://pubmed.ncbi.nlm.nih.gov/" target="_blank" rel="noopener noreferrer" style="color:#2563eb;font-weight:600;text-decoration:none;">PubMed</a>. </div> """) with gr.Column(): gr.Markdown("### Mark a Research Paper as Read") gr.Markdown("Use either a DOI or a direct research-paper link. The entry is saved only for the current app user.") with gr.Row(): with gr.Column(scale=1): pubcrawler_doi_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1093/nar/gkac123") pubcrawler_doi_btn = gr.Button("Mark DOI as Read", variant="primary") with gr.Column(scale=1): pubcrawler_link_input = gr.Textbox(label="Research Paper Link", placeholder="https://pubmed.ncbi.nlm.nih.gov/...") pubcrawler_link_btn = gr.Button("Mark Link as Read", variant="primary") pubcrawler_mark_status = gr.Markdown("") with gr.Row(): with gr.Column(scale=2, min_width=320, visible=True) as pubcrawler_term_panel: gr.Markdown("### Add a crawler term") pubcrawler_term_input = gr.Textbox( label="Term", placeholder="e.g. bovine oocyte CRISPR" ) with gr.Row(): pubcrawler_save_btn = gr.Button("Save Term", variant="primary") pubcrawler_refresh_btn = gr.Button("Refresh", variant="secondary") pubcrawler_status = gr.Markdown("") with gr.Column(scale=3, min_width=420): gr.Markdown("### Your Saved PubCrawler Terms") pubcrawler_table = gr.Dataframe( value=get_pubcrawler_terms_df(), headers=['ID', 'Term'], datatype=['number', 'str'], interactive=False, wrap=True, max_height=300, ) selected_pubcrawler_id = gr.State("") with gr.Row(): pubcrawler_delete_btn = gr.Button("Remove Selected Term", variant="stop") pubcrawler_selection_status = gr.Markdown("") gr.Markdown("### Articles Matching Your Saved Terms — Past 30 Days") with gr.Row(): pubcrawler_articles_refresh_btn = gr.Button("Refresh Articles", variant="secondary", scale=1) pubcrawler_articles_status = gr.Markdown("") pubcrawler_articles_html = gr.HTML( value="<div style='padding:28px;border:1px dashed #cbd5e1;background:#ffffff;border-radius:10px;text-align:center;color:#64748b;'>Set your user in the Administrative Portal.</div>" ) # ── TAB 6: Administrative Portal ─────────────────────────────────────── with gr.TabItem("Administrative Portal"): with gr.Column(visible=True) as login_panel: gr.Markdown("### Senior Admin Login") gr.Markdown("Optional. Ordinary users can create or log in to an app user below without an admin password.") user_box = gr.Textbox(label="Username", placeholder="Enter username...") pass_box = gr.Textbox(label="Password", type="password", placeholder="Enter password...") login_btn = gr.Button("Unlock Admin Console", variant="primary") with gr.Column(visible=True) as user_gate_panel: with gr.Row(): gr.Markdown("## Select User") user_gate_logout_btn = gr.Button("Log Out", variant="secondary") gr.Markdown("Create a new user or log in as an existing user. This user will be used for both PubCrawler terms and Mark as Read.") app_user_input = gr.Textbox(label="User", placeholder="Enter user name...") with gr.Row(): create_user_btn = gr.Button("Create User", variant="primary") login_user_btn = gr.Button("Login as User", variant="secondary") app_user_status = gr.Markdown("") with gr.Column(visible=False) as junior_access_panel: gr.Markdown("## User Tools — DOI Review") junior_current_user = gr.Markdown("Current user: not selected") gr.Markdown("Your DOI review and PubCrawler workspace. Dataset uploads, record deletion, homepage editing, and removing reviewed articles require senior admin access.") with gr.Row(): junior_doi_input = gr.Textbox(label="DOI", placeholder="e.g. 10.1093/nar/gkac123", scale=4) junior_doi_btn = gr.Button("Mark as Read", variant="primary", scale=1) junior_doi_status = gr.Markdown("") junior_logout_btn = gr.Button("Log Out", variant="secondary") gr.Markdown("### Recently Marked DOIs") junior_reviewed_table = gr.Dataframe(value=get_reviewed_table_df(), headers=['DOI', 'Reviewed At', 'User', 'Link'], datatype=['str', 'str', 'str', 'str'], interactive=False, wrap=True, max_height=320) with gr.Column(visible=False) as upload_panel: senior_current_user = gr.Markdown("Current user: not selected") with gr.Row(): gr.Markdown("## Admin Console") senior_logout_btn = gr.Button("Log Out", variant="secondary", scale=1) with gr.Row(): with gr.Column(scale=2): gr.Markdown("### Upload Records") file_input = gr.File(label="Upload CSV or Excel", file_types=[".csv", ".xlsx"]) upload_species = gr.Dropdown(choices=["Bos taurus", "Buffalo"], label="Animal Type", value="Bos taurus") upload_tissue = gr.Dropdown(choices=["Oocyte", "Blastocyst", "Sperm"], label="Tissue Type", value="Oocyte") upload_dataset = gr.Radio(choices=["GEO", "SRA"], label="Dataset Type", value="SRA") submit_btn = gr.Button("Push Records", variant="primary") gr.Markdown("---") gr.Markdown("### Delete Record") delete_btn = gr.Button("Delete Selected Row", variant="stop") status_output = gr.Textbox(label="Console Log", placeholder="Awaiting actions...") with gr.Column(scale=3): gr.Markdown("### Filter & Browse Records") admin_species = gr.Dropdown(choices=["Bos taurus", "Buffalo"], label="Animal Type", value="Bos taurus") admin_tissue = gr.Dropdown(choices=["Oocyte", "Blastocyst", "Sperm"], label="Tissue Type", value="Oocyte") admin_tool = gr.Radio(choices=["GEO", "SRA"], label="Source", value="SRA") with gr.Row(): admin_search_btn = gr.Button("Run Filter", variant="secondary") admin_reset_btn = gr.Button("Reload All", variant="secondary") gr.Markdown("### Database Table (All Records)") admin_table_view = gr.Dataframe(value=BLANK_TEMPLATE_DF, interactive=False, wrap=False) # ── Manual DOI mark as read ────────────────────── gr.Markdown("### Manual Mark as Read") gr.HTML(""" <p style="font-size:12px;color:#64748b;margin:0 0 8px;"> Paste a DOI (e.g., <code>10.1093/nar/gkac123</code>) and click the button. The article will be marked as reviewed and stored in Supabase. </p> """) with gr.Row(): manual_doi_input = gr.Textbox( label="DOI", placeholder="e.g. 10.1093/nar/gkac123", scale=4 ) manual_doi_btn = gr.Button("Mark as Read", variant="primary", scale=1) manual_doi_status = gr.Markdown("") gr.Markdown("### Marked Articles") gr.HTML("<p style='font-size:12px;color:#64748b;margin:0 0 8px;'>All DOIs currently marked as read/reviewed. Select a row, then remove it if needed.</p>") reviewed_table_view = gr.Dataframe( value=get_reviewed_table_df(), headers=['DOI', 'Reviewed At', 'User', 'Link'], datatype=['str', 'str', 'str', 'str'], interactive=False, wrap=True, max_height=320, ) selected_reviewed_doi = gr.State("") remove_reviewed_btn = gr.Button("Remove Selected Article", variant="stop") reviewed_status = gr.Markdown("") # ── Admin login and shared app-user selection ─────────────────── admin_outputs = [login_panel, user_gate_panel, junior_access_panel, upload_panel, status_output, admin_table_view, home_locked_panel, home_editor_panel, home_editor_component, is_authenticated, pm_doi_col, ls_doi_col, reviewed_table_view, junior_reviewed_table, pubcrawler_tab, pubcrawler_term_panel, pubcrawler_user_display, junior_current_user, senior_current_user, current_user_state] login_btn.click( fn=check_upload_credentials_generator, inputs=[user_box, pass_box], outputs=admin_outputs ) pass_box.submit( fn=check_upload_credentials_generator, inputs=[user_box, pass_box], outputs=admin_outputs ) user_activate_outputs = [app_user_status, current_user_state, user_gate_panel, junior_access_panel, upload_panel, pm_doi_col, ls_doi_col, reviewed_table_view, junior_reviewed_table, pubcrawler_tab, pubcrawler_term_panel, pubcrawler_table, pubcrawler_user_display, pubcrawler_articles_html, junior_current_user, senior_current_user] create_user_btn.click( fn=create_app_user, inputs=[app_user_input], outputs=user_activate_outputs ) login_user_btn.click( fn=login_as_app_user, inputs=[app_user_input], outputs=user_activate_outputs ) logout_outputs = [login_panel, user_gate_panel, junior_access_panel, upload_panel, status_output, admin_table_view, home_locked_panel, home_editor_panel, home_editor_component, is_authenticated, pm_doi_col, ls_doi_col, reviewed_table_view, junior_reviewed_table, pubcrawler_tab, pubcrawler_term_panel, pubcrawler_user_display, junior_current_user, senior_current_user, current_user_state] senior_logout_btn.click(fn=logout_admin, inputs=[], outputs=logout_outputs) junior_logout_btn.click(fn=logout_admin, inputs=[], outputs=logout_outputs) user_gate_logout_btn.click(fn=logout_admin, inputs=[], outputs=logout_outputs) # ── PubCrawler event wiring ─────────────────────────────────── pubcrawler_save_btn.click( fn=save_pubcrawler_term, inputs=[current_user_state, pubcrawler_term_input], outputs=[pubcrawler_status, pubcrawler_table, pubcrawler_term_input, pubcrawler_articles_html] ) def mark_pubcrawler_doi_and_refresh(doi, user_name, request: gr.Request): msg = manual_mark_doi(doi, request) current_user = _pubcrawler_current_user(request) reviewed = get_reviewed_table_df(current_user) return msg, get_pubcrawler_articles_html(request, current_user), reviewed, reviewed def mark_pubcrawler_link_and_refresh(paper_link, user_name, request: gr.Request): current_user = _pubcrawler_current_user(request) msg = save_reviewed_paper_link(paper_link, current_user) reviewed = get_reviewed_table_df(current_user) return msg, get_pubcrawler_articles_html(request, current_user), reviewed, reviewed pubcrawler_doi_btn.click( fn=mark_pubcrawler_doi_and_refresh, inputs=[pubcrawler_doi_input, current_user_state], outputs=[pubcrawler_mark_status, pubcrawler_articles_html, junior_reviewed_table, reviewed_table_view] ) pubcrawler_link_btn.click( fn=mark_pubcrawler_link_and_refresh, inputs=[pubcrawler_link_input, current_user_state], outputs=[pubcrawler_mark_status, pubcrawler_articles_html, junior_reviewed_table, reviewed_table_view] ) def refresh_pubcrawler_admin(user_name, request: gr.Request): current_user = get_current_app_user(getattr(request, 'session_hash', None)) return get_pubcrawler_terms_df(current_user), get_pubcrawler_articles_html(request, current_user) pubcrawler_refresh_btn.click( fn=refresh_pubcrawler_admin, inputs=[current_user_state], outputs=[pubcrawler_table, pubcrawler_articles_html] ) pubcrawler_term_input.submit( fn=save_pubcrawler_term, inputs=[current_user_state, pubcrawler_term_input], outputs=[pubcrawler_status, pubcrawler_table, pubcrawler_term_input, pubcrawler_articles_html] ) pubcrawler_table.select( fn=pubcrawler_row_selection, inputs=[pubcrawler_table], outputs=[selected_pubcrawler_id, pubcrawler_selection_status] ) pubcrawler_delete_btn.click( fn=delete_pubcrawler_term, inputs=[selected_pubcrawler_id, current_user_state], outputs=[pubcrawler_status, pubcrawler_table, selected_pubcrawler_id, pubcrawler_articles_html] ) pubcrawler_articles_refresh_btn.click( fn=refresh_pubcrawler_articles, inputs=[current_user_state], outputs=[pubcrawler_articles_html] ) save_home_btn.click( fn=update_homepage_string, inputs=[hidden_canvas_data], outputs=[home_save_status, home_view_component], js="() => { const ed = document.getElementById('homepage-canvas-editor'); return [ed ? ed.innerHTML : '']; }" ) admin_table_view.select( fn=handle_row_selection, inputs=[admin_table_view], outputs=[selected_accession, status_output] ) admin_search_btn.click( fn=admin_search_supabase, inputs=[admin_species, admin_tissue, admin_tool], outputs=admin_table_view ) admin_reset_btn.click( fn=load_entire_table, inputs=[], outputs=admin_table_view ) def post_upload_refresh(file, species, tissue, dataset): log_msg = upload_data_to_supabase(file, species, tissue, dataset) return log_msg, load_entire_table() submit_btn.click( fn=post_upload_refresh, inputs=[file_input, upload_species, upload_tissue, upload_dataset], outputs=[status_output, admin_table_view] ) delete_btn.click( fn=delete_record_from_supabase, inputs=[selected_accession, admin_table_view], outputs=[status_output, admin_table_view, selected_accession] ) # ── User DOI button ───────────────────────────────────────── def junior_mark_doi_and_refresh(doi, user_name, request: gr.Request): msg = manual_mark_doi(doi, request) current_user = get_current_app_user(getattr(request, 'session_hash', None)) return msg, get_reviewed_table_df(current_user) junior_doi_btn.click( fn=junior_mark_doi_and_refresh, inputs=[junior_doi_input, current_user_state], outputs=[junior_doi_status, junior_reviewed_table] ) # ── Manual DOI button ──────────────────────────────────────── manual_doi_btn.click( fn=manual_mark_doi_and_refresh, inputs=[manual_doi_input, current_user_state], outputs=[manual_doi_status, reviewed_table_view] ) reviewed_table_view.select( fn=reviewed_row_selection, inputs=[reviewed_table_view], outputs=[selected_reviewed_doi, reviewed_status] ) remove_reviewed_btn.click( fn=remove_selected_reviewed_doi, inputs=[selected_reviewed_doi, current_user_state], outputs=[reviewed_status, reviewed_table_view, selected_reviewed_doi] ) # ── mark_article_api REST endpoint ────────────────────────────── with gr.Row(visible=False): _api_in_doi = gr.Textbox(value="", elem_id="api-doi") _api_in_action = gr.Textbox(value="", elem_id="api-action") _api_out = gr.Textbox(value="", elem_id="api-out") _api_btn = gr.Button("api", elem_id="api-btn") _api_btn.click( fn=mark_article_api, inputs=[_api_in_doi, _api_in_action], outputs=[_api_out], api_name="mark_article_api", ) # Add parameters directly to launch() demo.launch(css=css, theme=light_theme)
import os
import gradio as gr
import pandas as pd
import numpy as np
import datetime
import urllib.parse
import urllib.request
import urllib.error
import json
import time
import re
import html as html_lib
from supabase import create_client, Client
# ── Helper: build query from terms and operators ──────────────
def build_boolean_query(term1, op1, term2, op2, term3):
"""
Build a boolean query from up to three terms with operators.
"""
terms = []
if term1 and term1.strip():
terms.append(term1.strip())
if term2 and term2.strip():
terms.append(term2.strip())
if term3 and term3.strip():
terms.append(term3.strip())
if len(terms) == 0:
return ""
if len(terms) == 1:
return terms[0]
# Build query with operators
query_parts = []
for i, t in enumerate(terms):
# Put quotes around phrases with spaces
if ' ' in t and not (t.startswith('"') and t.endswith('"')):
t = f'"{t}"'
query_parts.append(t)
# Insert operators between terms
if len(query_parts) == 2:
return f"{query_parts[0]} {op1} {query_parts[1]}"
else:
return f"{query_parts[0]} {op1} {query_parts[1]} {op2} {query_parts[2]}"
def normalize_boolean_query(query: str) -> str:
"""
Replace lowercase 'and' and 'or' with uppercase operators.
"""
if not query:
return query
pattern_and = re.compile(r'(?<!\w)and(?!\w)', re.IGNORECASE)
pattern_or = re.compile(r'(?<!\w)or(?!\w)', re.IGNORECASE)
query = pattern_and.sub('AND', query)
query = pattern_or.sub('OR', query)
return query
def _is_boolean_query(query: str) -> bool:
"""Return True if query contains AND or OR operators."""
q = normalize_boolean_query(query)
return ' AND ' in q or ' OR ' in q
# ── Admin authentication using session tracking ──────────────────
_admin_sessions = {} # session_id -> timestamp
_admin_roles = {} # session_id -> "senior" or "junior"
_admin_users = {} # session_id -> current app user name
def set_admin_active(session_id, role="senior"):
if session_id:
_admin_sessions[session_id] = time.time()
_admin_roles[session_id] = role
return True
def is_admin_active(session_id):
return session_id in _admin_sessions
def get_admin_role(session_id):
return _admin_roles.get(session_id)
def is_senior_admin(session_id):
return get_admin_role(session_id) == "senior"
def is_junior_admin(session_id):
return get_admin_role(session_id) == "junior"
def set_current_app_user(session_id, user_name):
if session_id:
_admin_users[session_id] = _normalize_app_user(user_name)
def get_current_app_user(session_id):
return _normalize_app_user(_admin_users.get(session_id, ""))
def clear_current_app_user(session_id):
if session_id:
_admin_users.pop(session_id, None)