Spaces:
Sleeping
Sleeping
prompt edits
Browse files- backend/main.py +52 -17
backend/main.py
CHANGED
|
@@ -40,50 +40,85 @@ GROQ_MODEL = "llama-3.3-70b-versatile"
|
|
| 40 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
| 41 |
|
| 42 |
# ββ Prompts βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 43 |
-
EXTRACTION_SYSTEM = """Extract protocol parameters from this research paper. Return ONLY valid JSON:
|
| 44 |
{
|
| 45 |
"title": "paper title",
|
| 46 |
"authors": "first author et al.",
|
| 47 |
"year": "year",
|
| 48 |
-
"protocol_type": "e.g.
|
| 49 |
"parameters": {
|
| 50 |
-
"reagents": [{"name": "...", "concentration": "...", "vendor": "..."}],
|
| 51 |
-
"cell_lines": [{"name": "...", "culture_conditions": "...", "serum": "..."}],
|
| 52 |
"temperatures": [{"step": "...", "value": "...", "unit": "C"}],
|
| 53 |
-
"timings": [{"step": "...", "duration": "..."}],
|
| 54 |
-
"equipment": [{"name": "...", "settings": "..."}],
|
| 55 |
"buffers": [{"name": "...", "composition": "...", "pH": "..."}],
|
| 56 |
"antibodies": [{"target": "...", "dilution": "...", "vendor": "..."}],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
"other": [{"parameter": "...", "value": "..."}]
|
| 58 |
}
|
| 59 |
-
}
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
{
|
| 65 |
"protocol_type": "detected protocol type",
|
| 66 |
"contradictions": [
|
| 67 |
{
|
| 68 |
"parameter": "parameter name",
|
| 69 |
-
"category": "reagents|cell_lines|temperatures|timings|equipment|buffers|
|
| 70 |
"severity": "high|medium|low",
|
| 71 |
-
"values": {"paper_0": "value from paper 1", "paper_1": "value from paper 2"},
|
| 72 |
-
"explanation": "
|
| 73 |
}
|
| 74 |
],
|
| 75 |
"ranked_issues": [
|
| 76 |
-
{"rank": 1, "parameter": "...", "severity": "high|medium|low", "brief": "one-sentence impact"}
|
| 77 |
],
|
| 78 |
"optimal_protocol": {
|
| 79 |
"rationale": "overall recommendation rationale",
|
| 80 |
"parameters": [
|
| 81 |
-
{"label": "parameter name", "value": "recommended value", "reason": "why this is optimal"}
|
| 82 |
]
|
| 83 |
},
|
| 84 |
"summary": {"total_contradictions": 0, "high": 0, "medium": 0, "low": 0}
|
| 85 |
-
}
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# ββ Core helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 88 |
|
| 89 |
def extract_text_from_pdf(pdf_path: str) -> str:
|
|
|
|
| 40 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
| 41 |
|
| 42 |
# ββ Prompts βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 43 |
+
EXTRACTION_SYSTEM = """You are an expert bioengineering methodologist. Extract ALL experimental protocol parameters from this research paper with maximum specificity. Return ONLY valid JSON:
|
| 44 |
{
|
| 45 |
"title": "paper title",
|
| 46 |
"authors": "first author et al.",
|
| 47 |
"year": "year",
|
| 48 |
+
"protocol_type": "e.g. CRISPR screen / lentivirus production / protein purification",
|
| 49 |
"parameters": {
|
| 50 |
+
"reagents": [{"name": "...", "concentration": "...", "volume": "...", "vendor": "...", "catalog": "..."}],
|
| 51 |
+
"cell_lines": [{"name": "...", "subtype": "e.g. HEK293 vs HEK293T", "culture_conditions": "...", "serum": "...", "passage": "...", "density_seeding": "..."}],
|
| 52 |
"temperatures": [{"step": "...", "value": "...", "unit": "C"}],
|
| 53 |
+
"timings": [{"step": "...", "duration": "...", "timepoint": "..."}],
|
| 54 |
+
"equipment": [{"name": "...", "settings": "...", "speed": "...", "duration": "..."}],
|
| 55 |
"buffers": [{"name": "...", "composition": "...", "pH": "..."}],
|
| 56 |
"antibodies": [{"target": "...", "dilution": "...", "vendor": "..."}],
|
| 57 |
+
"viral_production": [{"parameter": "...", "value": "...", "notes": "..."}],
|
| 58 |
+
"transfection": [{"reagent": "...", "ratio": "...", "volume": "...", "timing": "..."}],
|
| 59 |
+
"selection": [{"agent": "...", "concentration": "...", "duration": "..."}],
|
| 60 |
+
"moi": [{"value": "...", "cell_line": "...", "context": "..."}],
|
| 61 |
+
"library_coverage": [{"cells_per_sgrna": "...", "total_cells": "...", "replicates": "..."}],
|
| 62 |
+
"analysis_pipeline": [{"tool": "...", "version": "...", "parameters": "...", "statistical_model": "..."}],
|
| 63 |
+
"packaging_system": [{"generation": "2nd or 3rd", "plasmids": "...", "ratios": "...", "promoter": "..."}],
|
| 64 |
+
"centrifugation": [{"step": "...", "speed": "...", "duration": "...", "temperature": "..."}],
|
| 65 |
"other": [{"parameter": "...", "value": "..."}]
|
| 66 |
}
|
| 67 |
+
}
|
| 68 |
|
| 69 |
+
IMPORTANT RULES:
|
| 70 |
+
- If a value is not stated, write "Not specified" β never omit the field
|
| 71 |
+
- Extract exact numerical values (e.g. "0.3 MOI", "500 cells/sgRNA", "72h") not vague descriptions
|
| 72 |
+
- For cell lines, always note whether it is HEK293 or HEK293T β these are biologically distinct
|
| 73 |
+
- For lentivirus production, extract packaging plasmid names, ratios, and generation (2nd vs 3rd)
|
| 74 |
+
- For CRISPR screens, always look for: MOI, library coverage, selection agent/duration, readout method, analysis software
|
| 75 |
+
- For protein expression, always look for: induction conditions (IPTG concentration, OD600, temperature), purification steps, elution conditions"""
|
| 76 |
+
|
| 77 |
+
COMPARISON_SYSTEM = """You are a senior peer reviewer specializing in bioengineering reproducibility.
|
| 78 |
+
Your job is to identify ALL methodological contradictions between protocols β including subtle ones most researchers miss.
|
| 79 |
+
|
| 80 |
+
Return ONLY valid JSON (no markdown, no extra text):
|
| 81 |
{
|
| 82 |
"protocol_type": "detected protocol type",
|
| 83 |
"contradictions": [
|
| 84 |
{
|
| 85 |
"parameter": "parameter name",
|
| 86 |
+
"category": "reagents|cell_lines|temperatures|timings|equipment|buffers|viral_production|transfection|selection|moi|library_coverage|analysis_pipeline|packaging_system|centrifugation|other",
|
| 87 |
"severity": "high|medium|low",
|
| 88 |
+
"values": {"paper_0": "exact value from paper 1", "paper_1": "exact value from paper 2"},
|
| 89 |
+
"explanation": "specific biological mechanism by which this difference affects reproducibility β cite exact parameter values, not vague descriptions"
|
| 90 |
}
|
| 91 |
],
|
| 92 |
"ranked_issues": [
|
| 93 |
+
{"rank": 1, "parameter": "...", "severity": "high|medium|low", "brief": "one-sentence mechanistic impact β must mention specific values"}
|
| 94 |
],
|
| 95 |
"optimal_protocol": {
|
| 96 |
"rationale": "overall recommendation rationale",
|
| 97 |
"parameters": [
|
| 98 |
+
{"label": "parameter name", "value": "recommended value", "reason": "cite evidence from papers or established literature for why this value is optimal"}
|
| 99 |
]
|
| 100 |
},
|
| 101 |
"summary": {"total_contradictions": 0, "high": 0, "medium": 0, "low": 0}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
SEVERITY RULES:
|
| 105 |
+
- HIGH: affects primary experimental outcome (e.g. MOI determines single vs multiple sgRNA integration; HEK293 vs HEK293T affects viral titer 3-10x; selection duration creates fitness bias)
|
| 106 |
+
- MEDIUM: affects data quality or efficiency (e.g. library coverage affects statistical power; packaging ratios affect titer)
|
| 107 |
+
- LOW: minor procedural difference unlikely to change conclusions
|
| 108 |
+
|
| 109 |
+
CRITICAL CHECKS β always look for these specific contradictions:
|
| 110 |
+
1. HEK293 vs HEK293T (SV40 T antigen affects transfection efficiency and episomal replication)
|
| 111 |
+
2. MOI values β flag if one paper uses <0.5 (single integration) vs β₯0.5 (multiple integrations)
|
| 112 |
+
3. Library coverage β flag if cells/sgRNA differ by more than 2x
|
| 113 |
+
4. Selection duration β longer selection introduces fitness bias toward fast-growing cells
|
| 114 |
+
5. Antibiotic concentration differences (e.g. puromycin 1 vs 2 Β΅g/mL)
|
| 115 |
+
6. 2nd vs 3rd generation lentiviral packaging (biosafety and titer implications)
|
| 116 |
+
7. Analysis pipeline (casTLE vs MAGeCK vs BAGEL use different statistical models β hits may not overlap)
|
| 117 |
+
8. Viral collection timepoints (36h+60h dual collection vs single 72h β affects titer and tropism)
|
| 118 |
+
9. Centrifugation concentration vs filter-only (ultracentrifugation vs 0.45Β΅m filter)
|
| 119 |
+
10. Promoter differences (CMV vs EF1a vs PGK β expression level and cell-type specificity differ)
|
| 120 |
+
|
| 121 |
+
DO NOT flag as a contradiction: parameters where both papers say "Not specified" β these are shared gaps, not contradictions. Flag them separately as reproducibility gaps only if they are critical parameters."""
|
| 122 |
# ββ Core helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 123 |
|
| 124 |
def extract_text_from_pdf(pdf_path: str) -> str:
|