Spaces:
Running
Running
Commit
·
0a01100
1
Parent(s):
b15d785
init
Browse files
app.py
CHANGED
|
@@ -31,9 +31,9 @@ def t(key, lang="en"):
|
|
| 31 |
# Configuration parameters
|
| 32 |
|
| 33 |
TIP_TRY_N = 4 # Show like button tip after 12 tries
|
| 34 |
-
FREE_TRY_N =
|
| 35 |
-
SLOW_TRY_N =
|
| 36 |
-
SLOW2_TRY_N =
|
| 37 |
RATE_LIMIT_60 = 25 # Full restriction: blocked after 40 tries
|
| 38 |
|
| 39 |
# Time window configuration (minutes)
|
|
@@ -527,18 +527,25 @@ def edit_image_interface(input_image, prompt, lang, request: gr.Request, progres
|
|
| 527 |
current_phase = get_ip_phase(client_ip)
|
| 528 |
current_count = get_ip_generation_count(client_ip)
|
| 529 |
geo_info = IP_Country_Cache.get(client_ip, {"country": "Unknown", "region": "Unknown", "city": "Unknown"})
|
|
|
|
| 530 |
|
| 531 |
-
print(f"📊 User phase info - IP: {client_ip}, Location: {geo_info['country']}/{geo_info['region']}/{geo_info['city']}, Phase: {current_phase}, Count: {current_count}")
|
| 532 |
|
| 533 |
-
# Check if user reached the like button tip threshold
|
| 534 |
-
|
|
|
|
| 535 |
|
| 536 |
# Check if completely blocked
|
| 537 |
if current_phase == 'blocked':
|
| 538 |
-
# Generate blocked limit button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
blocked_button_html = f"""
|
| 540 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 541 |
-
<a href='
|
| 542 |
display: inline-flex;
|
| 543 |
align-items: center;
|
| 544 |
justify-content: center;
|
|
@@ -568,10 +575,15 @@ def edit_image_interface(input_image, prompt, lang, request: gr.Request, progres
|
|
| 568 |
is_limited, wait_minutes, window_count = check_rate_limit_for_phase(client_ip, current_phase)
|
| 569 |
if is_limited:
|
| 570 |
wait_minutes_int = int(wait_minutes) + 1
|
| 571 |
-
# Generate rate limit button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
rate_limit_button_html = f"""
|
| 573 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 574 |
-
<a href='
|
| 575 |
display: inline-flex;
|
| 576 |
align-items: center;
|
| 577 |
justify-content: center;
|
|
@@ -688,10 +700,15 @@ def edit_image_interface(input_image, prompt, lang, request: gr.Request, progres
|
|
| 688 |
final_result = result_url
|
| 689 |
final_message = t("warning_content_review", lang)
|
| 690 |
|
| 691 |
-
# Generate NSFW button for blurred content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
nsfw_action_buttons_html = f"""
|
| 693 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 694 |
-
<a href='
|
| 695 |
display: inline-flex;
|
| 696 |
align-items: center;
|
| 697 |
justify-content: center;
|
|
@@ -721,71 +738,96 @@ def edit_image_interface(input_image, prompt, lang, request: gr.Request, progres
|
|
| 721 |
except Exception as e:
|
| 722 |
print(f"⚠️ Final progress update failed: {e}")
|
| 723 |
|
| 724 |
-
# Generate action buttons HTML
|
| 725 |
action_buttons_html = ""
|
| 726 |
-
if task_uuid:
|
| 727 |
-
# Create task detail URL for downloading HD image
|
| 728 |
-
task_detail_url = f"https://omnicreator.net/my-creations/task/{task_uuid}"
|
| 729 |
-
action_buttons_html = f"""
|
| 730 |
-
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 731 |
-
<a href='https://omnicreator.net/#generator' target='_blank' style='
|
| 732 |
-
display: inline-flex;
|
| 733 |
-
align-items: center;
|
| 734 |
-
justify-content: center;
|
| 735 |
-
padding: 16px 32px;
|
| 736 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 737 |
-
color: white;
|
| 738 |
-
text-decoration: none;
|
| 739 |
-
border-radius: 12px;
|
| 740 |
-
font-weight: 600;
|
| 741 |
-
font-size: 16px;
|
| 742 |
-
text-align: center;
|
| 743 |
-
min-width: 160px;
|
| 744 |
-
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
| 745 |
-
transition: all 0.3s ease;
|
| 746 |
-
border: none;
|
| 747 |
-
'>🚀 Unlimited Generation</a>
|
| 748 |
-
<a href='{task_detail_url}' target='_blank' style='
|
| 749 |
-
display: inline-flex;
|
| 750 |
-
align-items: center;
|
| 751 |
-
justify-content: center;
|
| 752 |
-
padding: 16px 32px;
|
| 753 |
-
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
| 754 |
-
color: white;
|
| 755 |
-
text-decoration: none;
|
| 756 |
-
border-radius: 12px;
|
| 757 |
-
font-weight: 600;
|
| 758 |
-
font-size: 16px;
|
| 759 |
-
text-align: center;
|
| 760 |
-
min-width: 160px;
|
| 761 |
-
box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
|
| 762 |
-
transition: all 0.3s ease;
|
| 763 |
-
border: none;
|
| 764 |
-
'>💾 Download HD Image</a>
|
| 765 |
-
</div>
|
| 766 |
-
"""
|
| 767 |
|
| 768 |
-
#
|
| 769 |
-
if
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
<div style='
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
|
| 790 |
return final_result, final_message, gr.update(value=action_buttons_html, visible=True)
|
| 791 |
else:
|
|
|
|
| 31 |
# Configuration parameters
|
| 32 |
|
| 33 |
TIP_TRY_N = 4 # Show like button tip after 12 tries
|
| 34 |
+
FREE_TRY_N = 7 # Free phase: first 15 tries without restrictions
|
| 35 |
+
SLOW_TRY_N = 12 # Slow phase start: 25 tries
|
| 36 |
+
SLOW2_TRY_N = 18 # Slow phase start: 32 tries
|
| 37 |
RATE_LIMIT_60 = 25 # Full restriction: blocked after 40 tries
|
| 38 |
|
| 39 |
# Time window configuration (minutes)
|
|
|
|
| 527 |
current_phase = get_ip_phase(client_ip)
|
| 528 |
current_count = get_ip_generation_count(client_ip)
|
| 529 |
geo_info = IP_Country_Cache.get(client_ip, {"country": "Unknown", "region": "Unknown", "city": "Unknown"})
|
| 530 |
+
is_restricted = is_restricted_country_ip(client_ip)
|
| 531 |
|
| 532 |
+
print(f"📊 User phase info - IP: {client_ip}, Location: {geo_info['country']}/{geo_info['region']}/{geo_info['city']}, Phase: {current_phase}, Count: {current_count}, Restricted: {is_restricted}")
|
| 533 |
|
| 534 |
+
# Check if user reached the like button tip threshold
|
| 535 |
+
# For restricted countries, show like tip from the first attempt
|
| 536 |
+
show_like_tip = (current_count >= 1) if is_restricted else (current_count >= TIP_TRY_N)
|
| 537 |
|
| 538 |
# Check if completely blocked
|
| 539 |
if current_phase == 'blocked':
|
| 540 |
+
# Generate blocked limit button with different URL for restricted countries
|
| 541 |
+
if is_restricted:
|
| 542 |
+
blocked_url = 'https://raphael.app/ai-image-editor'
|
| 543 |
+
else:
|
| 544 |
+
blocked_url = 'https://omnicreator.net/#generator'
|
| 545 |
+
|
| 546 |
blocked_button_html = f"""
|
| 547 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 548 |
+
<a href='{blocked_url}' target='_blank' style='
|
| 549 |
display: inline-flex;
|
| 550 |
align-items: center;
|
| 551 |
justify-content: center;
|
|
|
|
| 575 |
is_limited, wait_minutes, window_count = check_rate_limit_for_phase(client_ip, current_phase)
|
| 576 |
if is_limited:
|
| 577 |
wait_minutes_int = int(wait_minutes) + 1
|
| 578 |
+
# Generate rate limit button with different URL for restricted countries
|
| 579 |
+
if is_restricted:
|
| 580 |
+
rate_limit_url = 'https://raphael.app/ai-image-editor'
|
| 581 |
+
else:
|
| 582 |
+
rate_limit_url = 'https://omnicreator.net/#generator'
|
| 583 |
+
|
| 584 |
rate_limit_button_html = f"""
|
| 585 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 586 |
+
<a href='{rate_limit_url}' target='_blank' style='
|
| 587 |
display: inline-flex;
|
| 588 |
align-items: center;
|
| 589 |
justify-content: center;
|
|
|
|
| 700 |
final_result = result_url
|
| 701 |
final_message = t("warning_content_review", lang)
|
| 702 |
|
| 703 |
+
# Generate NSFW button for blurred content with different URL for restricted countries
|
| 704 |
+
if is_restricted:
|
| 705 |
+
nsfw_url = 'https://raphael.app/ai-image-editor'
|
| 706 |
+
else:
|
| 707 |
+
nsfw_url = 'https://omnicreator.net/#generator'
|
| 708 |
+
|
| 709 |
nsfw_action_buttons_html = f"""
|
| 710 |
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 711 |
+
<a href='{nsfw_url}' target='_blank' style='
|
| 712 |
display: inline-flex;
|
| 713 |
align-items: center;
|
| 714 |
justify-content: center;
|
|
|
|
| 738 |
except Exception as e:
|
| 739 |
print(f"⚠️ Final progress update failed: {e}")
|
| 740 |
|
| 741 |
+
# Generate action buttons HTML
|
| 742 |
action_buttons_html = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 743 |
|
| 744 |
+
# For restricted countries, only show like tip (no action buttons)
|
| 745 |
+
if is_restricted:
|
| 746 |
+
if show_like_tip:
|
| 747 |
+
action_buttons_html = """
|
| 748 |
+
<div style='display: flex; justify-content: center; margin: 15px 0 5px 0; padding: 0px;'>
|
| 749 |
+
<div style='
|
| 750 |
+
display: inline-flex;
|
| 751 |
+
align-items: center;
|
| 752 |
+
justify-content: center;
|
| 753 |
+
padding: 12px 24px;
|
| 754 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%);
|
| 755 |
+
color: white;
|
| 756 |
+
border-radius: 10px;
|
| 757 |
+
font-weight: 600;
|
| 758 |
+
font-size: 14px;
|
| 759 |
+
text-align: center;
|
| 760 |
+
max-width: 400px;
|
| 761 |
+
box-shadow: 0 3px 12px rgba(255, 107, 107, 0.3);
|
| 762 |
+
border: none;
|
| 763 |
+
'>👉 Click the ❤️ Like button to unlock more free trial attempts!</div>
|
| 764 |
+
</div>
|
| 765 |
+
"""
|
| 766 |
+
else:
|
| 767 |
+
# For non-restricted countries, show normal buttons
|
| 768 |
+
if task_uuid:
|
| 769 |
+
# Create task detail URL for downloading HD image
|
| 770 |
+
task_detail_url = f"https://omnicreator.net/my-creations/task/{task_uuid}"
|
| 771 |
+
action_buttons_html = f"""
|
| 772 |
+
<div style='display: flex; justify-content: center; gap: 15px; margin: 10px 0 5px 0; padding: 0px;'>
|
| 773 |
+
<a href='https://omnicreator.net/#generator' target='_blank' style='
|
| 774 |
+
display: inline-flex;
|
| 775 |
+
align-items: center;
|
| 776 |
+
justify-content: center;
|
| 777 |
+
padding: 16px 32px;
|
| 778 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 779 |
+
color: white;
|
| 780 |
+
text-decoration: none;
|
| 781 |
+
border-radius: 12px;
|
| 782 |
+
font-weight: 600;
|
| 783 |
+
font-size: 16px;
|
| 784 |
+
text-align: center;
|
| 785 |
+
min-width: 160px;
|
| 786 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
| 787 |
+
transition: all 0.3s ease;
|
| 788 |
+
border: none;
|
| 789 |
+
'>🚀 Unlimited Generation</a>
|
| 790 |
+
<a href='{task_detail_url}' target='_blank' style='
|
| 791 |
+
display: inline-flex;
|
| 792 |
+
align-items: center;
|
| 793 |
+
justify-content: center;
|
| 794 |
+
padding: 16px 32px;
|
| 795 |
+
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
| 796 |
+
color: white;
|
| 797 |
+
text-decoration: none;
|
| 798 |
+
border-radius: 12px;
|
| 799 |
+
font-weight: 600;
|
| 800 |
+
font-size: 16px;
|
| 801 |
+
text-align: center;
|
| 802 |
+
min-width: 160px;
|
| 803 |
+
box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
|
| 804 |
+
transition: all 0.3s ease;
|
| 805 |
+
border: none;
|
| 806 |
+
'>💾 Download HD Image</a>
|
| 807 |
+
</div>
|
| 808 |
+
"""
|
| 809 |
+
|
| 810 |
+
# Add popup script if needed (using different approach)
|
| 811 |
+
if show_like_tip:
|
| 812 |
+
action_buttons_html += """
|
| 813 |
+
<div style='display: flex; justify-content: center; margin: 15px 0 5px 0; padding: 0px;'>
|
| 814 |
+
<div style='
|
| 815 |
+
display: inline-flex;
|
| 816 |
+
align-items: center;
|
| 817 |
+
justify-content: center;
|
| 818 |
+
padding: 12px 24px;
|
| 819 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%);
|
| 820 |
+
color: white;
|
| 821 |
+
border-radius: 10px;
|
| 822 |
+
font-weight: 600;
|
| 823 |
+
font-size: 14px;
|
| 824 |
+
text-align: center;
|
| 825 |
+
max-width: 400px;
|
| 826 |
+
box-shadow: 0 3px 12px rgba(255, 107, 107, 0.3);
|
| 827 |
+
border: none;
|
| 828 |
+
'>👉 Click the ❤️ Like button to unlock more free trial attempts!</div>
|
| 829 |
+
</div>
|
| 830 |
+
"""
|
| 831 |
|
| 832 |
return final_result, final_message, gr.update(value=action_buttons_html, visible=True)
|
| 833 |
else:
|