Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_completion_messages(messages, model="gpt-3.5-turbo", temperature=0, max_tokens =500, presence_penalty=0, seed =None, stream=False):
|
| 9 |
+
response = openai.chat.completions.create(
|
| 10 |
+
model=model,
|
| 11 |
+
messages=messages,
|
| 12 |
+
temperature=temperature,
|
| 13 |
+
max_tokens=max_tokens,
|
| 14 |
+
presence_penalty=presence_penalty,
|
| 15 |
+
seed=seed,
|
| 16 |
+
stream = stream
|
| 17 |
+
|
| 18 |
+
)
|
| 19 |
+
return response.choices[0].message.content
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
delimiter = "####"
|
| 23 |
+
AV_system_message = f"""
|
| 24 |
+
You are Anu Madan, the learning solutions Manager at Analytics Vidhya, an ed-tech platform for Data Science, AI, and Generative AI.\
|
| 25 |
+
You focus on business development for clients in the US.
|
| 26 |
+
You will be provided with email chains between you and potential customers. \
|
| 27 |
+
The emails will be delimited with \
|
| 28 |
+
{delimiter} characters.
|
| 29 |
+
|
| 30 |
+
You have to perform the following tasks by going through the emails.\
|
| 31 |
+
1. Classify the email into a category.
|
| 32 |
+
2. Share information about the prospective client such as name, designation, and company.
|
| 33 |
+
3. Mention the date of last communication with the client
|
| 34 |
+
4. Share the sentiment of the last email shared by the prospective client.
|
| 35 |
+
5. Write a suitable email reply for the last email of the prospective client, which increases the chances of closing a deal
|
| 36 |
+
|
| 37 |
+
Provide your output in JSON format with the keys: Category, Client Info, Last comm from client, Sentiment of last comm and Email reply
|
| 38 |
+
|
| 39 |
+
Here are the Categories for the first task: Corporate Training, Enterprise Plans or Hackathon.
|
| 40 |
+
|
| 41 |
+
Corporate Training refers to customised training plans developed for companies. The trainings could be either\
|
| 42 |
+
In-Person - Instructor led, Online instructor led or hybrid.
|
| 43 |
+
|
| 44 |
+
Enterprise Plans refers to subscription plans for enterprises wherein they could purchase licenses of \
|
| 45 |
+
different self paced courses for their employees.\
|
| 46 |
+
There are three kinds of enterprise plans: Blackbelt, Generative AI Pinnalce or Customised \
|
| 47 |
+
The Blackbelt plan focusses on data analytics, data science and machine learning courses starting from \
|
| 48 |
+
excel, python, EDA, stats and going all the way Natural language processing.\
|
| 49 |
+
The Pinnacle plan has courses related to0 generative AI starting from basics of LLMs, finetuning and training LLMs and \
|
| 50 |
+
going till RAGs, Agents and LLMOps.\
|
| 51 |
+
The customised plan is a mix of these which could have a mix of courses from both the plans.
|
| 52 |
+
|
| 53 |
+
Hackathon refers to Machine Learning or Generatifve AI hackathons, which Analytics Vidhya \
|
| 54 |
+
organises for companies. The companies do it for either Hiring candidates or Branding or a mix of both.
|
| 55 |
+
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def email_replier(prompt):
|
| 61 |
+
messages = [
|
| 62 |
+
{'role':'system',
|
| 63 |
+
'content': AV_system_message},
|
| 64 |
+
{'role':'user',
|
| 65 |
+
'content': f"{delimiter}{prompt}{delimiter}"},
|
| 66 |
+
]
|
| 67 |
+
response = get_completion_messages(messages)
|
| 68 |
+
res = json.loads(response)
|
| 69 |
+
return res['Category'], res['Client Info'], res[ "Last comm from client"], res["Sentiment of last comm"], res["Email reply"]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
demo = gr.Interface(fn=email_replier,
|
| 74 |
+
inputs=[gr.Textbox(label="Email Chain", lines=10)],
|
| 75 |
+
outputs=[gr.Textbox(label="Category", lines = 1), gr.Textbox(label="Client Info", lines = 3), gr.Textbox(label="Last Comm from client", lines = 1),
|
| 76 |
+
gr.Textbox(label="Sentiment", lines = 1), gr.Textbox(label="Email Reply", lines = 5)],
|
| 77 |
+
title="Buisness Email Replier",
|
| 78 |
+
description= "Use your own judgement to modify the email")
|
| 79 |
+
demo.launch()
|