Email / app.py
Sibanjan's picture
Update app.py
852919f
raw
history blame contribute delete
No virus
3.5 kB
import openai
import gradio as gr
import os
open_ai_key = os.environ["open_ai_key"]
openai.api_key = open_ai_key # Replace this with your API key: https://beta.openai.com/docs/quickstart/add-your-api-key
def openai_chat(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip()
def build_type_1(content_url, Email_Type, industry,theme, keywords,job_role,prospect_context):
return f"Write a {Email_Type} email to sell servicenow product to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} around {keywords} focusing on {theme} and is relevant for job {job_role}"
def build_type_2(content_url, Email_Type, industry,theme, keywords,job_role,prospect_context):
return f"Write a {Email_Type} email to sell servicenow product to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} around {keywords} focusing on {theme} and is relevant for job {job_role}.Start with congratulating {job_role} for the new role"
def build_prod_upgrade_yes(content_url, Email_Type, industry,theme, keywords,job_role,prospect_context):
return f"Write a {Email_Type} email to inform on new product update for servicenow to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} around {keywords} focusing on {theme} and is relevant for job {job_role}.Start with congratulating {job_role} for the new role"
def build_prod_upgrade_no(content_url, Email_Type, industry,theme, keywords,job_role,prospect_context):
return f"Write a {Email_Type} email to inform on new product update for servicenow to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} around {keywords} focusing on {theme} and is relevant for job {job_role}."
def call_email(Email_Type,industry,keywords, theme, content_url,job_role_change, job_role,prospect_context, history=[]):
if job_role_change=="Yes":
if Email_Type=="Product Upgrade Communication":
input_agg = build_prod_upgrade_yes(content_url,Email_Type, industry,theme, keywords, job_role,prospect_context)
else:
input_agg = build_type_2(content_url,Email_Type, industry,theme, keywords, job_role,prospect_context)
elif job_role_change=="No":
if Email_Type=="Product Upgrade Communication":
input_agg = build_prod_upgrade_no(content_url,Email_Type, industry,theme, keywords, job_role,prospect_context)
else:
input_agg = build_type_1(content_url,Email_Type, industry,theme, keywords, job_role,prospect_context)
print(input_agg)
output = openai_chat(input_agg)
history=[]
history.append((Email_Type, output))
return history, history
gr.Interface(fn = call_email,
inputs = [gr.Radio(["First Touch", "Persuasive", "Followup","Event Invitation","New Launch Communication", "Product Upgrade Communication"],value="First Touch"),"text","text","text","text",gr.Dropdown(["Yes", "No"],value="No"),"text",'text','state'],
outputs = ["chatbot",'state']).launch(debug = True)
gr.launch(share=True)