Justin Grammens commited on
Commit
ff2758d
·
1 Parent(s): 7a39102

latest updates

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import os
 
3
 
4
  from langchain.prompts import PromptTemplate
5
  from langchain_openai import ChatOpenAI
@@ -48,6 +49,24 @@ prompt = PromptTemplate(
48
  template=template,
49
  )
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Function to generate the essay using the template and answers
52
  def stream_leadership_essay(*answers):
53
 
@@ -56,8 +75,6 @@ def stream_leadership_essay(*answers):
56
  yield "All fields are required.", "All fields are required."
57
  return
58
 
59
- print("UPDATED")
60
- print(answers[28])
61
  # Check if the email is valid
62
  if "@" not in answers[28]:
63
  yield "Invalid email address. Please enter a valid email address.", "Invalid email address. Please enter a valid email address."
@@ -87,6 +104,10 @@ def stream_leadership_essay(*answers):
87
  essay += chunk.content
88
  yield essay, filled_prompt # Yield partial essay to the Gradio output in real-time
89
 
 
 
 
 
90
  # Define the Gradio interface (form layout)
91
  with gr.Blocks(
92
  theme=gr.themes.Soft()
 
1
  import gradio as gr
2
  import os
3
+ import requests
4
 
5
  from langchain.prompts import PromptTemplate
6
  from langchain_openai import ChatOpenAI
 
49
  template=template,
50
  )
51
 
52
+ def send_simple_message(essay, email):
53
+ print("SENT THIS TEXT", essay, "to this email", email)
54
+ return requests.post(
55
+ "https://api.mailgun.net/v3/sandboxa5c1d20055034dc494f4641da3e62a92.mailgun.org/messages",
56
+ auth=("api", os.environ["MAILGUN_API_KEY"]),
57
+ data={"from": os.environ["PLP_RETURN_EMAIL_ADDRESS"],
58
+ "to": [email, email],
59
+ "subject": "PLP Essay Results",
60
+ "text": essay}
61
+ )
62
+
63
+ # Add an alert box to notify the user if the email was sent correctly
64
+ def show_alert(result):
65
+ if result.status_code == 200:
66
+ gr.Info("Emails sent")
67
+ else:
68
+ gr.Info("Failed to send emails")
69
+
70
  # Function to generate the essay using the template and answers
71
  def stream_leadership_essay(*answers):
72
 
 
75
  yield "All fields are required.", "All fields are required."
76
  return
77
 
 
 
78
  # Check if the email is valid
79
  if "@" not in answers[28]:
80
  yield "Invalid email address. Please enter a valid email address.", "Invalid email address. Please enter a valid email address."
 
104
  essay += chunk.content
105
  yield essay, filled_prompt # Yield partial essay to the Gradio output in real-time
106
 
107
+ result = send_simple_message(essay, answers[28])
108
+ print(result)
109
+ show_alert(result)
110
+
111
  # Define the Gradio interface (form layout)
112
  with gr.Blocks(
113
  theme=gr.themes.Soft()