1
+ import re
1
2
from copy import deepcopy
2
3
3
4
import requests
10
11
from pages .FaceInpainting import FaceInpaintingPage
11
12
12
13
14
+ email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
15
+
13
16
class EmailFaceInpaintingPage (FaceInpaintingPage ):
14
17
title = "Email of You in Paris"
15
18
doc_name = "EmailFaceInpainting#2"
@@ -21,10 +24,10 @@ class RequestModel(BaseModel):
21
24
22
25
num_outputs : int = 1
23
26
quality : int = 50
24
- from_email_prompt : str
25
- cc_email_prompt : str
26
- email_subject_prompt : str
27
- email_body_prompt : str
27
+ email_from : str
28
+ email_cc : str
29
+ email_subject : str
30
+ email_body : str
28
31
should_send_email : bool
29
32
30
33
class Config :
@@ -115,85 +118,40 @@ def render_form(self):
115
118
if not (text_prompt and email_address ):
116
119
st .error ("Please provide a Prompt and your Email Address" , icon = "⚠️" )
117
120
return False
121
+ if not re .fullmatch (email_regex , email_address ):
122
+ st .error ("Please provide a valid Email Address" , icon = "⚠️" )
123
+ return False
118
124
119
125
return submitted
120
126
121
127
def render_settings (self ):
122
128
super ().render_settings ()
123
-
124
- self .should_send_email_checkbox ()
125
- self .from_email_text_input ()
126
- self .cc_email_text_input ()
127
- self .email_subject_text_input ()
128
- self .email_body_text_area ()
129
-
130
- save_btn = st .button (label = "💾 Save Settings" )
131
- if save_btn :
132
- state_to_save = {
133
- field_name : deepcopy (st .session_state [field_name ])
134
- for field_name in self .fields_to_save ()
135
- if field_name in st .session_state
136
- }
137
- with st .spinner ("Saving..." ):
138
- set_saved_doc (
139
- get_doc_ref (
140
- self .doc_name ,
141
- ),
142
- state_to_save ,
143
- )
144
-
145
- def cc_email_text_input (self ):
146
129
st .write (
147
130
"""
148
- ### CC Email
131
+ ### Email settings
149
132
"""
150
133
)
151
- st .text_input (
152
- "cc_email_prompt" ,
153
- label_visibility = "collapsed" ,
154
- key = "cc_email_prompt" ,
155
- )
156
-
157
- def email_body_text_area (self ):
158
- st .write (
159
- """
160
- ### Email Body
161
- """
162
- )
163
- st .text_area (
164
- "email_body_prompt" ,
165
- label_visibility = "collapsed" ,
166
- key = "email_body_prompt" ,
167
- )
168
134
169
- def email_subject_text_input (self ):
170
- st .write (
171
- """
172
- ### Email Subject
173
- """
135
+ st .checkbox (
136
+ "Send email" ,
137
+ key = "should_send_email" ,
174
138
)
175
139
st .text_input (
176
- "email_subject_prompt" ,
177
- label_visibility = "collapsed" ,
178
- key = "email_subject_prompt" ,
140
+ label = "From email" ,
141
+ key = "email_from" ,
179
142
)
180
-
181
- def from_email_text_input (self ):
182
- st .write (
183
- """
184
- ### From Email
185
- """
143
+ st .text_input (
144
+ label = "CC emails (You can enter multiple emails separated by comma)" ,
145
+ key = "email_cc" ,
146
+ placeholder = "john@gmail.com, cathy@gmail.com "
186
147
)
187
148
st .text_input (
188
- "from_email_prompt" ,
189
- label_visibility = "collapsed" ,
190
- key = "from_email_prompt" ,
149
+ label = "Email subject" ,
150
+ key = "email_subject" ,
191
151
)
192
-
193
- def should_send_email_checkbox (self ):
194
- st .checkbox (
195
- "Send Email" ,
196
- key = "should_send_email" ,
152
+ st .text_area (
153
+ label = "Email body" ,
154
+ key = "email_body" ,
197
155
)
198
156
199
157
def render_output (self ):
@@ -218,10 +176,10 @@ def run(self, state: dict):
218
176
yield from super ().run (state )
219
177
should_send_email = st .session_state .get ("should_send_email" )
220
178
if should_send_email :
221
- from_email = st .session_state .get ("from_email_prompt " )
222
- cc_email = st .session_state .get ("cc_email_prompt " )
223
- email_subject = st .session_state .get ("email_subject_prompt " )
224
- email_body = st .session_state .get ("email_body_prompt " )
179
+ from_email = st .session_state .get ("email_from " )
180
+ cc_email = st .session_state .get ("email_cc " )
181
+ email_subject = st .session_state .get ("email_subject " )
182
+ email_body = st .session_state .get ("email_body " )
225
183
send_smtp_message (
226
184
sender = from_email if from_email else "devs@dara.network" ,
227
185
to_address = email_address ,
0 commit comments