adi-123 commited on
Commit
3df0ab9
Β·
verified Β·
1 Parent(s): 5838dbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -59
app.py CHANGED
@@ -71,46 +71,6 @@ def get_user_preferences() -> Dict[str, str]:
71
  }
72
  return preferences
73
 
74
- # Function to send the story via email using smtplib
75
- def send_story_email(recipient_email: str, story_text: str, audio_file_path: str) -> bool:
76
- try:
77
- # Email configuration
78
- smtp_server = os.environ.get("SMTP_SERVER") # e.g., "smtp.gmail.com"
79
- smtp_port = int(os.environ.get("SMTP_PORT", 587)) # e.g., 587 for TLS
80
- sender_email = os.environ.get("SENDER_EMAIL") # Your email
81
- sender_password = os.environ.get("SENDER_PASSWORD") # Your email password
82
-
83
- # Create the email
84
- msg = MIMEMultipart()
85
- msg['From'] = sender_email
86
- msg['To'] = recipient_email
87
- msg['Subject'] = "Your Generated Story"
88
-
89
- # Attach the story text
90
- msg.attach(MIMEText(f"Here's your generated story:\n\n{story_text}\n\nEnjoy!", 'plain'))
91
-
92
- # Attach the audio file
93
- with open(audio_file_path, 'rb') as audio_file:
94
- audio_part = MIMEAudio(audio_file.read(), _subtype='mp3')
95
- audio_part.add_header('Content-Disposition', 'attachment', filename=os.path.basename(audio_file_path))
96
- msg.attach(audio_part)
97
-
98
- # Send the email
99
- with smtplib.SMTP(smtp_server, smtp_port) as server:
100
- server.starttls() # Upgrade to a secure connection
101
- server.login(sender_email, sender_password)
102
- server.send_message(msg)
103
-
104
- return True
105
-
106
- except Exception as e:
107
- print(f"Error sending email: {str(e)}")
108
- return False
109
-
110
- # Basic email validation function
111
- def validate_email(email: str) -> bool:
112
- pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
113
- return re.match(pattern, email) is not None
114
 
115
  # Main Streamlit application
116
  def main():
@@ -194,25 +154,6 @@ def main():
194
  with st.expander("🎧 Audio Version", expanded=True):
195
  st.audio(st.session_state.audio_file_path)
196
 
197
- # Email section
198
- st.markdown("---")
199
- st.markdown("## πŸ“§ Get Story via Email - RUN LOCALLY")
200
- email = st.text_input(
201
- "Enter your email address:",
202
- help="We'll send you the story text and audio file"
203
- )
204
-
205
- if st.button("πŸ“€ Send to Email"):
206
- if not email:
207
- st.warning("Please enter an email address.")
208
- elif not validate_email(email):
209
- st.error("Please enter a valid email address.")
210
- else:
211
- with st.spinner("πŸ“¨ Sending email..."):
212
- if send_story_email(email, st.session_state.story, st.session_state.audio_file_path):
213
- st.success(f"Email sent to: {email}")
214
- else:
215
- st.error("❌ Failed to send email. Please try again.")
216
 
217
  if __name__ == '__main__':
218
  main()
 
71
  }
72
  return preferences
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Main Streamlit application
76
  def main():
 
154
  with st.expander("🎧 Audio Version", expanded=True):
155
  st.audio(st.session_state.audio_file_path)
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  if __name__ == '__main__':
159
  main()