adi-123 commited on
Commit
bcc2fa3
Β·
verified Β·
1 Parent(s): 7a1f380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -77
app.py CHANGED
@@ -1,17 +1,12 @@
1
  import os
2
  import streamlit as st
3
- import requests
4
- from transformers import pipeline
5
- from typing import Dict
6
- from together import Together
7
  from utils import (
8
  img2txt,
9
  txt2story,
10
  txt2speech,
11
  get_user_preferences,
12
  send_story_email,
13
- validate_email,
14
- validate_gmail_credentials
15
  )
16
 
17
  def main():
@@ -22,46 +17,6 @@ def main():
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")
60
- with st.sidebar.expander("Model Parameters", expanded=False):
61
- top_k = st.number_input("Top-K", min_value=1, max_value=100, value=5)
62
- top_p = st.number_input("Top-P", min_value=0.0, max_value=1.0, value=0.8)
63
- temperature = st.number_input("Temperature", min_value=0.1, max_value=2.0, value=1.5)
64
-
65
  # Main content area
66
  col1, col2 = st.columns([2, 3])
67
 
@@ -102,7 +57,7 @@ def main():
102
  and end with a {preferences['ending']} ending."""
103
 
104
  # Generate story
105
- story = txt2story(prompt, top_k, top_p, temperature)
106
 
107
  # Convert to audio
108
  txt2speech(story)
@@ -123,40 +78,28 @@ def main():
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"
132
- )
133
-
134
- if st.button("πŸ“€ Send to Email"):
135
- if not email:
136
- st.warning("Please enter an email address.")
137
- elif not validate_email(email):
138
- st.error("Please enter a valid email address.")
139
- else:
140
- with st.spinner("πŸ“¨ Sending email..."):
141
- if send_story_email(email, story, "audio_story.mp3"):
142
- st.success("βœ‰οΈ Story sent successfully! Check your email.")
143
- else:
144
- st.error("❌ Failed to send email. Please try again.")
145
- else:
146
- st.warning("⚠️ Please configure Gmail settings in the sidebar to enable email delivery.")
147
 
148
  except Exception as e:
149
  st.error(f"An error occurred: {str(e)}")
150
  st.warning("Please try again or contact support if the problem persists.")
151
 
152
- # Footer
153
- st.markdown("---")
154
- st.markdown("### Credits")
155
- st.caption('''
156
- Made with ❀️ by @Aditya-Neural-Net-Ninja\n
157
- Utilizes Image-to-Text model, Text Generation model, Google Text-to-Speech library\n
158
- Gratitude to Streamlit, πŸ€— Spaces for Deployment & Hosting
159
- ''')
160
-
161
  if __name__ == '__main__':
162
  main()
 
1
  import os
2
  import streamlit as st
 
 
 
 
3
  from utils import (
4
  img2txt,
5
  txt2story,
6
  txt2speech,
7
  get_user_preferences,
8
  send_story_email,
9
+ validate_email
 
10
  )
11
 
12
  def main():
 
17
  )
18
  st.title("Turn the Image into Audio Story")
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # Main content area
21
  col1, col2 = st.columns([2, 3])
22
 
 
57
  and end with a {preferences['ending']} ending."""
58
 
59
  # Generate story
60
+ story = txt2story(prompt, top_k=5, top_p=0.8, temperature=1.5)
61
 
62
  # Convert to audio
63
  txt2speech(story)
 
78
  st.audio("audio_story.mp3")
79
 
80
  # Email section
81
+ st.markdown("---")
82
+ st.markdown("## πŸ“§ Get Story via Email")
83
+ email = st.text_input(
84
+ "Enter your email address:",
85
+ help="We'll send you the story text and audio file"
86
+ )
87
+
88
+ if st.button("πŸ“€ Send to Email"):
89
+ if not email:
90
+ st.warning("Please enter an email address.")
91
+ elif not validate_email(email):
92
+ st.error("Please enter a valid email address.")
93
+ else:
94
+ with st.spinner("πŸ“¨ Sending email..."):
95
+ if send_story_email(email, story, "audio_story.mp3"):
96
+ st.success("βœ‰οΈ Story sent successfully! Check your email.")
97
+ else:
98
+ st.error("❌ Failed to send email. Please try again.")
 
 
 
99
 
100
  except Exception as e:
101
  st.error(f"An error occurred: {str(e)}")
102
  st.warning("Please try again or contact support if the problem persists.")
103
 
 
 
 
 
 
 
 
 
 
104
  if __name__ == '__main__':
105
  main()