Spaces:
Sleeping
Sleeping
Commit
Β·
00efb7c
1
Parent(s):
08a5a31
add example
Browse files
app.py
CHANGED
|
@@ -26,6 +26,43 @@ queue_manager = QueueManager(max_concurrent=3)
|
|
| 26 |
# Progress tracking
|
| 27 |
progress_store = {}
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def update_progress(request_id: str, stage: str, progress: float, message: str):
|
| 30 |
"""Update progress for a request"""
|
| 31 |
progress_store[request_id] = {
|
|
@@ -198,12 +235,31 @@ def check_progress_ui(request_id: str) -> str:
|
|
| 198 |
return json.dumps(progress_store[request_id], indent=2)
|
| 199 |
return json.dumps({"error": "Request ID not found"}, indent=2)
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
# Build Gradio Interface
|
| 202 |
with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft()) as demo:
|
| 203 |
gr.Markdown("""
|
| 204 |
# π¬ Automated Consensus Analysis API
|
| 205 |
|
| 206 |
This API provides automated peer review consensus analysis using LLMs and search-augmented verification.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
""")
|
| 208 |
|
| 209 |
with gr.Tabs():
|
|
@@ -212,16 +268,40 @@ with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft())
|
|
| 212 |
gr.Markdown("### Run the complete analysis pipeline")
|
| 213 |
with gr.Row():
|
| 214 |
with gr.Column():
|
| 215 |
-
full_title = gr.Textbox(
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
full_reviews = gr.Code(
|
| 218 |
label="Reviews (JSON Array)",
|
| 219 |
language="json",
|
| 220 |
-
value='["Review 1 text...", "Review 2 text..."]'
|
|
|
|
| 221 |
)
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
with gr.Column():
|
| 224 |
-
full_output = gr.Code(label="Results", language="json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
full_submit.click(
|
| 227 |
fn=run_full_pipeline_ui,
|
|
@@ -232,9 +312,25 @@ with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft())
|
|
| 232 |
# Individual Stages
|
| 233 |
with gr.Tab("π Critique Extraction"):
|
| 234 |
gr.Markdown("### Extract critique points from reviews")
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
critique_submit.click(
|
| 240 |
fn=run_critique_extraction_ui,
|
|
@@ -243,10 +339,16 @@ with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft())
|
|
| 243 |
)
|
| 244 |
|
| 245 |
with gr.Tab("β‘ Disagreement Detection"):
|
| 246 |
-
gr.Markdown("### Detect disagreements")
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
disagree_submit.click(
|
| 252 |
fn=run_disagreement_detection_ui,
|
|
@@ -255,15 +357,21 @@ with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft())
|
|
| 255 |
)
|
| 256 |
|
| 257 |
with gr.Tab("π Search & Retrieval"):
|
| 258 |
-
gr.Markdown("### Search for evidence")
|
|
|
|
|
|
|
| 259 |
with gr.Row():
|
| 260 |
with gr.Column():
|
| 261 |
-
search_title = gr.Textbox(label="Paper Title")
|
| 262 |
-
search_abstract = gr.Textbox(label="Paper Abstract", lines=
|
| 263 |
-
search_critiques = gr.Code(
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
with gr.Column():
|
| 266 |
-
search_output = gr.Code(label="Search Results", language="json")
|
| 267 |
|
| 268 |
search_submit.click(
|
| 269 |
fn=run_search_retrieval_ui,
|
|
@@ -272,7 +380,75 @@ with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft())
|
|
| 272 |
)
|
| 273 |
|
| 274 |
with gr.Tab("π API Documentation"):
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
# Launch the app
|
| 278 |
if __name__ == "__main__":
|
|
|
|
| 26 |
# Progress tracking
|
| 27 |
progress_store = {}
|
| 28 |
|
| 29 |
+
# Example data for quick testing
|
| 30 |
+
EXAMPLE_PAPER_TITLE = "Learning Disentangled Representations for CounterFactual Regression"
|
| 31 |
+
|
| 32 |
+
EXAMPLE_PAPER_ABSTRACT = """We consider the challenge of estimating treatment effects from observational data; and point out that, in general, only some factors based on the observed covariates X contribute to selection of the treatment T, and only some to determining the outcomes Y. We model this by considering three underlying sources of {X, T, Y} and show that explicitly modeling these sources offers great insight to guide designing models that better handle selection bias. This paper is an attempt to conceptualize this line of thought and provide a path to explore it further.
|
| 33 |
+
In this work, we propose an algorithm to (1) identify disentangled representations of the above-mentioned underlying factors from any given observational dataset D and (2) leverage this knowledge to reduce, as well as account for, the negative impact of selection bias on estimating the treatment effects from D. Our empirical results show that the proposed method achieves state-of-the-art performance in both individual and population based evaluation measures."""
|
| 34 |
+
|
| 35 |
+
EXAMPLE_REVIEWS = [
|
| 36 |
+
"""Summary:
|
| 37 |
+
The authors consider the problem of estimating average treatment effects when observed X and treatment T causes Y. Observational data for X,T,Y is available and strong ignorability is assumed. Previous work (Shalit et al 2017) introduced learning a representation that is invariant in distribution across treatment and control groups and using that with treatment to estimate Y. However, authors point out that this representation being forced to be invariant still does not drive the selection bias to zero. A follow up work (Hassanpour and Greiner 2019) - corrects for this by using additional importance weighting that estimates the treatment selection bias given the learnt representation. However, the authors point out even this is not complete in general, as X could be determined by three latent factors, one that is the actual confounder between treatment and outcome and the other that affects only the outcome and the other that affects only the treatment. Therefore, the authors propose to have three representations and enforce independence between representation that solely determines outcome and the treatment and make other appropriate terms depend on the respective latent factors. This gives a modified objective with respect to these two prior works.
|
| 38 |
+
|
| 39 |
+
The authors implement optimize this joint system on synthetic and real world datasets. They show that they outperform all these previous works because of explicitly accounting for confounder, latent factors that solely control only outcome and treatment assignment respectively.
|
| 40 |
+
|
| 41 |
+
Pros:
|
| 42 |
+
This paper directly addresses the problems due to Shalit 2017 that are still left open. The experimental results seems convincing on standard benchmarks.
|
| 43 |
+
|
| 44 |
+
I vote for accepting the paper. I don't have many concerns about this paper.
|
| 45 |
+
|
| 46 |
+
Cons:
|
| 47 |
+
- I have one question for the authors - if T and Y(0),Y(1) are independent given X is assumed, then how are we sure that the composite representations (of the three latent factors) are going to necessarily satisfy ignorability provably ?? I guess this cannot be formally established. It would be great for the authors to comment on this.""",
|
| 48 |
+
|
| 49 |
+
"""The paper proposes a new way of estimating treatment effects from observational data, that decouples (disentangles) the observed covariates X into three sets: covariates that contributed to the selection of the treatment T, covariates that cause the outcome Y and covariates that do both. The authors show that by leveraging this additional structure they can improve upon existing methods in both ITE and ATE
|
| 50 |
+
|
| 51 |
+
The main contributions of the paper are:
|
| 52 |
+
* Highlighting the importance of differentiating between treatment and outcome inducing factors and proposing an algorithm to detect the two
|
| 53 |
+
* Creating a joint optimisation model that contains the factual loss, the cross entropy (treatment) loss and the imbalance loss
|
| 54 |
+
|
| 55 |
+
Overall, I like the paper quite a lot, I find it well-written and clearly motivated with a very nice experimental section that it is designed around understanding the behaviour of the proposed model.
|
| 56 |
+
|
| 57 |
+
In terms of suggestions, I think it will be very interesting to link the approaches using invariant causal representations with existing work in the Counterfactual Risk Minimization [1] literature and to mutualise the experimental setup.
|
| 58 |
+
|
| 59 |
+
[1] Swaminathan, Adith, and Thorsten Joachims. "Counterfactual risk minimization: Learning from logged bandit feedback." International Conference on Machine Learning. 2015.""",
|
| 60 |
+
|
| 61 |
+
"""The paper proposes an algorithm that identifies disentangled representation to find out an individual treatment effect. A very specific model that tries to find out the underlying dynamics of such a problem is proposed and is learned by minimizing a suggested objective that takes the strengths of previous approaches. The method is demonstrated in a synthetic dataset and IHDP dataset and shown to outperform other previous methods by a large margin.
|
| 62 |
+
|
| 63 |
+
My initial review was negative, but I changed my mind after reading a few papers in this area. It seems that explicit learning of underlying factors that are described in (Hassanpour & Greiner, 2019) is a nice idea and works well. My only concern is that the paper has a lot of overlap with (Hassanpour & Greiner, 2019), even using identical figures. I am not sure whether it is OK."""
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
def update_progress(request_id: str, stage: str, progress: float, message: str):
|
| 67 |
"""Update progress for a request"""
|
| 68 |
progress_store[request_id] = {
|
|
|
|
| 235 |
return json.dumps(progress_store[request_id], indent=2)
|
| 236 |
return json.dumps({"error": "Request ID not found"}, indent=2)
|
| 237 |
|
| 238 |
+
def load_example():
|
| 239 |
+
"""Load example paper and reviews into the form"""
|
| 240 |
+
return (
|
| 241 |
+
EXAMPLE_PAPER_TITLE,
|
| 242 |
+
EXAMPLE_PAPER_ABSTRACT,
|
| 243 |
+
json.dumps(EXAMPLE_REVIEWS, indent=2)
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
def load_example_critiques():
|
| 247 |
+
"""Load example reviews for critique extraction"""
|
| 248 |
+
return json.dumps(EXAMPLE_REVIEWS, indent=2)
|
| 249 |
+
|
| 250 |
# Build Gradio Interface
|
| 251 |
with gr.Blocks(title="Automated Consensus Analysis API", theme=gr.themes.Soft()) as demo:
|
| 252 |
gr.Markdown("""
|
| 253 |
# π¬ Automated Consensus Analysis API
|
| 254 |
|
| 255 |
This API provides automated peer review consensus analysis using LLMs and search-augmented verification.
|
| 256 |
+
|
| 257 |
+
**Pipeline stages:**
|
| 258 |
+
1. π **Critique Extraction** - Extract structured critique points from reviews (Gemini)
|
| 259 |
+
2. β‘ **Disagreement Detection** - Identify conflicts between reviewers
|
| 260 |
+
3. π **Search & Retrieval** - Find supporting evidence from academic sources
|
| 261 |
+
4. π§ **Disagreement Resolution** - AI-powered resolution with reasoning (DeepSeek-R1)
|
| 262 |
+
5. π **Meta-Review Generation** - Comprehensive synthesis of all analyses
|
| 263 |
""")
|
| 264 |
|
| 265 |
with gr.Tabs():
|
|
|
|
| 268 |
gr.Markdown("### Run the complete analysis pipeline")
|
| 269 |
with gr.Row():
|
| 270 |
with gr.Column():
|
| 271 |
+
full_title = gr.Textbox(
|
| 272 |
+
label="Paper Title",
|
| 273 |
+
placeholder="Enter paper title...",
|
| 274 |
+
lines=2
|
| 275 |
+
)
|
| 276 |
+
full_abstract = gr.Textbox(
|
| 277 |
+
label="Paper Abstract",
|
| 278 |
+
lines=8,
|
| 279 |
+
placeholder="Enter paper abstract..."
|
| 280 |
+
)
|
| 281 |
full_reviews = gr.Code(
|
| 282 |
label="Reviews (JSON Array)",
|
| 283 |
language="json",
|
| 284 |
+
value='["Review 1 text...", "Review 2 text..."]',
|
| 285 |
+
lines=15
|
| 286 |
)
|
| 287 |
+
|
| 288 |
+
with gr.Row():
|
| 289 |
+
load_example_btn = gr.Button("π₯ Load Example", variant="secondary")
|
| 290 |
+
full_submit = gr.Button("π Run Full Pipeline", variant="primary")
|
| 291 |
+
|
| 292 |
+
gr.Markdown("""
|
| 293 |
+
π‘ **Tip:** Click "Load Example" to populate the form with a sample ICLR 2020 paper
|
| 294 |
+
on Counterfactual Regression with 3 peer reviews.
|
| 295 |
+
""")
|
| 296 |
+
|
| 297 |
with gr.Column():
|
| 298 |
+
full_output = gr.Code(label="Results", language="json", lines=30)
|
| 299 |
+
|
| 300 |
+
load_example_btn.click(
|
| 301 |
+
fn=load_example,
|
| 302 |
+
inputs=[],
|
| 303 |
+
outputs=[full_title, full_abstract, full_reviews]
|
| 304 |
+
)
|
| 305 |
|
| 306 |
full_submit.click(
|
| 307 |
fn=run_full_pipeline_ui,
|
|
|
|
| 312 |
# Individual Stages
|
| 313 |
with gr.Tab("π Critique Extraction"):
|
| 314 |
gr.Markdown("### Extract critique points from reviews")
|
| 315 |
+
gr.Markdown("Extract structured critique points categorized by: Methodology, Experiments, Clarity, Significance, Novelty")
|
| 316 |
+
|
| 317 |
+
critique_reviews = gr.Code(
|
| 318 |
+
label="Reviews (JSON Array)",
|
| 319 |
+
language="json",
|
| 320 |
+
lines=15
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
with gr.Row():
|
| 324 |
+
load_critique_example_btn = gr.Button("π₯ Load Example", variant="secondary")
|
| 325 |
+
critique_submit = gr.Button("Extract Critiques", variant="primary")
|
| 326 |
+
|
| 327 |
+
critique_output = gr.Code(label="Extracted Critiques", language="json", lines=20)
|
| 328 |
+
|
| 329 |
+
load_critique_example_btn.click(
|
| 330 |
+
fn=load_example_critiques,
|
| 331 |
+
inputs=[],
|
| 332 |
+
outputs=critique_reviews
|
| 333 |
+
)
|
| 334 |
|
| 335 |
critique_submit.click(
|
| 336 |
fn=run_critique_extraction_ui,
|
|
|
|
| 339 |
)
|
| 340 |
|
| 341 |
with gr.Tab("β‘ Disagreement Detection"):
|
| 342 |
+
gr.Markdown("### Detect disagreements between reviewers")
|
| 343 |
+
gr.Markdown("Compares critique points from multiple reviews and identifies conflicts with disagreement scores (0-1).")
|
| 344 |
+
|
| 345 |
+
disagree_critiques = gr.Code(
|
| 346 |
+
label="Critique Points (JSON) - Output from Critique Extraction",
|
| 347 |
+
language="json",
|
| 348 |
+
lines=15
|
| 349 |
+
)
|
| 350 |
+
disagree_submit = gr.Button("Detect Disagreements", variant="primary")
|
| 351 |
+
disagree_output = gr.Code(label="Disagreement Analysis", language="json", lines=20)
|
| 352 |
|
| 353 |
disagree_submit.click(
|
| 354 |
fn=run_disagreement_detection_ui,
|
|
|
|
| 357 |
)
|
| 358 |
|
| 359 |
with gr.Tab("π Search & Retrieval"):
|
| 360 |
+
gr.Markdown("### Search for supporting evidence")
|
| 361 |
+
gr.Markdown("Searches Semantic Scholar, arXiv, and Tavily for state-of-the-art research and evidence to validate critiques.")
|
| 362 |
+
|
| 363 |
with gr.Row():
|
| 364 |
with gr.Column():
|
| 365 |
+
search_title = gr.Textbox(label="Paper Title", lines=2)
|
| 366 |
+
search_abstract = gr.Textbox(label="Paper Abstract", lines=5)
|
| 367 |
+
search_critiques = gr.Code(
|
| 368 |
+
label="Critiques (JSON) - Output from Critique Extraction",
|
| 369 |
+
language="json",
|
| 370 |
+
lines=10
|
| 371 |
+
)
|
| 372 |
+
search_submit = gr.Button("Search Evidence", variant="primary")
|
| 373 |
with gr.Column():
|
| 374 |
+
search_output = gr.Code(label="Search Results", language="json", lines=25)
|
| 375 |
|
| 376 |
search_submit.click(
|
| 377 |
fn=run_search_retrieval_ui,
|
|
|
|
| 380 |
)
|
| 381 |
|
| 382 |
with gr.Tab("π API Documentation"):
|
| 383 |
+
gr.Markdown("""
|
| 384 |
+
## API Endpoints
|
| 385 |
+
|
| 386 |
+
### Full Pipeline
|
| 387 |
+
**Endpoint**: `/api/full_pipeline`
|
| 388 |
+
**Method**: POST
|
| 389 |
+
|
| 390 |
+
```json
|
| 391 |
+
{
|
| 392 |
+
"paper_title": "Your Paper Title",
|
| 393 |
+
"paper_abstract": "Your paper abstract...",
|
| 394 |
+
"reviews": ["Review 1 text...", "Review 2 text..."]
|
| 395 |
+
}
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
### Individual Stages
|
| 399 |
+
|
| 400 |
+
| Endpoint | Description |
|
| 401 |
+
|----------|-------------|
|
| 402 |
+
| `/api/critique_extraction` | Extract critique points from reviews |
|
| 403 |
+
| `/api/disagreement_detection` | Detect disagreements between critiques |
|
| 404 |
+
| `/api/search_retrieval` | Search for supporting evidence |
|
| 405 |
+
|
| 406 |
+
### Rate Limits
|
| 407 |
+
- **10 requests per minute** per client
|
| 408 |
+
- **Maximum 3 concurrent** pipeline executions
|
| 409 |
+
|
| 410 |
+
### Example Python Usage
|
| 411 |
+
```python
|
| 412 |
+
import requests
|
| 413 |
+
|
| 414 |
+
response = requests.post(
|
| 415 |
+
"https://your-space.hf.space/api/full_pipeline",
|
| 416 |
+
json={
|
| 417 |
+
"paper_title": "Novel Approach to X",
|
| 418 |
+
"paper_abstract": "We propose...",
|
| 419 |
+
"reviews": ["Review 1...", "Review 2..."]
|
| 420 |
+
}
|
| 421 |
+
)
|
| 422 |
+
result = response.json()
|
| 423 |
+
print(result["meta_review"])
|
| 424 |
+
```
|
| 425 |
+
""")
|
| 426 |
+
|
| 427 |
+
with gr.Tab("βΉοΈ About"):
|
| 428 |
+
gr.Markdown("""
|
| 429 |
+
## About This Tool
|
| 430 |
+
|
| 431 |
+
This API provides automated peer review consensus analysis using state-of-the-art LLMs
|
| 432 |
+
and search-augmented verification.
|
| 433 |
+
|
| 434 |
+
### Models Used
|
| 435 |
+
- **Gemini 2.5 Flash Lite** - Critique extraction and disagreement detection
|
| 436 |
+
- **DeepSeek-R1** - Disagreement resolution and meta-review generation (with reasoning)
|
| 437 |
+
|
| 438 |
+
### Search Sources
|
| 439 |
+
- Semantic Scholar
|
| 440 |
+
- arXiv
|
| 441 |
+
- Tavily Search
|
| 442 |
+
- Google Scholar (via SerpAPI)
|
| 443 |
+
|
| 444 |
+
### Example Paper
|
| 445 |
+
The example paper is from **ICLR 2020**: *"Learning Disentangled Representations for
|
| 446 |
+
CounterFactual Regression"* which addresses estimating treatment effects from observational
|
| 447 |
+
data using disentangled representations.
|
| 448 |
+
|
| 449 |
+
### License
|
| 450 |
+
MIT License - See repository for details.
|
| 451 |
+
""")
|
| 452 |
|
| 453 |
# Launch the app
|
| 454 |
if __name__ == "__main__":
|