Upload app.py
Browse files
app.py
CHANGED
|
@@ -81,7 +81,6 @@ USER_PROMPT_TEMPLATE = """Review the following paper:
|
|
| 81 |
{paper_text}
|
| 82 |
"""
|
| 83 |
|
| 84 |
-
# For now, use fixed review fields
|
| 85 |
# For now, use fixed review fields
|
| 86 |
REVIEW_FIELDS = """## Summary
|
| 87 |
Briefly summarize the paper and its contributions. This is not the place to critique the paper; the authors should generally agree with a well-written summary.
|
|
@@ -310,11 +309,11 @@ def process_file(file):
|
|
| 310 |
# Check if it's a research paper
|
| 311 |
is_paper, confidence, reason = is_research_paper(paper_text)
|
| 312 |
if not is_paper:
|
| 313 |
-
return f"
|
| 314 |
|
| 315 |
# If confidence is low, add a warning
|
| 316 |
if confidence < 0.7:
|
| 317 |
-
paper_text = f"
|
| 318 |
|
| 319 |
return paper_text, True
|
| 320 |
|
|
@@ -324,7 +323,7 @@ def generate(paper_text, review_template):
|
|
| 324 |
# Final check before generation
|
| 325 |
is_paper, confidence, reason = is_research_paper(paper_text)
|
| 326 |
if not is_paper:
|
| 327 |
-
return f"
|
| 328 |
|
| 329 |
messages = create_messages(review_template, paper_text)
|
| 330 |
input_ids = tokenizer.apply_chat_template(
|
|
@@ -409,9 +408,9 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 409 |
return "", gr.update(visible=False), gr.update(interactive=False)
|
| 410 |
text, is_valid = process_file(file)
|
| 411 |
if is_valid:
|
| 412 |
-
return text, gr.update(value="
|
| 413 |
else:
|
| 414 |
-
return text, gr.update(value="
|
| 415 |
|
| 416 |
def handle_text_change(text):
|
| 417 |
if not text or len(text) < 200:
|
|
@@ -420,12 +419,12 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 420 |
is_paper, confidence, reason = is_research_paper(text)
|
| 421 |
if is_paper:
|
| 422 |
if confidence >= 0.7:
|
| 423 |
-
status = "
|
| 424 |
else:
|
| 425 |
-
status = f"
|
| 426 |
return gr.update(interactive=True), gr.update(value=status, visible=True)
|
| 427 |
else:
|
| 428 |
-
return gr.update(interactive=False), gr.update(value=f"
|
| 429 |
|
| 430 |
file_input.upload(handle_file_upload, file_input, [paper_text_field, validation_status, generate_button])
|
| 431 |
paper_text_field.change(handle_text_change, paper_text_field, [generate_button, validation_status])
|
|
|
|
| 81 |
{paper_text}
|
| 82 |
"""
|
| 83 |
|
|
|
|
| 84 |
# For now, use fixed review fields
|
| 85 |
REVIEW_FIELDS = """## Summary
|
| 86 |
Briefly summarize the paper and its contributions. This is not the place to critique the paper; the authors should generally agree with a well-written summary.
|
|
|
|
| 309 |
# Check if it's a research paper
|
| 310 |
is_paper, confidence, reason = is_research_paper(paper_text)
|
| 311 |
if not is_paper:
|
| 312 |
+
return f"⚠️ **Not a Research Paper**\n\nThe uploaded document does not appear to be a research paper.\n\nReason: {reason}\n\nPlease upload a proper academic/research paper with sections like Abstract, Introduction, Methodology, Results, and References.", False
|
| 313 |
|
| 314 |
# If confidence is low, add a warning
|
| 315 |
if confidence < 0.7:
|
| 316 |
+
paper_text = f"⚠️ **Warning**: {reason}. Proceeding with review generation...\n\n---\n\n{paper_text}"
|
| 317 |
|
| 318 |
return paper_text, True
|
| 319 |
|
|
|
|
| 323 |
# Final check before generation
|
| 324 |
is_paper, confidence, reason = is_research_paper(paper_text)
|
| 325 |
if not is_paper:
|
| 326 |
+
return f"⚠️ Cannot generate review: {reason}"
|
| 327 |
|
| 328 |
messages = create_messages(review_template, paper_text)
|
| 329 |
input_ids = tokenizer.apply_chat_template(
|
|
|
|
| 408 |
return "", gr.update(visible=False), gr.update(interactive=False)
|
| 409 |
text, is_valid = process_file(file)
|
| 410 |
if is_valid:
|
| 411 |
+
return text, gr.update(value="✅ **Document validated**: This appears to be a research paper.", visible=True), gr.update(interactive=True)
|
| 412 |
else:
|
| 413 |
+
return text, gr.update(value="❌ **Validation failed**: Please upload a research paper.", visible=True), gr.update(interactive=False)
|
| 414 |
|
| 415 |
def handle_text_change(text):
|
| 416 |
if not text or len(text) < 200:
|
|
|
|
| 419 |
is_paper, confidence, reason = is_research_paper(text)
|
| 420 |
if is_paper:
|
| 421 |
if confidence >= 0.7:
|
| 422 |
+
status = "✅ **Text validated**: This appears to be a research paper."
|
| 423 |
else:
|
| 424 |
+
status = f"⚠️ **Low confidence**: {reason}"
|
| 425 |
return gr.update(interactive=True), gr.update(value=status, visible=True)
|
| 426 |
else:
|
| 427 |
+
return gr.update(interactive=False), gr.update(value=f"❌ **Not a research paper**: {reason}", visible=True)
|
| 428 |
|
| 429 |
file_input.upload(handle_file_upload, file_input, [paper_text_field, validation_status, generate_button])
|
| 430 |
paper_text_field.change(handle_text_change, paper_text_field, [generate_button, validation_status])
|