Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -136,6 +136,100 @@ class EmailGenie:
|
|
136 |
# [The rest of the code (create_interface and main) remains the same]
|
137 |
# ... [Implementation remains unchanged]
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
if __name__ == "__main__":
|
140 |
demo = create_interface()
|
141 |
demo.launch()
|
|
|
136 |
# [The rest of the code (create_interface and main) remains the same]
|
137 |
# ... [Implementation remains unchanged]
|
138 |
|
139 |
+
|
140 |
+
def create_interface():
|
141 |
+
emailgenie = EmailGenie()
|
142 |
+
|
143 |
+
with gr.Blocks(title="EmailGenie") as demo:
|
144 |
+
gr.Markdown("# EmailGenie: AI-Powered Email Outreach")
|
145 |
+
|
146 |
+
with gr.Tab("Profile Setup"):
|
147 |
+
name_input = gr.Textbox(label="Full Name")
|
148 |
+
industry_input = gr.Textbox(label="Industry")
|
149 |
+
background_input = gr.Textbox(label="Professional Background", lines=3)
|
150 |
+
target_input = gr.Textbox(label="Target Audience", lines=2)
|
151 |
+
save_profile_btn = gr.Button("Save Profile")
|
152 |
+
profile_status = gr.Textbox(label="Status", interactive=False)
|
153 |
+
|
154 |
+
with gr.Tab("Generate Email"):
|
155 |
+
profile_name = gr.Textbox(label="Your Profile Name")
|
156 |
+
load_profile_btn = gr.Button("Load Profile")
|
157 |
+
profile_load_status = gr.Textbox(label="Profile Status", interactive=False)
|
158 |
+
|
159 |
+
template_dropdown = gr.Dropdown(
|
160 |
+
choices=["sales_pitch", "job_application"],
|
161 |
+
label="Select Template"
|
162 |
+
)
|
163 |
+
subject_input = gr.Textbox(label="Email Subject")
|
164 |
+
recipient_input = gr.Textbox(label="Recipient Name/Company")
|
165 |
+
recipient_info = gr.Textbox(label="Recipient Information", lines=5)
|
166 |
+
generate_btn = gr.Button("Generate Email")
|
167 |
+
preview_output = gr.Textbox(label="Email Preview", lines=10)
|
168 |
+
|
169 |
+
with gr.Tab("Send Email"):
|
170 |
+
recipient_email = gr.Textbox(label="Recipient Email")
|
171 |
+
send_btn = gr.Button("Send Email")
|
172 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
173 |
+
|
174 |
+
def save_profile(name, industry, background, target):
|
175 |
+
profile_data = {
|
176 |
+
"name": name,
|
177 |
+
"industry": industry,
|
178 |
+
"background": background,
|
179 |
+
"target_audience": target
|
180 |
+
}
|
181 |
+
success = emailgenie.user_profile.save_profile(profile_data)
|
182 |
+
if success:
|
183 |
+
emailgenie.set_current_profile(name)
|
184 |
+
return "Profile saved successfully!" if success else "Error saving profile"
|
185 |
+
|
186 |
+
def load_profile(name):
|
187 |
+
success = emailgenie.set_current_profile(name)
|
188 |
+
return "Profile loaded successfully!" if success else "Profile not found"
|
189 |
+
|
190 |
+
def generate_email_handler(template, subject, recipient, info):
|
191 |
+
if not emailgenie.current_profile:
|
192 |
+
return "Please load your profile first"
|
193 |
+
|
194 |
+
context = {
|
195 |
+
"email_subject": subject,
|
196 |
+
"recipient": recipient,
|
197 |
+
"recipient_info": info
|
198 |
+
}
|
199 |
+
email_content = emailgenie.generate_email(template, context)
|
200 |
+
return emailgenie.preview_email(email_content)
|
201 |
+
|
202 |
+
def send_email_handler(email, content):
|
203 |
+
success, message = emailgenie.send_email(email, "Your Subject", content)
|
204 |
+
return message
|
205 |
+
|
206 |
+
# Connect the interface components with their handlers
|
207 |
+
save_profile_btn.click(
|
208 |
+
save_profile,
|
209 |
+
inputs=[name_input, industry_input, background_input, target_input],
|
210 |
+
outputs=profile_status
|
211 |
+
)
|
212 |
+
|
213 |
+
load_profile_btn.click(
|
214 |
+
load_profile,
|
215 |
+
inputs=[profile_name],
|
216 |
+
outputs=profile_load_status
|
217 |
+
)
|
218 |
+
|
219 |
+
generate_btn.click(
|
220 |
+
generate_email_handler,
|
221 |
+
inputs=[template_dropdown, subject_input, recipient_input, recipient_info],
|
222 |
+
outputs=preview_output
|
223 |
+
)
|
224 |
+
|
225 |
+
send_btn.click(
|
226 |
+
send_email_handler,
|
227 |
+
inputs=[recipient_email, preview_output],
|
228 |
+
outputs=status_output
|
229 |
+
)
|
230 |
+
|
231 |
+
return demo
|
232 |
+
|
233 |
if __name__ == "__main__":
|
234 |
demo = create_interface()
|
235 |
demo.launch()
|