Update app.py
Browse files
app.py
CHANGED
|
@@ -740,17 +740,17 @@ def run_tool(source_url, target_url, anchor_text, smart_rewrite, plain_text, sug
|
|
| 740 |
anchor_was_present = res.get("anchor_was_present", False)
|
| 741 |
keyword_in_article = res.get("keyword_in_article", False)
|
| 742 |
|
| 743 |
-
# If anchor is present in the article (even if not in the best sentence)
|
| 744 |
if keyword_in_article:
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
result = warn + f"β
**Anchor text '{anchor_text}' found in article!**\n\n"
|
| 750 |
result += f"π Add link here:\n\n"
|
| 751 |
-
result += f"{final_output}"
|
| 752 |
-
|
| 753 |
-
|
|
|
|
| 754 |
g = gpt_rewrite(draft_html, anchor_text, target_url, style="neutral", language=language_name)
|
| 755 |
final_html = g["sentence_html"]
|
| 756 |
else:
|
|
@@ -761,58 +761,27 @@ def run_tool(source_url, target_url, anchor_text, smart_rewrite, plain_text, sug
|
|
| 761 |
final_output = to_plain_text(final_html) if plain_text else final_html
|
| 762 |
|
| 763 |
result = warn + f"β
**Anchor text '{anchor_text}' found in article!**\n\n"
|
| 764 |
-
result += f"π Add link here:\n\n"
|
| 765 |
-
result += f"{final_output}"
|
| 766 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 767 |
else:
|
| 768 |
-
|
| 769 |
-
if smart_rewrite:
|
| 770 |
-
g = gpt_rewrite(draft_html, anchor_text, target_url, style="neutral", language=language_name)
|
| 771 |
-
final_html = g["sentence_html"]
|
| 772 |
-
else:
|
| 773 |
-
final_html = draft_html
|
| 774 |
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
# Show alternative if requested and available
|
| 785 |
-
if suggest_alternative_anchor and res.get("alternative_anchor"):
|
| 786 |
-
alt_anchor = res["alternative_anchor"]
|
| 787 |
-
alt_sentence_original = res.get("alternative_sentence_original", "")
|
| 788 |
-
alt_sentence = res.get("alternative_sentence", "")
|
| 789 |
-
|
| 790 |
-
# Detect language for alternative sentence
|
| 791 |
-
if alt_sentence_original:
|
| 792 |
-
alt_detected_lang = detect_language(alt_sentence_original)
|
| 793 |
-
alt_language_name = get_language_name(alt_detected_lang)
|
| 794 |
-
|
| 795 |
-
# Apply GPT rewriting to alternative as well
|
| 796 |
-
if smart_rewrite and alt_sentence:
|
| 797 |
-
alt_g = gpt_rewrite(alt_sentence, alt_anchor, target_url, style="neutral", language=alt_language_name)
|
| 798 |
-
alt_final = alt_g["sentence_html"]
|
| 799 |
-
else:
|
| 800 |
-
alt_final = alt_sentence
|
| 801 |
-
|
| 802 |
-
# Polish if needed
|
| 803 |
-
if not res.get("alternative_exact_match", False):
|
| 804 |
-
alt_polished = gpt_validate_and_polish(alt_final, alt_anchor, target_url, language=alt_language_name)
|
| 805 |
-
alt_final = alt_polished.get("sentence_html", alt_final)
|
| 806 |
-
|
| 807 |
-
alt_output = to_plain_text(alt_final) if plain_text else alt_final
|
| 808 |
-
|
| 809 |
-
# Add alternative as Result 2
|
| 810 |
-
result += f"\n\n{'='*50}\n\n"
|
| 811 |
-
result += f"π Result 2 - Alternative from article:\n"
|
| 812 |
-
result += f"π‘ Alternative anchor: '{alt_anchor}'\n\n"
|
| 813 |
-
result += f"Original: {alt_sentence_original}\n\n"
|
| 814 |
-
result += f"Suggested: {alt_output}"
|
| 815 |
|
|
|
|
|
|
|
| 816 |
return result
|
| 817 |
|
| 818 |
def clear_cache():
|
|
|
|
| 740 |
anchor_was_present = res.get("anchor_was_present", False)
|
| 741 |
keyword_in_article = res.get("keyword_in_article", False)
|
| 742 |
|
|
|
|
| 743 |
if keyword_in_article:
|
| 744 |
+
# Anchor exists somewhere in article
|
| 745 |
+
if anchor_was_present:
|
| 746 |
+
# Anchor is in the suggested sentence - just show where to add the link
|
| 747 |
+
final_output = to_plain_text(draft_html) if plain_text else draft_html
|
| 748 |
result = warn + f"β
**Anchor text '{anchor_text}' found in article!**\n\n"
|
| 749 |
result += f"π Add link here:\n\n"
|
| 750 |
+
result += f"{final_output}"
|
| 751 |
+
else:
|
| 752 |
+
# Anchor is in article but not in this sentence
|
| 753 |
+
if smart_rewrite:
|
| 754 |
g = gpt_rewrite(draft_html, anchor_text, target_url, style="neutral", language=language_name)
|
| 755 |
final_html = g["sentence_html"]
|
| 756 |
else:
|
|
|
|
| 761 |
final_output = to_plain_text(final_html) if plain_text else final_html
|
| 762 |
|
| 763 |
result = warn + f"β
**Anchor text '{anchor_text}' found in article!**\n\n"
|
| 764 |
+
result += f"π Add link here:\n\n"
|
| 765 |
+
result += f"{final_output}"
|
| 766 |
+
else: # THIS IS LINE 752 - Make sure this else matches the if keyword_in_article
|
| 767 |
+
# Anchor doesn't exist in article at all - need to add it
|
| 768 |
+
if smart_rewrite:
|
| 769 |
+
g = gpt_rewrite(draft_html, anchor_text, target_url, style="neutral", language=language_name)
|
| 770 |
+
final_html = g["sentence_html"]
|
| 771 |
else:
|
| 772 |
+
final_html = draft_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 773 |
|
| 774 |
+
polished = gpt_validate_and_polish(final_html, anchor_text, target_url, language=language_name)
|
| 775 |
+
final_html = polished.get("sentence_html", final_html)
|
| 776 |
+
final_output = to_plain_text(final_html) if plain_text else final_html
|
| 777 |
|
| 778 |
+
result = warn + f"β οΈ **Anchor text '{anchor_text}' not found in article**\n\n"
|
| 779 |
+
result += f"π Result 1 - Suggested placement:\n\n"
|
| 780 |
+
result += f"Original: {original_sentence}\n\n"
|
| 781 |
+
result += f"Suggested: {final_output}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
|
| 783 |
+
# Show alternative if requested and available
|
| 784 |
+
if suggest_alternative_anchor and res.get("alternative_anchor"):
|
| 785 |
return result
|
| 786 |
|
| 787 |
def clear_cache():
|