Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -172,8 +172,8 @@ class CitationGenerator:
|
|
| 172 |
}
|
| 173 |
try:
|
| 174 |
prompt = self.generate_queries_prompt.format(**input_map)
|
| 175 |
-
response = await self.llm.
|
| 176 |
-
content = response.strip()
|
| 177 |
if not content.startswith('['):
|
| 178 |
start = content.find('[')
|
| 179 |
end = content.rfind(']') + 1
|
|
@@ -230,8 +230,8 @@ class CitationGenerator:
|
|
| 230 |
4. If unsure, use the most likely letter
|
| 231 |
5. Maintain the format: "Lastname, Firstname"
|
| 232 |
"""
|
| 233 |
-
response = await self.llm.
|
| 234 |
-
fixed_name = response.strip()
|
| 235 |
return fixed_name if fixed_name else author
|
| 236 |
except Exception as e:
|
| 237 |
logger.error(f"Error fixing author name: {e}")
|
|
@@ -428,10 +428,10 @@ class CitationGenerator:
|
|
| 428 |
"papers": json.dumps(input_data["papers"], indent=2)
|
| 429 |
}
|
| 430 |
prompt = self.citation_prompt.format(**citation_input)
|
| 431 |
-
response = await self.llm.
|
| 432 |
-
cited_text = response.strip()
|
| 433 |
|
| 434 |
-
# Aggregate BibTeX entries
|
| 435 |
bib_database = BibDatabase()
|
| 436 |
for p in input_data["papers"]:
|
| 437 |
if 'bibtex_entry' in p:
|
|
@@ -482,9 +482,7 @@ def create_gradio_interface() -> gr.Interface:
|
|
| 482 |
if not text.strip():
|
| 483 |
return "Please enter text to process", ""
|
| 484 |
try:
|
| 485 |
-
config = Config(
|
| 486 |
-
gemini_api_key=api_key
|
| 487 |
-
)
|
| 488 |
citation_gen = CitationGenerator(config)
|
| 489 |
return await citation_gen.process_text(
|
| 490 |
text, num_queries, citations_per_query,
|
|
@@ -497,165 +495,188 @@ def create_gradio_interface() -> gr.Interface:
|
|
| 497 |
|
| 498 |
css = """
|
| 499 |
:root {
|
| 500 |
-
|
| 501 |
-
--primary-
|
| 502 |
-
--bg: #FFFFFF;
|
| 503 |
-
--
|
| 504 |
-
--
|
| 505 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
}
|
| 507 |
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
max-width: 100%;
|
| 514 |
-
background: var(--bg);
|
| 515 |
}
|
| 516 |
|
| 517 |
.header {
|
| 518 |
text-align: center;
|
| 519 |
-
margin-bottom:
|
| 520 |
-
|
| 521 |
-
|
|
|
|
|
|
|
| 522 |
}
|
| 523 |
|
| 524 |
.header h1 {
|
| 525 |
-
font-size:
|
| 526 |
-
color: var(--
|
| 527 |
-
|
| 528 |
-
|
| 529 |
}
|
| 530 |
|
| 531 |
-
.header p
|
| 532 |
-
font-size:
|
| 533 |
-
color: var(--text);
|
| 534 |
}
|
| 535 |
|
| 536 |
-
.input-group {
|
| 537 |
-
|
|
|
|
| 538 |
border: 1px solid var(--border);
|
| 539 |
-
|
|
|
|
|
|
|
| 540 |
}
|
| 541 |
|
| 542 |
-
.controls-row {
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
margin-
|
|
|
|
| 546 |
}
|
| 547 |
|
| 548 |
-
.
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
gap: 0.5rem;
|
| 558 |
}
|
| 559 |
|
| 560 |
-
input[type="number"], textarea {
|
| 561 |
-
border:
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
background: var(--control-bg);
|
| 565 |
-
color: var(--text);
|
| 566 |
-
font-size: 0.95rem;
|
| 567 |
}
|
| 568 |
|
| 569 |
.generate-btn {
|
| 570 |
-
background: var(--
|
| 571 |
color: white;
|
| 572 |
-
padding:
|
| 573 |
-
border-radius: 4px;
|
| 574 |
border: none;
|
| 575 |
-
|
| 576 |
-
|
|
|
|
|
|
|
|
|
|
| 577 |
width: 100%;
|
| 578 |
}
|
| 579 |
|
| 580 |
.generate-btn:hover {
|
| 581 |
-
background:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
}
|
| 583 |
|
| 584 |
-
.
|
| 585 |
-
|
| 586 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
}
|
| 588 |
"""
|
| 589 |
|
| 590 |
with gr.Blocks(css=css, theme=gr.themes.Default()) as demo:
|
| 591 |
-
|
|
|
|
|
|
|
| 592 |
<h1>📚 AutoCitation</h1>
|
| 593 |
-
<p>
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
)
|
| 603 |
-
|
| 604 |
-
label="
|
| 605 |
-
|
| 606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
)
|
| 608 |
-
with gr.Row(elem_classes="controls-row"):
|
| 609 |
-
with gr.Column(scale=1):
|
| 610 |
-
num_queries = gr.Number(
|
| 611 |
-
label="Search Queries",
|
| 612 |
-
value=3,
|
| 613 |
-
minimum=1,
|
| 614 |
-
maximum=Config.max_queries,
|
| 615 |
-
step=1
|
| 616 |
-
)
|
| 617 |
-
with gr.Column(scale=1):
|
| 618 |
-
citations_per_query = gr.Number(
|
| 619 |
-
label="Citations per Query",
|
| 620 |
-
value=1,
|
| 621 |
-
minimum=1,
|
| 622 |
-
maximum=Config.max_citations_per_query,
|
| 623 |
-
step=1
|
| 624 |
-
)
|
| 625 |
-
|
| 626 |
-
with gr.Row(elem_classes="source-controls"):
|
| 627 |
-
with gr.Column(scale=1):
|
| 628 |
-
use_arxiv = gr.Checkbox(
|
| 629 |
-
label="Search ArXiv",
|
| 630 |
-
value=True,
|
| 631 |
-
elem_classes="checkbox-group"
|
| 632 |
-
)
|
| 633 |
-
with gr.Column(scale=1):
|
| 634 |
-
use_crossref = gr.Checkbox(
|
| 635 |
-
label="Search CrossRef (Experimental)",
|
| 636 |
-
value=True,
|
| 637 |
-
elem_classes="checkbox-group"
|
| 638 |
-
)
|
| 639 |
-
with gr.Column(scale=2):
|
| 640 |
-
process_btn = gr.Button(
|
| 641 |
-
"Generate",
|
| 642 |
-
elem_classes="generate-btn"
|
| 643 |
-
)
|
| 644 |
-
|
| 645 |
-
with gr.Group(elem_classes="output-group"):
|
| 646 |
-
with gr.Row():
|
| 647 |
-
with gr.Column(scale=1):
|
| 648 |
-
cited_text = gr.Textbox(
|
| 649 |
-
label="Generated Text",
|
| 650 |
-
lines=10,
|
| 651 |
-
show_copy_button=True
|
| 652 |
-
)
|
| 653 |
-
with gr.Column(scale=1):
|
| 654 |
-
bibtex = gr.Textbox(
|
| 655 |
-
label="BibTeX References",
|
| 656 |
-
lines=10,
|
| 657 |
-
show_copy_button=True
|
| 658 |
-
)
|
| 659 |
|
| 660 |
process_btn.click(
|
| 661 |
fn=process,
|
|
|
|
| 172 |
}
|
| 173 |
try:
|
| 174 |
prompt = self.generate_queries_prompt.format(**input_map)
|
| 175 |
+
response = await self.llm.ainvoke(prompt)
|
| 176 |
+
content = response.content.strip()
|
| 177 |
if not content.startswith('['):
|
| 178 |
start = content.find('[')
|
| 179 |
end = content.rfind(']') + 1
|
|
|
|
| 230 |
4. If unsure, use the most likely letter
|
| 231 |
5. Maintain the format: "Lastname, Firstname"
|
| 232 |
"""
|
| 233 |
+
response = await self.llm.ainvoke(prompt)
|
| 234 |
+
fixed_name = response.content.strip()
|
| 235 |
return fixed_name if fixed_name else author
|
| 236 |
except Exception as e:
|
| 237 |
logger.error(f"Error fixing author name: {e}")
|
|
|
|
| 428 |
"papers": json.dumps(input_data["papers"], indent=2)
|
| 429 |
}
|
| 430 |
prompt = self.citation_prompt.format(**citation_input)
|
| 431 |
+
response = await self.llm.ainvoke(prompt)
|
| 432 |
+
cited_text = response.content.strip()
|
| 433 |
|
| 434 |
+
# Aggregate BibTeX entries
|
| 435 |
bib_database = BibDatabase()
|
| 436 |
for p in input_data["papers"]:
|
| 437 |
if 'bibtex_entry' in p:
|
|
|
|
| 482 |
if not text.strip():
|
| 483 |
return "Please enter text to process", ""
|
| 484 |
try:
|
| 485 |
+
config = Config(gemini_api_key=api_key)
|
|
|
|
|
|
|
| 486 |
citation_gen = CitationGenerator(config)
|
| 487 |
return await citation_gen.process_text(
|
| 488 |
text, num_queries, citations_per_query,
|
|
|
|
| 495 |
|
| 496 |
css = """
|
| 497 |
:root {
|
| 498 |
+
/* Modern, sophisticated color palette */
|
| 499 |
+
--primary-bg: #F8F9FA;
|
| 500 |
+
--secondary-bg: #FFFFFF;
|
| 501 |
+
--accent-1: #4A90E2; /* Refined blue */
|
| 502 |
+
--accent-2: #50C878; /* Emerald green */
|
| 503 |
+
--accent-3: #F5B041; /* Warm orange */
|
| 504 |
+
--text-primary: #2C3E50; /* Deep blue-gray */
|
| 505 |
+
--text-secondary: #566573; /* Medium gray */
|
| 506 |
+
--border: #E5E7E9;
|
| 507 |
+
--shadow: rgba(0, 0, 0, 0.1);
|
| 508 |
}
|
| 509 |
|
| 510 |
+
body {
|
| 511 |
+
background-color: var(--primary-bg);
|
| 512 |
+
color: var(--text-primary);
|
| 513 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
| 514 |
+
line-height: 1.6;
|
|
|
|
|
|
|
| 515 |
}
|
| 516 |
|
| 517 |
.header {
|
| 518 |
text-align: center;
|
| 519 |
+
margin-bottom: 2rem;
|
| 520 |
+
padding: 1.5rem;
|
| 521 |
+
background-color: var(--secondary-bg);
|
| 522 |
+
box-shadow: 0 2px 4px var(--shadow);
|
| 523 |
+
border-bottom: none;
|
| 524 |
}
|
| 525 |
|
| 526 |
.header h1 {
|
| 527 |
+
font-size: 2.25rem;
|
| 528 |
+
color: var(--accent-1);
|
| 529 |
+
margin-bottom: 0.75rem;
|
| 530 |
+
font-weight: 600;
|
| 531 |
}
|
| 532 |
|
| 533 |
+
.header p {
|
| 534 |
+
font-size: 1.1rem;
|
| 535 |
+
color: var(--text-secondary);
|
| 536 |
}
|
| 537 |
|
| 538 |
+
.input-group, .controls-row, .source-controls, .output-group {
|
| 539 |
+
padding: 1rem;
|
| 540 |
+
margin-bottom: 1.5rem;
|
| 541 |
border: 1px solid var(--border);
|
| 542 |
+
border-radius: 12px;
|
| 543 |
+
background-color: var(--secondary-bg);
|
| 544 |
+
box-shadow: 0 1px 3px var(--shadow);
|
| 545 |
}
|
| 546 |
|
| 547 |
+
.input-group label, .controls-row label, .source-controls label {
|
| 548 |
+
color: var(--text-primary);
|
| 549 |
+
font-weight: 500;
|
| 550 |
+
margin-bottom: 0.5rem;
|
| 551 |
+
display: block;
|
| 552 |
}
|
| 553 |
|
| 554 |
+
input[type="number"], textarea, .gradio-input, .gradio-output {
|
| 555 |
+
border: 1px solid var(--border);
|
| 556 |
+
border-radius: 8px;
|
| 557 |
+
padding: 0.75rem;
|
| 558 |
+
background-color: var(--primary-bg);
|
| 559 |
+
color: var(--text-primary);
|
| 560 |
+
font-size: 1rem;
|
| 561 |
+
width: 100%;
|
| 562 |
+
transition: border-color 0.3s, box-shadow 0.3s;
|
|
|
|
| 563 |
}
|
| 564 |
|
| 565 |
+
input[type="number"]:focus, textarea:focus {
|
| 566 |
+
border-color: var(--accent-1);
|
| 567 |
+
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
|
| 568 |
+
outline: none;
|
|
|
|
|
|
|
|
|
|
| 569 |
}
|
| 570 |
|
| 571 |
.generate-btn {
|
| 572 |
+
background-color: var(--accent-1);
|
| 573 |
color: white;
|
| 574 |
+
padding: 1rem 2rem;
|
|
|
|
| 575 |
border: none;
|
| 576 |
+
border-radius: 8px;
|
| 577 |
+
font-size: 1.1rem;
|
| 578 |
+
font-weight: 500;
|
| 579 |
+
cursor: pointer;
|
| 580 |
+
transition: all 0.3s ease;
|
| 581 |
width: 100%;
|
| 582 |
}
|
| 583 |
|
| 584 |
.generate-btn:hover {
|
| 585 |
+
background-color: #357ABD;
|
| 586 |
+
transform: translateY(-1px);
|
| 587 |
+
box-shadow: 0 4px 6px var(--shadow);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
.gradio-button {
|
| 591 |
+
background-color: var(--accent-2) !important;
|
| 592 |
+
border-radius: 8px !important;
|
| 593 |
+
transition: all 0.3s ease !important;
|
| 594 |
}
|
| 595 |
|
| 596 |
+
.gradio-button:hover {
|
| 597 |
+
background-color: #45B76C !important;
|
| 598 |
+
transform: translateY(-1px);
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
.gradio-copy-button {
|
| 602 |
+
background-color: var(--accent-3) !important;
|
| 603 |
+
color: var(--text-primary) !important;
|
| 604 |
+
border: none !important;
|
| 605 |
+
border-radius: 6px !important;
|
| 606 |
+
padding: 0.4rem 0.8rem !important;
|
| 607 |
+
cursor: pointer !important;
|
| 608 |
+
font-size: 0.9rem !important;
|
| 609 |
+
font-weight: 500 !important;
|
| 610 |
+
transition: all 0.3s ease !important;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
.gradio-copy-button:hover {
|
| 614 |
+
background-color: #F39C12 !important;
|
| 615 |
+
transform: translateY(-1px);
|
| 616 |
+
box-shadow: 0 2px 4px var(--shadow);
|
| 617 |
}
|
| 618 |
"""
|
| 619 |
|
| 620 |
with gr.Blocks(css=css, theme=gr.themes.Default()) as demo:
|
| 621 |
+
|
| 622 |
+
gr.HTML("""
|
| 623 |
+
<div class="header">
|
| 624 |
<h1>📚 AutoCitation</h1>
|
| 625 |
+
<p>An AI agent that automatically adds citations into your academic text</p>
|
| 626 |
+
</div>
|
| 627 |
+
""")
|
| 628 |
+
|
| 629 |
+
api_key = gr.Textbox(
|
| 630 |
+
label="Gemini API Key",
|
| 631 |
+
placeholder="Enter your Gemini API key...",
|
| 632 |
+
type="password"
|
| 633 |
+
)
|
| 634 |
+
|
| 635 |
+
input_text = gr.Textbox(
|
| 636 |
+
label="Input Text",
|
| 637 |
+
placeholder="Paste or type your text here...",
|
| 638 |
+
lines=8
|
| 639 |
+
)
|
| 640 |
+
|
| 641 |
+
with gr.Row():
|
| 642 |
+
num_queries = gr.Number(
|
| 643 |
+
label="Search Queries",
|
| 644 |
+
value=3,
|
| 645 |
+
minimum=1,
|
| 646 |
+
maximum=Config.max_queries,
|
| 647 |
+
step=1
|
| 648 |
)
|
| 649 |
+
citations_per_query = gr.Number(
|
| 650 |
+
label="Citations per Query",
|
| 651 |
+
value=1,
|
| 652 |
+
minimum=1,
|
| 653 |
+
maximum=Config.max_citations_per_query,
|
| 654 |
+
step=1
|
| 655 |
+
)
|
| 656 |
+
|
| 657 |
+
with gr.Row():
|
| 658 |
+
use_arxiv = gr.Checkbox(
|
| 659 |
+
label="Search arXiv",
|
| 660 |
+
value=True
|
| 661 |
+
)
|
| 662 |
+
use_crossref = gr.Checkbox(
|
| 663 |
+
label="Search Crossref",
|
| 664 |
+
value=True
|
| 665 |
+
)
|
| 666 |
+
|
| 667 |
+
process_btn = gr.Button("Generate", elem_classes="generate-btn")
|
| 668 |
+
|
| 669 |
+
with gr.Row():
|
| 670 |
+
cited_text = gr.Textbox(
|
| 671 |
+
label="Generated Text",
|
| 672 |
+
lines=10,
|
| 673 |
+
show_copy_button=True
|
| 674 |
+
)
|
| 675 |
+
bibtex = gr.Textbox(
|
| 676 |
+
label="BibTeX References",
|
| 677 |
+
lines=10,
|
| 678 |
+
show_copy_button=True
|
| 679 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
| 681 |
process_btn.click(
|
| 682 |
fn=process,
|