Skip to content

Commit f5365fe

Browse files
authored
Merge pull request #1 from dara-network/mitesh
2 parents 20085cc + f58156a commit f5365fe

File tree

2 files changed

+32
-88
lines changed

2 files changed

+32
-88
lines changed

pages/EmailFaceInpainting.py

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from copy import deepcopy
23

34
import requests
@@ -10,6 +11,8 @@
1011
from pages.FaceInpainting import FaceInpaintingPage
1112

1213

14+
email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
15+
1316
class EmailFaceInpaintingPage(FaceInpaintingPage):
1417
title = "Email of You in Paris"
1518
doc_name = "EmailFaceInpainting#2"
@@ -21,10 +24,10 @@ class RequestModel(BaseModel):
2124

2225
num_outputs: int = 1
2326
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
2831
should_send_email: bool
2932

3033
class Config:
@@ -115,85 +118,40 @@ def render_form(self):
115118
if not (text_prompt and email_address):
116119
st.error("Please provide a Prompt and your Email Address", icon="⚠️")
117120
return False
121+
if not re.fullmatch(email_regex, email_address):
122+
st.error("Please provide a valid Email Address", icon="⚠️")
123+
return False
118124

119125
return submitted
120126

121127
def render_settings(self):
122128
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):
146129
st.write(
147130
"""
148-
### CC Email
131+
### Email settings
149132
"""
150133
)
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-
)
168134

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",
174138
)
175139
st.text_input(
176-
"email_subject_prompt",
177-
label_visibility="collapsed",
178-
key="email_subject_prompt",
140+
label="From email",
141+
key="email_from",
179142
)
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 "
186147
)
187148
st.text_input(
188-
"from_email_prompt",
189-
label_visibility="collapsed",
190-
key="from_email_prompt",
149+
label="Email subject",
150+
key="email_subject",
191151
)
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",
197155
)
198156

199157
def render_output(self):
@@ -218,10 +176,10 @@ def run(self, state: dict):
218176
yield from super().run(state)
219177
should_send_email = st.session_state.get("should_send_email")
220178
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")
225183
send_smtp_message(
226184
sender=from_email if from_email else "devs@dara.network",
227185
to_address=email_address,

uberduck.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,16 @@ def get_audio(uuid):
2525

2626
def main():
2727
st.write("# Text To Audio")
28-
change_voice = st.button("Change voice")
29-
voices = ('zwf',)
30-
if change_voice:
31-
voices_resp = requests.get("https://api.uberduck.ai/voices?mode=tts-basic&language=english",
32-
auth=(config("UBERDUCK_KEY"), config("UBERDUCK_SECRET")),
33-
)
34-
if voices_resp.status_code == 200:
35-
data = json.loads(voices_resp.text)
36-
st.write(data)
37-
38-
option = st.selectbox(
39-
'Change voice',
40-
('zwf', 'Home phone', 'Mobile phone'))
41-
st.write('You selected:', option)
42-
st.write(voices)
4328

4429
with st.form(key="send_email", clear_on_submit=False):
30+
voice = st.text_input(label="Voice", value="zwf")
4531
text = st.text_area(label="Text input", value="This is a test.")
46-
submitted = st.form_submit_button("Send")
32+
submitted = st.form_submit_button("Generate")
4733
if submitted:
4834
response = requests.post(
4935
"https://api.uberduck.ai/speak",
5036
auth=(config("UBERDUCK_KEY"), config("UBERDUCK_SECRET")),
51-
json={"speech": text, "voice": "zwf"}
37+
json={"speech": text, "voice": voice}
5238
)
5339
uuid = json.loads(response.text)["uuid"]
5440
get_audio(uuid)

0 commit comments

Comments
 (0)