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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
with gr.Blocks(title="Text Paraphraser & Expander", theme=gr.themes.Soft()) as demo:
|
| 391 |
gr.Markdown(
|
| 392 |
"""
|
|
@@ -411,59 +590,58 @@ with gr.Blocks(title="Text Paraphraser & Expander", theme=gr.themes.Soft()) as d
|
|
| 411 |
info="Choose the model for processing"
|
| 412 |
)
|
| 413 |
|
| 414 |
-
gr.
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
)
|
| 467 |
|
| 468 |
with gr.Row():
|
| 469 |
with gr.Column(scale=1):
|
|
@@ -565,6 +743,6 @@ with gr.Blocks(title="Text Paraphraser & Expander", theme=gr.themes.Soft()) as d
|
|
| 565 |
- Output chunks are separated by double newlines for readability
|
| 566 |
"""
|
| 567 |
)
|
| 568 |
-
|
| 569 |
if __name__ == "__main__":
|
| 570 |
demo.launch(share=True)
|
|
|
|
| 387 |
return error_msg, "Error occurred", 0.0, "", "", ""
|
| 388 |
|
| 389 |
# Create Gradio interface
|
| 390 |
+
# with gr.Blocks(title="Text Paraphraser & Expander", theme=gr.themes.Soft()) as demo:
|
| 391 |
+
# gr.Markdown(
|
| 392 |
+
# """
|
| 393 |
+
# # π Text Paraphraser & Expander
|
| 394 |
+
# Transform your text with AI-powered paraphrasing and expansion capabilities.
|
| 395 |
+
# """
|
| 396 |
+
# )
|
| 397 |
+
|
| 398 |
+
# with gr.Row():
|
| 399 |
+
# with gr.Column(scale=1):
|
| 400 |
+
# mode = gr.Radio(
|
| 401 |
+
# choices=["Paraphrase", "Expand"],
|
| 402 |
+
# value="Paraphrase",
|
| 403 |
+
# label="Mode",
|
| 404 |
+
# info="Choose to paraphrase or expand your text"
|
| 405 |
+
# )
|
| 406 |
+
|
| 407 |
+
# model_dropdown = gr.Dropdown(
|
| 408 |
+
# choices=list(PARAPHRASE_MODELS.keys()),
|
| 409 |
+
# value=list(PARAPHRASE_MODELS.keys())[0],
|
| 410 |
+
# label="Model Selection",
|
| 411 |
+
# info="Choose the model for processing"
|
| 412 |
+
# )
|
| 413 |
+
|
| 414 |
+
# gr.Markdown("### βοΈ Parameters")
|
| 415 |
+
|
| 416 |
+
# temperature = gr.Slider(
|
| 417 |
+
# minimum=0.0,
|
| 418 |
+
# maximum=2.0,
|
| 419 |
+
# value=0.7,
|
| 420 |
+
# step=0.1,
|
| 421 |
+
# label="Temperature",
|
| 422 |
+
# info="Higher = more creative, Lower = more focused"
|
| 423 |
+
# )
|
| 424 |
+
|
| 425 |
+
# top_p = gr.Slider(
|
| 426 |
+
# minimum=0.1,
|
| 427 |
+
# maximum=1.0,
|
| 428 |
+
# value=0.9,
|
| 429 |
+
# step=0.05,
|
| 430 |
+
# label="Top-p (Nucleus Sampling)",
|
| 431 |
+
# info="Probability threshold for token selection"
|
| 432 |
+
# )
|
| 433 |
+
|
| 434 |
+
# max_length = gr.Slider(
|
| 435 |
+
# minimum=128,
|
| 436 |
+
# maximum=1024,
|
| 437 |
+
# value=512,
|
| 438 |
+
# step=32,
|
| 439 |
+
# label="Max Length (tokens)",
|
| 440 |
+
# info="Maximum length of generated text per chunk"
|
| 441 |
+
# )
|
| 442 |
+
|
| 443 |
+
# num_beams = gr.Slider(
|
| 444 |
+
# minimum=1,
|
| 445 |
+
# maximum=10,
|
| 446 |
+
# value=4,
|
| 447 |
+
# step=1,
|
| 448 |
+
# label="Number of Beams",
|
| 449 |
+
# info="Higher = better quality but slower"
|
| 450 |
+
# )
|
| 451 |
+
|
| 452 |
+
# max_sentences = gr.Slider(
|
| 453 |
+
# minimum=1,
|
| 454 |
+
# maximum=10,
|
| 455 |
+
# value=4,
|
| 456 |
+
# step=1,
|
| 457 |
+
# label="Sentences per Chunk",
|
| 458 |
+
# info="Number of sentences to process together"
|
| 459 |
+
# )
|
| 460 |
+
|
| 461 |
+
# target_words = gr.Number(
|
| 462 |
+
# value=300,
|
| 463 |
+
# label="Target Word Count (Expand mode)",
|
| 464 |
+
# info="Approximate number of words for expansion",
|
| 465 |
+
# visible=False
|
| 466 |
+
# )
|
| 467 |
+
|
| 468 |
+
# with gr.Row():
|
| 469 |
+
# with gr.Column(scale=1):
|
| 470 |
+
# gr.Markdown("### π₯ Input Text")
|
| 471 |
+
# input_text = gr.Textbox(
|
| 472 |
+
# lines=10,
|
| 473 |
+
# placeholder="Enter your text here...",
|
| 474 |
+
# label="Original Text",
|
| 475 |
+
# show_copy_button=True
|
| 476 |
+
# )
|
| 477 |
+
|
| 478 |
+
# with gr.Column(scale=1):
|
| 479 |
+
# gr.Markdown("### π€ Generated Text")
|
| 480 |
+
# output_text = gr.Textbox(
|
| 481 |
+
# lines=10,
|
| 482 |
+
# label="Processed Text",
|
| 483 |
+
# show_copy_button=True
|
| 484 |
+
# )
|
| 485 |
+
|
| 486 |
+
# with gr.Row():
|
| 487 |
+
# process_btn = gr.Button("π Generate", variant="primary", size="lg")
|
| 488 |
+
# clear_btn = gr.ClearButton([input_text, output_text], value="ποΈ Clear")
|
| 489 |
+
|
| 490 |
+
# stats_display = gr.Markdown()
|
| 491 |
+
|
| 492 |
+
# similarity_display = gr.Number(
|
| 493 |
+
# label="Cosine Similarity Score",
|
| 494 |
+
# precision=4,
|
| 495 |
+
# interactive=False
|
| 496 |
+
# )
|
| 497 |
+
|
| 498 |
+
# # Highlighted comparison section
|
| 499 |
+
# gr.Markdown("---")
|
| 500 |
+
# gr.Markdown("## π Visual Comparison - See What Changed")
|
| 501 |
+
|
| 502 |
+
# with gr.Row():
|
| 503 |
+
# with gr.Column(scale=1):
|
| 504 |
+
# gr.Markdown("### π Original Text (with changes highlighted)")
|
| 505 |
+
# highlighted_original = gr.HTML(
|
| 506 |
+
# label="Original with Changes",
|
| 507 |
+
# show_label=False
|
| 508 |
+
# )
|
| 509 |
+
|
| 510 |
+
# with gr.Column(scale=1):
|
| 511 |
+
# gr.Markdown("### β¨ Generated Text (with changes highlighted)")
|
| 512 |
+
# highlighted_generated = gr.HTML(
|
| 513 |
+
# label="Generated with Changes",
|
| 514 |
+
# show_label=False
|
| 515 |
+
# )
|
| 516 |
+
|
| 517 |
+
# change_stats = gr.HTML(label="Change Statistics")
|
| 518 |
+
|
| 519 |
+
# # Event handlers
|
| 520 |
+
# mode.change(
|
| 521 |
+
# fn=update_model_choices,
|
| 522 |
+
# inputs=[mode],
|
| 523 |
+
# outputs=[model_dropdown]
|
| 524 |
+
# )
|
| 525 |
+
|
| 526 |
+
# mode.change(
|
| 527 |
+
# fn=update_parameters_visibility,
|
| 528 |
+
# inputs=[mode],
|
| 529 |
+
# outputs=[target_words]
|
| 530 |
+
# )
|
| 531 |
+
|
| 532 |
+
# process_btn.click(
|
| 533 |
+
# fn=process_text,
|
| 534 |
+
# inputs=[
|
| 535 |
+
# input_text,
|
| 536 |
+
# mode,
|
| 537 |
+
# model_dropdown,
|
| 538 |
+
# temperature,
|
| 539 |
+
# top_p,
|
| 540 |
+
# max_length,
|
| 541 |
+
# num_beams,
|
| 542 |
+
# max_sentences,
|
| 543 |
+
# target_words
|
| 544 |
+
# ],
|
| 545 |
+
# outputs=[
|
| 546 |
+
# output_text,
|
| 547 |
+
# stats_display,
|
| 548 |
+
# similarity_display,
|
| 549 |
+
# highlighted_original,
|
| 550 |
+
# highlighted_generated,
|
| 551 |
+
# change_stats
|
| 552 |
+
# ]
|
| 553 |
+
# )
|
| 554 |
+
|
| 555 |
+
# gr.Markdown(
|
| 556 |
+
# """
|
| 557 |
+
# ---
|
| 558 |
+
# ### π‘ Tips:
|
| 559 |
+
# - **Paraphrase Mode**: Rewrites text while preserving meaning
|
| 560 |
+
# - **Expand Mode**: Adds details and elaboration to make text longer
|
| 561 |
+
# - **Sentences per Chunk**: Controls how many sentences are processed together (4 recommended)
|
| 562 |
+
# - Adjust temperature for creativity (0.7-1.0 for paraphrase, 1.0-1.5 for expansion)
|
| 563 |
+
# - Higher beam count = better quality but slower processing
|
| 564 |
+
# - Max length is automatically calculated based on input, but can be overridden
|
| 565 |
+
# - Output chunks are separated by double newlines for readability
|
| 566 |
+
# """
|
| 567 |
+
# )
|
| 568 |
+
|
| 569 |
with gr.Blocks(title="Text Paraphraser & Expander", theme=gr.themes.Soft()) as demo:
|
| 570 |
gr.Markdown(
|
| 571 |
"""
|
|
|
|
| 590 |
info="Choose the model for processing"
|
| 591 |
)
|
| 592 |
|
| 593 |
+
with gr.Accordion("βοΈ Advanced Parameters", open=False):
|
| 594 |
+
temperature = gr.Slider(
|
| 595 |
+
minimum=0.0,
|
| 596 |
+
maximum=2.0,
|
| 597 |
+
value=0.7,
|
| 598 |
+
step=0.1,
|
| 599 |
+
label="Temperature",
|
| 600 |
+
info="Higher = more creative, Lower = more focused"
|
| 601 |
+
)
|
| 602 |
+
|
| 603 |
+
top_p = gr.Slider(
|
| 604 |
+
minimum=0.1,
|
| 605 |
+
maximum=1.0,
|
| 606 |
+
value=0.9,
|
| 607 |
+
step=0.05,
|
| 608 |
+
label="Top-p (Nucleus Sampling)",
|
| 609 |
+
info="Probability threshold for token selection"
|
| 610 |
+
)
|
| 611 |
+
|
| 612 |
+
max_length = gr.Slider(
|
| 613 |
+
minimum=128,
|
| 614 |
+
maximum=1024,
|
| 615 |
+
value=512,
|
| 616 |
+
step=32,
|
| 617 |
+
label="Max Length (tokens)",
|
| 618 |
+
info="Maximum length of generated text per chunk"
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
num_beams = gr.Slider(
|
| 622 |
+
minimum=1,
|
| 623 |
+
maximum=10,
|
| 624 |
+
value=4,
|
| 625 |
+
step=1,
|
| 626 |
+
label="Number of Beams",
|
| 627 |
+
info="Higher = better quality but slower"
|
| 628 |
+
)
|
| 629 |
+
|
| 630 |
+
max_sentences = gr.Slider(
|
| 631 |
+
minimum=1,
|
| 632 |
+
maximum=10,
|
| 633 |
+
value=4,
|
| 634 |
+
step=1,
|
| 635 |
+
label="Sentences per Chunk",
|
| 636 |
+
info="Number of sentences to process together"
|
| 637 |
+
)
|
| 638 |
+
|
| 639 |
+
target_words = gr.Number(
|
| 640 |
+
value=300,
|
| 641 |
+
label="Target Word Count (Expand mode)",
|
| 642 |
+
info="Approximate number of words for expansion",
|
| 643 |
+
visible=False
|
| 644 |
+
)
|
|
|
|
| 645 |
|
| 646 |
with gr.Row():
|
| 647 |
with gr.Column(scale=1):
|
|
|
|
| 743 |
- Output chunks are separated by double newlines for readability
|
| 744 |
"""
|
| 745 |
)
|
| 746 |
+
|
| 747 |
if __name__ == "__main__":
|
| 748 |
demo.launch(share=True)
|