Spaces:
Running
Running
Phoenixak99
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -582,57 +582,31 @@ def download_audio():
|
|
582 |
on_click=update_download_count
|
583 |
)
|
584 |
|
585 |
-
def notify_admin_of_generation(
|
586 |
"""
|
587 |
-
|
588 |
"""
|
589 |
-
sender_email = "[email protected]" # Your email
|
590 |
-
sender_password = os.getenv("EMAIL_PASSWORD") # Store this in your environment variables
|
591 |
-
|
592 |
-
# Create the email
|
593 |
-
msg = MIMEMultipart()
|
594 |
-
msg["From"] = sender_email
|
595 |
-
msg["To"] = sender_email # Sending to yourself
|
596 |
-
msg["Subject"] = f"New Song Generated - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
|
597 |
-
|
598 |
-
# Create the email body with generation details
|
599 |
-
body = f"""
|
600 |
-
New Song Generation Details:
|
601 |
-
|
602 |
-
Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
603 |
-
User ID: {user_id}
|
604 |
-
|
605 |
-
Song Parameters:
|
606 |
-
- Genre: {genre}
|
607 |
-
- Energy Level: {energy_level}
|
608 |
-
- Tempo: {tempo}
|
609 |
-
- Duration: {duration} seconds
|
610 |
-
- Description: {description}
|
611 |
-
|
612 |
-
Links:
|
613 |
-
- Permanent Link: {perm_link}
|
614 |
-
- Product Code: {product_code}
|
615 |
-
|
616 |
-
--
|
617 |
-
Automated notification from SongLab AI
|
618 |
-
"""
|
619 |
-
|
620 |
-
msg.attach(MIMEText(body, "plain"))
|
621 |
-
|
622 |
try:
|
623 |
-
|
624 |
-
server = smtplib.SMTP("smtp.gmail.com", 587) # Update with your SMTP server
|
625 |
-
server.starttls()
|
626 |
-
server.login(sender_email, sender_password)
|
627 |
|
628 |
-
#
|
629 |
-
|
630 |
-
|
|
|
|
|
|
|
|
|
|
|
631 |
|
632 |
-
|
|
|
|
|
|
|
|
|
|
|
633 |
except Exception as e:
|
634 |
-
print(f"×
|
635 |
-
|
636 |
def update_download_count():
|
637 |
auth_headers = get_auth_headers()
|
638 |
update_download_url = "https://songlabai.com/wp-json/custom-api/v1/update-download-count"
|
@@ -689,17 +663,9 @@ def load_and_play_generated_audio(response, genre=None, energy_level=None, tempo
|
|
689 |
except:
|
690 |
user_id = 'Unknown'
|
691 |
|
692 |
-
# Send
|
693 |
-
notify_admin_of_generation(
|
694 |
-
|
695 |
-
genre=genre,
|
696 |
-
energy_level=energy_level,
|
697 |
-
tempo=tempo,
|
698 |
-
description=description,
|
699 |
-
duration=duration,
|
700 |
-
perm_link=perm_link,
|
701 |
-
product_code=product_code
|
702 |
-
)
|
703 |
|
704 |
# Define col_btn and col_text
|
705 |
col_btn, col_text = st.columns([2, 4])
|
|
|
582 |
on_click=update_download_count
|
583 |
)
|
584 |
|
585 |
+
def notify_admin_of_generation(perm_link, product_code):
|
586 |
"""
|
587 |
+
Notify admin of new song generation using WordPress REST API
|
588 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
try:
|
590 |
+
notification_url = "https://songlabai.com/wp-json/songlab/v1/notify"
|
|
|
|
|
|
|
591 |
|
592 |
+
# Prepare the notification data
|
593 |
+
payload = {
|
594 |
+
"link": perm_link,
|
595 |
+
"product_code": product_code
|
596 |
+
}
|
597 |
+
|
598 |
+
# Send the notification
|
599 |
+
response = requests.post(notification_url, json=payload)
|
600 |
|
601 |
+
# Check if notification was successful
|
602 |
+
if response.status_code == 200:
|
603 |
+
print("✓ Admin notification sent successfully")
|
604 |
+
else:
|
605 |
+
print("× Failed to send admin notification")
|
606 |
+
|
607 |
except Exception as e:
|
608 |
+
print(f"× Error sending notification: {str(e)}")
|
609 |
+
|
610 |
def update_download_count():
|
611 |
auth_headers = get_auth_headers()
|
612 |
update_download_url = "https://songlabai.com/wp-json/custom-api/v1/update-download-count"
|
|
|
663 |
except:
|
664 |
user_id = 'Unknown'
|
665 |
|
666 |
+
# Send notification using simplified function
|
667 |
+
notify_admin_of_generation(perm_link, product_code)
|
668 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
|
670 |
# Define col_btn and col_text
|
671 |
col_btn, col_text = st.columns([2, 4])
|