Update app.py
Browse files
app.py
CHANGED
|
@@ -30,39 +30,50 @@ def query(payload, API_URL):
|
|
| 30 |
response = requests.request("POST", API_URL, json=payload)
|
| 31 |
return response.json()
|
| 32 |
|
| 33 |
-
def pre_query(recipient, recipient_name,
|
| 34 |
API_URL = "https://api-inference.huggingface.co/models/" + model_id
|
| 35 |
|
| 36 |
-
if model_id == "
|
| 37 |
input_string = "Write a professional email to my " + recipient.lower() + " starting with Hello " + recipient_name + ", about the subject " + context + " and the email should be based on this draft: " + input
|
| 38 |
-
data = query(
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
#if type(data) is dict:
|
| 44 |
-
# return data['error']
|
| 45 |
-
#else:
|
| 46 |
-
return data[0]['generated_text']
|
| 47 |
|
| 48 |
if model_id == "bigscience/bloom":
|
| 49 |
input_string = "Write a professional email to my " + recipient.lower() + " starting with Hello " + recipient_name + ", about the subject " + context + " and the email should be based on this draft: " + input + ": Hello " + recipient_name + ",\n\n"
|
| 50 |
data = query({
|
| 51 |
"inputs":input_string,
|
| 52 |
"parameters":{"max_new_tokens":96,
|
| 53 |
-
"return_full_text": False
|
| 54 |
-
"wait_for_model": True}
|
| 55 |
}, API_URL)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
if model_id == "GPT-3":
|
| 62 |
return openai_query(recipient, 250, recipient_name, context, input)
|
| 63 |
|
| 64 |
return
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
demo = gr.Blocks()
|
| 67 |
|
| 68 |
with demo:
|
|
@@ -75,22 +86,25 @@ with demo:
|
|
| 75 |
with gr.Column():
|
| 76 |
with gr.Group():
|
| 77 |
with gr.Row():
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
recipient = gr.Dropdown(["student", "professor", "employee", "employer", "coworker", "applicant", "recruiter"], label="I am writing to my...")
|
| 81 |
recipient_name = gr.Textbox(label="Recipient Name", placeholder = "Their name is...")
|
| 82 |
|
| 83 |
|
| 84 |
-
subject = gr.Dropdown([ "Requesting a meeting", "
|
| 85 |
-
dates = gr.Textbox(label="Relevant Dates", placeholder ="MM/DD/YYYY")
|
| 86 |
email = gr.Textbox(label="Input", lines=10, placeholder="Enter your Message Here!")
|
| 87 |
-
model_id = gr.Dropdown(["GPT-3", "
|
| 88 |
-
|
| 89 |
submit_button = gr.Button("Generate my email!")
|
| 90 |
text_output = gr.Textbox(lines=10, label = "Email", placeholder = "Your generated email!", interactive = True)
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
submit_button.click(pre_query, inputs = input_list, outputs=text_output)
|
| 95 |
-
|
| 96 |
-
demo.launch(debug=True)
|
|
|
|
| 30 |
response = requests.request("POST", API_URL, json=payload)
|
| 31 |
return response.json()
|
| 32 |
|
| 33 |
+
def pre_query(sender, recipient, recipient_name, context, input, model_id):
|
| 34 |
API_URL = "https://api-inference.huggingface.co/models/" + model_id
|
| 35 |
|
| 36 |
+
if model_id == "bigscience/T0pp":
|
| 37 |
input_string = "Write a professional email to my " + recipient.lower() + " starting with Hello " + recipient_name + ", about the subject " + context + " and the email should be based on this draft: " + input
|
| 38 |
+
data = query(input_string, API_URL)
|
| 39 |
+
if type(data) is dict:
|
| 40 |
+
return data['error']
|
| 41 |
+
else:
|
| 42 |
+
return data[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
if model_id == "bigscience/bloom":
|
| 45 |
input_string = "Write a professional email to my " + recipient.lower() + " starting with Hello " + recipient_name + ", about the subject " + context + " and the email should be based on this draft: " + input + ": Hello " + recipient_name + ",\n\n"
|
| 46 |
data = query({
|
| 47 |
"inputs":input_string,
|
| 48 |
"parameters":{"max_new_tokens":96,
|
| 49 |
+
"return_full_text": False}
|
|
|
|
| 50 |
}, API_URL)
|
| 51 |
+
if type(data) is dict:
|
| 52 |
+
return data['error']
|
| 53 |
+
else:
|
| 54 |
+
return "Hello " + recipient_name + ",\n\n" + data[0]['generated_text'].replace(input_string,'')
|
| 55 |
+
|
| 56 |
+
if model_id == "EleutherAI/gpt-neo-2.7B":
|
| 57 |
+
input_string = "Write a professional email to my " + recipient + " starting with Hello " + recipient_name + ", about the subject " + context + " and the email should be based on this draft: " + input
|
| 58 |
+
data = query(input_string, API_URL)
|
| 59 |
+
|
| 60 |
+
if type(data) is dict:
|
| 61 |
+
return data['error']
|
| 62 |
+
else:
|
| 63 |
+
return data[0]['generated_text']
|
| 64 |
|
| 65 |
if model_id == "GPT-3":
|
| 66 |
return openai_query(recipient, 250, recipient_name, context, input)
|
| 67 |
|
| 68 |
return
|
| 69 |
|
| 70 |
+
def set_email_link(email, recipient_address, subject):
|
| 71 |
+
email = email.replace(' ', '%20')
|
| 72 |
+
link = "<a href=\"" + "mailto:" + recipient_address + "?subject=" + subject.replace(' ', '%20') + "&body=" + email.replace('\n', '%0A') + "\">" + "<button class=\"gr-button-lg gr-button-secondary self-start\">Link generated!<br>Click here</button></a>"
|
| 73 |
+
return link
|
| 74 |
+
|
| 75 |
+
#def set_email_link_html():
|
| 76 |
+
|
| 77 |
demo = gr.Blocks()
|
| 78 |
|
| 79 |
with demo:
|
|
|
|
| 86 |
with gr.Column():
|
| 87 |
with gr.Group():
|
| 88 |
with gr.Row():
|
| 89 |
+
sender = gr.Dropdown(["student", "professor", "employee", "employer", "coworker", "applicant", "recruiter"], label="From", placeholder="I am a...")
|
| 90 |
+
recipient = gr.Dropdown(["student", "professor", "employee", "employer", "coworker", "applicant", "recruiter"], label="Recipient", placeholder="I am sending to my...")
|
|
|
|
| 91 |
recipient_name = gr.Textbox(label="Recipient Name", placeholder = "Their name is...")
|
| 92 |
|
| 93 |
|
| 94 |
+
subject = gr.Dropdown([ "Requesting a meeting", "Conflict with scheduled meeting time", "Requesting clarification", "Requesting to leave early", "Requesting a leave of absence", "Requesting a letter of recommendation", "Requesting a referral for a job application"], label= "Subject/Context")
|
|
|
|
| 95 |
email = gr.Textbox(label="Input", lines=10, placeholder="Enter your Message Here!")
|
| 96 |
+
model_id = gr.Dropdown(["GPT-3", "bigscience/T0pp", "bigscience/bloom", "EleutherAI/gpt-neo-2.7B"] ,label = "model_id")
|
|
|
|
| 97 |
submit_button = gr.Button("Generate my email!")
|
| 98 |
text_output = gr.Textbox(lines=10, label = "Email", placeholder = "Your generated email!", interactive = True)
|
| 99 |
|
| 100 |
+
with gr.Row():
|
| 101 |
+
recipient_address = gr.Textbox(label="To", placeholder ="recipient's address")
|
| 102 |
+
link = gr.HTML("<p>Link not generated</p>")
|
| 103 |
+
send_email = gr.Button("Send my email!")
|
| 104 |
|
| 105 |
+
input_list = [sender, recipient, recipient_name, subject, email, model_id]
|
| 106 |
+
|
| 107 |
+
#email_link.change(set_email_link_html, inputs = email_link, outputs=link)
|
| 108 |
submit_button.click(pre_query, inputs = input_list, outputs=text_output)
|
| 109 |
+
send_email.click(set_email_link, inputs = [text_output, recipient_address, subject], outputs = link)
|
| 110 |
+
demo.launch(debug=True)
|