File size: 3,501 Bytes
96e9b7a
6214ba1
 
e091a20
 
f9294e5
6214ba1
f2eadbf
6214ba1
 
 
 
 
 
 
 
 
 
 
 
 
852919f
 
9fe5891
852919f
 
9fe5891
852919f
 
9fe5891
852919f
 
09efc0e
852919f
80962ea
852919f
 
80962ea
852919f
80962ea
852919f
 
80962ea
852919f
6214ba1
 
 
852919f
6214ba1
 
80962ea
9fe5891
5de2060
5d4e23f
0c5aa39
fdcf821
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

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)