adi-123 commited on
Commit
143d77d
Β·
verified Β·
1 Parent(s): fd9ac31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -21
app.py CHANGED
@@ -11,11 +11,10 @@ from utils import (
11
  get_user_preferences,
12
  send_story_email,
13
  validate_email,
14
- create_gmail_config
15
  )
16
 
17
  def main():
18
- # Page configuration
19
  st.set_page_config(
20
  page_title="🎨 Image-to-Audio Story 🎧",
21
  page_icon="πŸ–ΌοΈ",
@@ -23,21 +22,38 @@ def main():
23
  )
24
  st.title("Turn the Image into Audio Story")
25
 
26
- # Check for Gmail configuration in sidebar
27
- if not os.path.exists('pysnail.conf'):
28
- st.sidebar.markdown("## πŸ“§ Email Configuration")
29
- with st.sidebar.expander("Configure Gmail Settings", expanded=True):
30
- sender_email = st.text_input("Gmail Address:", type="default", key="gmail")
31
- sender_password = st.text_input("App Password:", type="password", key="password")
32
-
33
- if st.button("Save Configuration"):
34
- if sender_email and sender_password:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  os.environ['SENDER_EMAIL'] = sender_email
36
  os.environ['SENDER_PASSWORD'] = sender_password
37
- create_gmail_config()
38
  st.success("Email configuration saved successfully!")
39
- else:
40
- st.error("Please provide both email and password.")
41
 
42
  # LLM Parameters in sidebar
43
  st.sidebar.markdown("# βš™οΈ LLM Configuration")
@@ -54,8 +70,7 @@ def main():
54
  st.markdown("## πŸ“· Upload Image")
55
  uploaded_file = st.file_uploader(
56
  "Choose an image...",
57
- type=["jpg", "jpeg", "png"],
58
- help="Upload an image to generate a story from"
59
  )
60
 
61
  # Story preferences section
@@ -108,11 +123,9 @@ def main():
108
  st.audio("audio_story.mp3")
109
 
110
  # Email section
111
- st.markdown("---")
112
- st.markdown("## πŸ“§ Get Story via Email")
113
-
114
- # Only show email input if configuration exists
115
- if os.path.exists('pysnail.conf'):
116
  email = st.text_input(
117
  "Enter your email address:",
118
  help="We'll send you the story text and audio file"
 
11
  get_user_preferences,
12
  send_story_email,
13
  validate_email,
14
+ validate_gmail_credentials
15
  )
16
 
17
  def main():
 
18
  st.set_page_config(
19
  page_title="🎨 Image-to-Audio Story 🎧",
20
  page_icon="πŸ–ΌοΈ",
 
22
  )
23
  st.title("Turn the Image into Audio Story")
24
 
25
+ # Email Configuration in Sidebar
26
+ st.sidebar.markdown("## πŸ“§ Email Configuration")
27
+ with st.sidebar.expander("Configure Gmail Settings", expanded=not bool(os.getenv('SENDER_EMAIL'))):
28
+ sender_email = st.text_input(
29
+ "Gmail Address:",
30
+ value=os.getenv('SENDER_EMAIL', ''),
31
+ type="default",
32
+ key="gmail"
33
+ )
34
+ sender_password = st.text_input(
35
+ "App Password:",
36
+ value=os.getenv('SENDER_PASSWORD', ''),
37
+ type="password",
38
+ key="password",
39
+ help="Use an App Password from your Google Account settings"
40
+ )
41
+
42
+ if st.button("Save Configuration"):
43
+ if not sender_email or not sender_password:
44
+ st.error("Please provide both email and password.")
45
+ elif not validate_email(sender_email):
46
+ st.error("Please enter a valid Gmail address.")
47
+ else:
48
+ # Validate credentials
49
+ error = validate_gmail_credentials(sender_email, sender_password)
50
+ if error:
51
+ st.error(f"Failed to validate credentials: {error}")
52
+ else:
53
+ # Save credentials to environment variables
54
  os.environ['SENDER_EMAIL'] = sender_email
55
  os.environ['SENDER_PASSWORD'] = sender_password
 
56
  st.success("Email configuration saved successfully!")
 
 
57
 
58
  # LLM Parameters in sidebar
59
  st.sidebar.markdown("# βš™οΈ LLM Configuration")
 
70
  st.markdown("## πŸ“· Upload Image")
71
  uploaded_file = st.file_uploader(
72
  "Choose an image...",
73
+ type=["jpg", "jpeg", "png"]
 
74
  )
75
 
76
  # Story preferences section
 
123
  st.audio("audio_story.mp3")
124
 
125
  # Email section
126
+ if os.getenv('SENDER_EMAIL') and os.getenv('SENDER_PASSWORD'):
127
+ st.markdown("---")
128
+ st.markdown("## πŸ“§ Get Story via Email")
 
 
129
  email = st.text_input(
130
  "Enter your email address:",
131
  help="We'll send you the story text and audio file"