Spaces:
Sleeping
Sleeping
Justin Grammens
commited on
Commit
·
8a56a77
1
Parent(s):
5827eb5
updated to use sendgrid
Browse files- app.py +25 -24
- requirements.txt +2 -1
app.py
CHANGED
@@ -6,8 +6,15 @@ from langchain.prompts import PromptTemplate
|
|
6 |
from langchain_openai import ChatOpenAI
|
7 |
from langchain.schema import HumanMessage
|
8 |
|
|
|
|
|
|
|
9 |
secretcode = os.environ["SECRETCODE"]
|
10 |
|
|
|
|
|
|
|
|
|
11 |
# Initialize the OpenAI model
|
12 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=.8)
|
13 |
|
@@ -49,32 +56,26 @@ prompt = PromptTemplate(
|
|
49 |
template=template,
|
50 |
)
|
51 |
|
52 |
-
def
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
print(jj.text)
|
69 |
-
print(jj.headers)
|
70 |
-
return jj
|
71 |
|
72 |
# Add an alert box to notify the user if the email was sent correctly
|
73 |
def show_alert(result):
|
74 |
-
|
75 |
-
gr.Info("Emails sent")
|
76 |
-
else:
|
77 |
-
gr.Info("Failed to send emails")
|
78 |
|
79 |
# Function to generate the essay using the template and answers
|
80 |
def stream_leadership_essay(*answers):
|
@@ -113,7 +114,7 @@ def stream_leadership_essay(*answers):
|
|
113 |
essay += chunk.content
|
114 |
yield essay, filled_prompt # Yield partial essay to the Gradio output in real-time
|
115 |
|
116 |
-
result =
|
117 |
print(result)
|
118 |
show_alert(result)
|
119 |
|
|
|
6 |
from langchain_openai import ChatOpenAI
|
7 |
from langchain.schema import HumanMessage
|
8 |
|
9 |
+
from sendgrid import SendGridAPIClient
|
10 |
+
from sendgrid.helpers.mail import Mail
|
11 |
+
|
12 |
secretcode = os.environ["SECRETCODE"]
|
13 |
|
14 |
+
|
15 |
+
# Replace with your verified sender email
|
16 |
+
from_email = '[email protected]'
|
17 |
+
|
18 |
# Initialize the OpenAI model
|
19 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=.8)
|
20 |
|
|
|
56 |
template=template,
|
57 |
)
|
58 |
|
59 |
+
def send_sendgrid_email(essay, email):
|
60 |
+
message = Mail(
|
61 |
+
from_email=from_email,
|
62 |
+
to_emails=email,
|
63 |
+
subject='PLP Essay Results',
|
64 |
+
html_content=essay)
|
65 |
+
try:
|
66 |
+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
|
67 |
+
response = sg.send(message)
|
68 |
+
print(response.status_code)
|
69 |
+
print(response.body)
|
70 |
+
print(response.headers)
|
71 |
+
return "Email Sent"
|
72 |
+
except Exception as e:
|
73 |
+
print(e)
|
74 |
+
return "Email Failed"
|
|
|
|
|
|
|
75 |
|
76 |
# Add an alert box to notify the user if the email was sent correctly
|
77 |
def show_alert(result):
|
78 |
+
gr.Info(result)
|
|
|
|
|
|
|
79 |
|
80 |
# Function to generate the essay using the template and answers
|
81 |
def stream_leadership_essay(*answers):
|
|
|
114 |
essay += chunk.content
|
115 |
yield essay, filled_prompt # Yield partial essay to the Gradio output in real-time
|
116 |
|
117 |
+
result = send_sendgrid_email(essay, answers[28])
|
118 |
print(result)
|
119 |
show_alert(result)
|
120 |
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
langchain
|
2 |
-
langchain_openai
|
|
|
|
1 |
langchain
|
2 |
+
langchain_openai
|
3 |
+
sendgrid
|