KneeKhan commited on
Commit
9d0d207
1 Parent(s): b77397f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -25
app.py CHANGED
@@ -18,7 +18,7 @@ def openai_query(
18
 
19
  return openai.Completion.create(
20
  engine='text-davinci-002',
21
- prompt="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,
22
  temperature = random_state,
23
  max_tokens= len,
24
  frequency_penalty=0.25,
@@ -26,18 +26,15 @@ def openai_query(
26
  best_of=1
27
  ).get("choices")[0]['text'].strip()
28
 
29
-
30
  def query(payload, API_URL):
31
- print()
32
  response = requests.request("POST", API_URL, json=payload)
33
  return response.json()
34
 
35
-
36
- def pre_query(model_id, context, input, dates, sender, recipient, recipient_name):
37
  API_URL = "https://api-inference.huggingface.co/models/" + model_id
38
 
39
  if model_id == "bigscience/T0pp":
40
- 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
41
  data = query(input_string, API_URL)
42
  if type(data) is dict:
43
  return data['error']
@@ -45,7 +42,7 @@ def pre_query(model_id, context, input, dates, sender, recipient, recipient_name
45
  return data[0]['generated_text']
46
 
47
  if model_id == "bigscience/bloom":
48
- 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 + ": Hello " + recipient_name + ",\n\n"
49
  data = query({
50
  "inputs":input_string,
51
  "parameters":{"max_new_tokens":96,
@@ -54,9 +51,9 @@ def pre_query(model_id, context, input, dates, sender, recipient, recipient_name
54
  if type(data) is dict:
55
  return data['error']
56
  else:
57
- return "Hello " + recipient_name + ",\n\n" + data[0]['generated_text'].replace(input_string,'')
58
-
59
- if model_id == "EleutherAI/gpt-neox-20b":
60
  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
61
  data = query(input_string, API_URL)
62
 
@@ -70,20 +67,31 @@ def pre_query(model_id, context, input, dates, sender, recipient, recipient_name
70
 
71
  return
72
 
73
- title = "Email Assistant"
74
 
75
- interface = gr.Interface(
76
- fn = pre_query,
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- inputs=[gr.Dropdown(["GPT-3", "bigscience/T0pp", "bigscience/bloom", "EleutherAI/gpt-neox-20b"] ,label = "model_id"),
79
- 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"),
80
- gr.Textbox(label="Input", lines=10, placeholder="Enter your Message Here!"),
81
- gr.Textbox(label="Relevant Dates", placeholder ="MM/DD/YYYY"),
82
- gr.Dropdown(["student", "employee", "applicant", "recruiter", "boss"], label="Sender"),
83
- gr.Dropdown(["professor", "supervisor", "coworker", "recruiter", "boss"], label="Recipient"),
84
- gr.Textbox(label="Recipient Name", placeholder = "George")],
85
-
86
- outputs=[gr.Textbox(lines=10, label = "Result")],
87
-
88
- title = title,
89
- ).launch(debug=True)
 
18
 
19
  return openai.Completion.create(
20
  engine='text-davinci-002',
21
+ prompt="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,
22
  temperature = random_state,
23
  max_tokens= len,
24
  frequency_penalty=0.25,
 
26
  best_of=1
27
  ).get("choices")[0]['text'].strip()
28
 
 
29
  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, sender, context, dates, 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']
 
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,
 
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
 
 
67
 
68
  return
69
 
70
+ demo = gr.Blocks()
71
 
72
+ with demo:
73
+ gr.Markdown(
74
+ """
75
+ # <center> Email Assistant
76
+ Please fill out the fields below!
77
+ """)
78
+ with gr.Row():
79
+ with gr.Column():
80
+ with gr.Group():
81
+ with gr.Row():
82
+ sender = gr.Dropdown(["student", "professor", "employee", "employer", "coworker", "applicant", "recruiter"], label="From", placeholder="I am a...")
83
+ recipient = gr.Dropdown(["student", "professor", "employee", "employer", "coworker", "applicant", "recruiter"], label="Recipient", placeholder="I am sending to my...")
84
+ recipient_name = gr.Textbox(label="Recipient Name", placeholder = "Their name is...")
85
 
86
+ 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")
87
+ dates = gr.Textbox(label="Relevant Dates", placeholder ="MM/DD/YYYY")
88
+ email = gr.Textbox(label="Input", lines=10, placeholder="Enter your Message Here!")
89
+ model_id = gr.Dropdown(["GPT-3", "bigscience/T0pp", "bigscience/bloom", "EleutherAI/gpt-neo-2.7B"] ,label = "model_id")
90
+ submit_button = gr.Button("Generate my email!")
91
+ text_output = gr.Textbox(lines=10, label = "Email", placeholder = "Your generated email!", interactive = True)
92
+
93
+ input_list = [sender, recipient, recipient_name, subject, dates, email, model_id]
94
+
95
+ submit_button.click(pre_query, inputs = input_list, outputs=text_output)
96
+
97
+ demo.launch(debug=True)