jenbenarye commited on
Commit
de86b59
·
1 Parent(s): a075bb3

thank you panel debug

Browse files
Files changed (1) hide show
  1. app/app.py +48 -60
app/app.py CHANGED
@@ -534,58 +534,8 @@ def save_new_language(lang_name, system_prompt):
534
  return gr.Group(visible=False), gr.HTML("<script>window.location.reload();</script>"), gr.Dropdown(choices=list(LANGUAGES.keys()))
535
 
536
 
537
- def send_email_notification(contributor_data):
538
- """Send an email notification to the admin team about a new contributor."""
539
- admin_email = os.getenv("ADMIN_EMAIL")
540
- if not admin_email:
541
- print("ADMIN_EMAIL environment variable not set, skipping notification")
542
- return False
543
-
544
- # Email sending configuration
545
- smtp_server = os.getenv("SMTP_SERVER", "smtp.gmail.com")
546
- smtp_port = int(os.getenv("SMTP_PORT", "587"))
547
- smtp_username = os.getenv("SMTP_USERNAME")
548
- smtp_password = os.getenv("SMTP_PASSWORD")
549
-
550
- if not smtp_username or not smtp_password:
551
- print("SMTP credentials not set, skipping notification")
552
- return False
553
-
554
- try:
555
- # Create message
556
- msg = MIMEMultipart()
557
- msg["Subject"] = "New FeeL Contributor Submission"
558
- msg["From"] = smtp_username
559
- msg["To"] = admin_email
560
-
561
- # Email body
562
- body = f"""
563
- New contributor has submitted their information:
564
-
565
- Email: {contributor_data.get('email', 'Not provided')}
566
- Name: {contributor_data.get('name', 'Not provided')}
567
- Timestamp: {contributor_data.get('timestamp', datetime.now().isoformat())}
568
- """
569
-
570
- msg.attach(MIMEText(body, "plain"))
571
-
572
- # Send email
573
- context = ssl.create_default_context()
574
- with smtplib.SMTP(smtp_server, smtp_port) as server:
575
- server.starttls(context=context)
576
- server.login(smtp_username, smtp_password)
577
- server.send_message(msg)
578
-
579
- print(f"Email notification sent to {admin_email}")
580
- return True
581
-
582
- except Exception as e:
583
- print(f"Error sending email notification: {e}")
584
- return False
585
-
586
-
587
  def save_contributor_email(email, name=""):
588
- """Save contributor email to persistent storage and notify admin"""
589
  emails_path, use_persistent = get_persistent_storage_path("contributors.json")
590
 
591
  # Read existing emails
@@ -595,25 +545,47 @@ def save_contributor_email(email, name=""):
595
  else:
596
  contributors = []
597
 
598
- # Create contributor data
599
- contributor_data = {
600
  "email": email,
601
  "name": name,
602
  "timestamp": datetime.now().isoformat()
603
- }
604
-
605
- # Add new email with timestamp
606
- contributors.append(contributor_data)
607
 
608
  # Save back to file
609
  with open(emails_path, "w", encoding="utf-8") as f:
610
  json.dump(contributors, f, ensure_ascii=False, indent=2)
611
 
612
- # Send email notification
613
- send_email_notification(contributor_data)
614
-
615
  return True
616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617
  css = """
618
  .options.svelte-pcaovb {
619
  display: none !important;
@@ -796,6 +768,16 @@ with gr.Blocks(css=css, js=js) as demo:
796
  submit_email_btn = gr.Button("Submit")
797
  email_submit_status = gr.Markdown("")
798
 
 
 
 
 
 
 
 
 
 
 
799
  refresh_html = gr.HTML(visible=False)
800
 
801
  session_id = gr.Textbox(
@@ -954,4 +936,10 @@ with gr.Blocks(css=css, js=js) as demo:
954
  outputs=None
955
  )
956
 
 
 
 
 
 
 
957
  demo.launch()
 
534
  return gr.Group(visible=False), gr.HTML("<script>window.location.reload();</script>"), gr.Dropdown(choices=list(LANGUAGES.keys()))
535
 
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  def save_contributor_email(email, name=""):
538
+ """Save contributor email to persistent storage"""
539
  emails_path, use_persistent = get_persistent_storage_path("contributors.json")
540
 
541
  # Read existing emails
 
545
  else:
546
  contributors = []
547
 
548
+ # Add new email with timestamp
549
+ contributors.append({
550
  "email": email,
551
  "name": name,
552
  "timestamp": datetime.now().isoformat()
553
+ })
 
 
 
554
 
555
  # Save back to file
556
  with open(emails_path, "w", encoding="utf-8") as f:
557
  json.dump(contributors, f, ensure_ascii=False, indent=2)
558
 
 
 
 
559
  return True
560
 
561
+ # Add this to view emails (protected with admin password)
562
+ def view_contributors(password):
563
+ """View contributor emails (protected)"""
564
+ correct_password = os.getenv("ADMIN_PASSWORD", "default_admin_password")
565
+ print(f"Entered password: {password}, Correct: {password == correct_password}")
566
+
567
+ if password != correct_password:
568
+ return "Incorrect password. Try using 'default_admin_password' if you haven't set the environment variable.", gr.Dataframe(visible=False)
569
+
570
+ emails_path, _ = get_persistent_storage_path("contributors.json")
571
+
572
+ print(f"Checking for contributors at: {emails_path}, exists: {emails_path.exists()}")
573
+
574
+ if not emails_path.exists():
575
+ return f"No contributors found. File does not exist at {emails_path}", gr.Dataframe(visible=False)
576
+
577
+ try:
578
+ with open(emails_path, "r", encoding="utf-8") as f:
579
+ contributors = json.load(f)
580
+
581
+ if not contributors:
582
+ return "Contributors file exists but is empty.", gr.Dataframe(visible=False)
583
+
584
+ # Return the DataFrame with visible=True
585
+ return f"Found {len(contributors)} contributors.", gr.Dataframe(value=contributors, visible=True)
586
+ except Exception as e:
587
+ return f"Error reading contributors file: {str(e)}", gr.Dataframe(visible=False)
588
+
589
  css = """
590
  .options.svelte-pcaovb {
591
  display: none !important;
 
768
  submit_email_btn = gr.Button("Submit")
769
  email_submit_status = gr.Markdown("")
770
 
771
+ # Admin section (hidden by default)
772
+ with gr.Accordion("Admin Access", open=False, visible=True):
773
+ admin_password = gr.Textbox(
774
+ label="Admin Password",
775
+ type="password"
776
+ )
777
+ view_emails_btn = gr.Button("View Contributors")
778
+ admin_status = gr.Markdown("")
779
+ contributor_table = gr.Dataframe(visible=False)
780
+
781
  refresh_html = gr.HTML(visible=False)
782
 
783
  session_id = gr.Textbox(
 
936
  outputs=None
937
  )
938
 
939
+ view_emails_btn.click(
940
+ fn=view_contributors,
941
+ inputs=[admin_password],
942
+ outputs=[admin_status, contributor_table]
943
+ )
944
+
945
  demo.launch()