Spaces:
Running
on
Zero
Running
on
Zero
Commit
Β·
28f7e6c
1
Parent(s):
fd9957e
Enhance abstract analysis function with input validation and improved reasoning prompts; update UI text for clarity and relevance
Browse files
app.py
CHANGED
@@ -283,11 +283,29 @@ def embed_text(text: str | list[str]) -> torch.Tensor:
|
|
283 |
|
284 |
def analyse_abstracts(query_abstract: str, compare_abstract: dict) -> str:
|
285 |
"""Analyze the relationship between two abstracts and return formatted analysis"""
|
286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
messages = [
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
|
292 |
Paper 1 Abstract:
|
293 |
{query_abstract}
|
@@ -295,58 +313,59 @@ Paper 1 Abstract:
|
|
295 |
Paper 2 Abstract:
|
296 |
{compare_abstract["abstract"]}
|
297 |
|
298 |
-
|
299 |
|
300 |
-
* **Methodological Cross-Pollination**:
|
301 |
-
* **Principle or Mechanism Extension**: Do the papers **share
|
302 |
-
* **Interdisciplinary
|
303 |
-
* **Solution or Application
|
304 |
|
305 |
-
|
306 |
|
307 |
-
Return a valid JSON object
|
308 |
{{
|
309 |
-
"reasoning": "Step-by-step analysis of the papers, highlighting **key
|
310 |
|
311 |
-
# Main connecting concepts, methods, or principles
|
312 |
"key_connections": [
|
313 |
{{
|
314 |
"connection": "connection 1",
|
315 |
-
"description": "
|
316 |
}},
|
317 |
-
|
318 |
],
|
319 |
|
320 |
-
"
|
321 |
{{
|
322 |
-
"type": ["Methodological Cross-Pollination", "Principle or Mechanism Extension", "Interdisciplinary
|
323 |
-
"description": "
|
324 |
}},
|
325 |
-
|
326 |
],
|
327 |
|
328 |
-
# Novel, actionable outcomes or applications emerging from the synergies
|
329 |
"research_potential": [
|
330 |
{{
|
331 |
-
"potential": "
|
332 |
-
"description": "
|
333 |
}},
|
334 |
-
|
335 |
],
|
336 |
|
337 |
-
"rating": 1-5, # Overall
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
|
344 |
-
"confidence": 0.0-1.0
|
|
|
|
|
345 |
}}
|
346 |
|
347 |
-
Return only the JSON object
|
348 |
-
|
349 |
-
|
|
|
350 |
|
351 |
# Generate analysis
|
352 |
try:
|
@@ -507,9 +526,9 @@ def create_interface():
|
|
507 |
gr.HTML(
|
508 |
"""
|
509 |
<div style="text-align: center; margin-bottom: 1rem">
|
510 |
-
<h1>
|
511 |
-
<p>
|
512 |
-
<p>An experiment in AI-
|
513 |
</div>
|
514 |
"""
|
515 |
)
|
@@ -517,22 +536,25 @@ def create_interface():
|
|
517 |
with gr.Accordion(label="Instructions and Privacy Policy", open=False):
|
518 |
gr.Markdown(
|
519 |
"""
|
520 |
-
This tool helps you
|
521 |
-
It uses AI to
|
522 |
-
|
523 |
-
|
524 |
-
|
|
|
525 |
|
|
|
|
|
|
|
|
|
|
|
526 |
|
527 |
**Privacy Policy**: The abstract or research description you provide will be included in any feedback
|
528 |
you submit and may be used to improve the model, and published in a public dataset.
|
529 |
Please ensure that you have the right to share this information.
|
530 |
By submitting feedback, you agree to the use of this information for research purposes.
|
531 |
-
|
532 |
-
Please do not include any personally identifiable information, proprietary or sensitive information,
|
533 |
-
or any other information you do not want to share.
|
534 |
|
535 |
-
|
536 |
**Disclaimer**: This tool is in alpha testing and is not intended for production use.
|
537 |
The results are not guaranteed to be accurate or reliable. Use at your own risk.
|
538 |
The tool is provided "as is" without any warranties or guarantees.
|
@@ -542,11 +564,11 @@ def create_interface():
|
|
542 |
)
|
543 |
gr.Markdown(
|
544 |
"""
|
545 |
-
1. **Enter Abstract**: Paste an abstract or describe your research
|
546 |
-
2. **
|
547 |
-
3. **Select a Paper**: Click on a row in the results table to view
|
548 |
-
4. **Analyze Connection
|
549 |
-
5. **
|
550 |
"""
|
551 |
)
|
552 |
|
@@ -556,7 +578,7 @@ def create_interface():
|
|
556 |
lines=8,
|
557 |
key="abstract",
|
558 |
)
|
559 |
-
search_btn = gr.Button("
|
560 |
|
561 |
# Store full paper data
|
562 |
paper_data_state = gr.State([])
|
@@ -572,7 +594,7 @@ def create_interface():
|
|
572 |
headers=["Title", "Authors", "Categories", "Date", "Match Score"],
|
573 |
datatype=["markdown", "markdown", "str", "date", "str"],
|
574 |
latex_delimiters=latex_delimiters,
|
575 |
-
label="
|
576 |
interactive=False,
|
577 |
wrap=False,
|
578 |
line_breaks=False,
|
@@ -589,25 +611,26 @@ def create_interface():
|
|
589 |
show_copy_button=True,
|
590 |
key="paper_details",
|
591 |
)
|
592 |
-
analyze_btn = gr.Button("Analyze
|
593 |
with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
|
594 |
gr.Markdown(
|
595 |
"""
|
596 |
-
Please provide feedback on the
|
|
|
597 |
"""
|
598 |
)
|
599 |
-
# Add thumbs up/down for paper match
|
600 |
paper_feedback = gr.Radio(
|
601 |
-
["π Good Match", "π Poor Match"],
|
|
|
602 |
)
|
603 |
paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
|
604 |
-
paper_comment = gr.Textbox(label="Additional feedback on this
|
605 |
flag_paper_btn = gr.Button("Submit Paper Feedback")
|
606 |
|
607 |
with gr.Column(scale=1):
|
608 |
analysis_output = gr.Markdown(
|
609 |
-
value="#
|
610 |
-
label="
|
611 |
latex_delimiters=latex_delimiters,
|
612 |
show_copy_button=True,
|
613 |
key="analysis_output",
|
@@ -615,17 +638,16 @@ def create_interface():
|
|
615 |
with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as analysis_feedback_accordion:
|
616 |
gr.Markdown(
|
617 |
"""
|
618 |
-
|
619 |
-
If you find
|
620 |
-
Your feedback is valuable and will be used to improve the model and prompt.
|
621 |
"""
|
622 |
)
|
623 |
-
# Add thumbs up/down for analysis
|
624 |
analysis_feedback = gr.Radio(
|
625 |
-
["π Helpful", "π Not Helpful"],
|
|
|
626 |
)
|
627 |
analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
|
628 |
-
analysis_comment = gr.Textbox(label="Additional feedback on analysis (optional)")
|
629 |
flag_analysis_btn = gr.Button("Submit Analysis Feedback")
|
630 |
|
631 |
# Set up logging directories
|
|
|
283 |
|
284 |
def analyse_abstracts(query_abstract: str, compare_abstract: dict) -> str:
|
285 |
"""Analyze the relationship between two abstracts and return formatted analysis"""
|
286 |
+
global reasoning_model
|
287 |
+
# Check if the compare_abstract is valid
|
288 |
+
if not isinstance(compare_abstract, dict) or "abstract" not in compare_abstract:
|
289 |
+
return "Invalid compare_abstract format. Expected a dictionary with 'abstract' key."
|
290 |
+
if not query_abstract or not compare_abstract["abstract"]:
|
291 |
+
return "Invalid input. Please provide both query_abstract and compare_abstract."
|
292 |
+
# Check if the query_abstract is a string
|
293 |
+
if not isinstance(query_abstract, str):
|
294 |
+
return "Invalid query_abstract format. Expected a string."
|
295 |
+
# Check if the compare_abstract is a string
|
296 |
+
if not isinstance(compare_abstract["abstract"], str):
|
297 |
+
return "Invalid compare_abstract format. Expected a string."
|
298 |
+
# Check if the query_abstract is empty
|
299 |
+
if not query_abstract.strip():
|
300 |
+
return "Invalid query_abstract format. Expected a non-empty string."
|
301 |
+
# Check if the compare_abstract is empty
|
302 |
+
if not compare_abstract["abstract"].strip():
|
303 |
+
return "Invalid compare_abstract format. Expected a non-empty string."
|
304 |
+
|
305 |
messages = [
|
306 |
+
{
|
307 |
+
"role": "user",
|
308 |
+
"content": f"""You are trained in evaluating conceptual and methodological connections between research papers. Please **identify and analyze the reasoning-based links** between the following two papers:
|
309 |
|
310 |
Paper 1 Abstract:
|
311 |
{query_abstract}
|
|
|
313 |
Paper 2 Abstract:
|
314 |
{compare_abstract["abstract"]}
|
315 |
|
316 |
+
In your evaluation, consider the following dimensions:
|
317 |
|
318 |
+
* **Methodological Cross-Pollination**: Do the methods or approaches from one paper **directly inform, enhance, or contrast with** the other?
|
319 |
+
* **Principle or Mechanism Extension**: Do the papers **share core principles, mechanisms, or assumptions** that could be **combined or extended** to generate new understanding or tools?
|
320 |
+
* **Interdisciplinary Bridges**: Are there clear opportunities for **knowledge transfer or collaboration** across fields or problem domains?
|
321 |
+
* **Solution or Application Overlap**: Can the solutions, frameworks, or applications in one paper be **adapted or repurposed** to benefit the work in the other, leading to **tangible, novel outcomes**?
|
322 |
|
323 |
+
Assess these connections in both directions (Paper 1 β Paper 2 and Paper 2 β Paper 1). Focus on **relevant and practically meaningful links** β especially those that might be **missed in practice** due to the sheer volume of publications or the separation between research communities. These are often connections that would be **immediately apparent to an expert** familiar with both papers, but easily overlooked otherwise.
|
324 |
|
325 |
+
Return a valid JSON object in the following structure:
|
326 |
{{
|
327 |
+
"reasoning": "Step-by-step conceptual analysis of how the papers relate, highlighting **key connections**, complementary methods, or shared ideas. Emphasize the most **relevant, practically useful takeaways**, and use markdown bold to highlight major points.",
|
328 |
|
|
|
329 |
"key_connections": [
|
330 |
{{
|
331 |
"connection": "connection 1",
|
332 |
+
"description": "1β2 sentence explanation of the **main conceptual or methodological link**, emphasizing its practical or theoretical relevance."
|
333 |
}},
|
334 |
+
...
|
335 |
],
|
336 |
|
337 |
+
"complementarities": [
|
338 |
{{
|
339 |
+
"type": ["Methodological Cross-Pollination", "Principle or Mechanism Extension", "Interdisciplinary Bridges", "Solution or Application Overlap"], # Use only the most relevant label per entry
|
340 |
+
"description": "A concise explanation (1β2 sentences) of the **identified complementarity** or **productive relationship**, including a specific example or outcome it could enable."
|
341 |
}},
|
342 |
+
...
|
343 |
],
|
344 |
|
|
|
345 |
"research_potential": [
|
346 |
{{
|
347 |
+
"potential": "Potential application or outcome 1",
|
348 |
+
"description": "1β2 sentence explanation of the **concrete potential impact**, framed in terms of a **realistic scenario or use case**."
|
349 |
}},
|
350 |
+
...
|
351 |
],
|
352 |
|
353 |
+
"rating": 1-5, # Overall strength of the connection:
|
354 |
+
# 1 = No meaningful connection
|
355 |
+
# 2 = Weak or speculative connection
|
356 |
+
# 3 = Plausible but unproven connection
|
357 |
+
# 4 = Solid connection with future potential
|
358 |
+
# 5 = Strong, well-aligned connection with immediate, valuable implications
|
359 |
|
360 |
+
"confidence": 0.0-1.0 # Confidence score in your assessment (e.g., 0.85 for high confidence, 1.0 for absolute certainty)
|
361 |
+
# Note: The confidence score should reflect your level of certainty in the analysis, not the strength of the connection itself.
|
362 |
+
# A score of 0.0 indicates no confidence in the analysis, while 1.0 indicates absolute certainty.
|
363 |
}}
|
364 |
|
365 |
+
Return only the JSON object. All key names and string values must be in double quotes.
|
366 |
+
""",
|
367 |
+
},
|
368 |
+
]
|
369 |
|
370 |
# Generate analysis
|
371 |
try:
|
|
|
526 |
gr.HTML(
|
527 |
"""
|
528 |
<div style="text-align: center; margin-bottom: 1rem">
|
529 |
+
<h1>Inkling</h1>
|
530 |
+
<p>Discover papers with deep conceptual connections to your research</p>
|
531 |
+
<p>An experiment in AI-assisted research discovery and insight generation</p>
|
532 |
</div>
|
533 |
"""
|
534 |
)
|
|
|
536 |
with gr.Accordion(label="Instructions and Privacy Policy", open=False):
|
537 |
gr.Markdown(
|
538 |
"""
|
539 |
+
This tool helps you uncover research papers with **deep, meaningful connections** to your ideas.
|
540 |
+
It uses AI to go beyond keyword or semantic similarity β analyzing how papers relate **conceptually** and **contextually**,
|
541 |
+
even when the surface topics differ.
|
542 |
+
|
543 |
+
The focus is on surfacing *novel insights* β connections that may not be obvious at a glance,
|
544 |
+
but could **spark new perspectives**, **deepen understanding**, or **highlight relationships that might otherwise be overlooked**.
|
545 |
|
546 |
+
Itβs designed to act more like a research collaborator than a search engine β helping you explore conceptual bridges and
|
547 |
+
unexpected pathways in the literature.
|
548 |
+
|
549 |
+
Please ask any questions or provide feedback on the tool to help us improve it by starting a discussion on
|
550 |
+
the [Community Tab](https://huggingface.co/spaces/nomadicsynth/inkling/discussions).
|
551 |
|
552 |
**Privacy Policy**: The abstract or research description you provide will be included in any feedback
|
553 |
you submit and may be used to improve the model, and published in a public dataset.
|
554 |
Please ensure that you have the right to share this information.
|
555 |
By submitting feedback, you agree to the use of this information for research purposes.
|
556 |
+
Do not include personally identifiable, proprietary, or sensitive information.
|
|
|
|
|
557 |
|
|
|
558 |
**Disclaimer**: This tool is in alpha testing and is not intended for production use.
|
559 |
The results are not guaranteed to be accurate or reliable. Use at your own risk.
|
560 |
The tool is provided "as is" without any warranties or guarantees.
|
|
|
564 |
)
|
565 |
gr.Markdown(
|
566 |
"""
|
567 |
+
1. **Enter Abstract**: Paste an abstract or describe your research question or idea in the text box.
|
568 |
+
2. **Find Related Papers**: Click the button to explore conceptually related research.
|
569 |
+
3. **Select a Paper**: Click on a row in the results table to view more details.
|
570 |
+
4. **Analyze Connection**: Click the analysis button to explore the potential connection between the papers.
|
571 |
+
5. **Insight Analysis**: Review the modelβs reasoning about how and why these papers may relate meaningfully.
|
572 |
"""
|
573 |
)
|
574 |
|
|
|
578 |
lines=8,
|
579 |
key="abstract",
|
580 |
)
|
581 |
+
search_btn = gr.Button("Find Related Papers", variant="primary")
|
582 |
|
583 |
# Store full paper data
|
584 |
paper_data_state = gr.State([])
|
|
|
594 |
headers=["Title", "Authors", "Categories", "Date", "Match Score"],
|
595 |
datatype=["markdown", "markdown", "str", "date", "str"],
|
596 |
latex_delimiters=latex_delimiters,
|
597 |
+
label="Related Papers",
|
598 |
interactive=False,
|
599 |
wrap=False,
|
600 |
line_breaks=False,
|
|
|
611 |
show_copy_button=True,
|
612 |
key="paper_details",
|
613 |
)
|
614 |
+
analyze_btn = gr.Button("Analyze Connection", variant="primary", visible=False)
|
615 |
with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as paper_feedback_accordion:
|
616 |
gr.Markdown(
|
617 |
"""
|
618 |
+
Please provide feedback on the relevance of this paper to your input.
|
619 |
+
This helps us improve how well the system identifies meaningful research connections.
|
620 |
"""
|
621 |
)
|
|
|
622 |
paper_feedback = gr.Radio(
|
623 |
+
["π Good Match", "π Poor Match"],
|
624 |
+
label="Is this paper meaningfully related to your query?",
|
625 |
)
|
626 |
paper_expert = gr.Checkbox(label="I am an expert in this field", value=False)
|
627 |
+
paper_comment = gr.Textbox(label="Additional feedback on this match (optional)")
|
628 |
flag_paper_btn = gr.Button("Submit Paper Feedback")
|
629 |
|
630 |
with gr.Column(scale=1):
|
631 |
analysis_output = gr.Markdown(
|
632 |
+
value="# Connection Analysis",
|
633 |
+
label="Connection Analysis",
|
634 |
latex_delimiters=latex_delimiters,
|
635 |
show_copy_button=True,
|
636 |
key="analysis_output",
|
|
|
638 |
with gr.Accordion(label="Feedback and Flagging", open=True, visible=False) as analysis_feedback_accordion:
|
639 |
gr.Markdown(
|
640 |
"""
|
641 |
+
This connection analysis was generated by an AI model trained to reason about conceptual links between research papers.
|
642 |
+
If you find the explanation helpful, unclear, or off-base, your feedback will help refine the modelβs reasoning process.
|
|
|
643 |
"""
|
644 |
)
|
|
|
645 |
analysis_feedback = gr.Radio(
|
646 |
+
["π Helpful", "π Not Helpful"],
|
647 |
+
label="Was this explanation useful in understanding the connection?",
|
648 |
)
|
649 |
analysis_expert = gr.Checkbox(label="I am an expert in this field", value=False)
|
650 |
+
analysis_comment = gr.Textbox(label="Additional feedback on the analysis (optional)")
|
651 |
flag_analysis_btn = gr.Button("Submit Analysis Feedback")
|
652 |
|
653 |
# Set up logging directories
|