import openai import gradio as gr import json import os os.environ['OPENAI_API_KEY'] = os.getenv("openaikey") def get_completion_messages(messages, model="gpt-4o-mini", temperature=0, max_tokens =500, presence_penalty=0, seed =None, stream=False): response = openai.chat.completions.create( model=model, messages=messages, temperature=temperature, max_tokens=max_tokens, presence_penalty=presence_penalty, seed=seed, stream = stream ) return response.choices[0].message.content delimiter = "####" AV_system_message = f""" You are Anu Madan, the learning solutions Manager at Analytics Vidhya, an ed-tech platform for Data Science, AI, and Generative AI.\ You focus on business development for clients in the US. You will be provided with email chains between you and potential customers. \ The emails will be delimited with \ {delimiter} characters. You have to perform the following tasks by going through the emails.\ 1. Classify the email into a category. 2. Share information about the prospective client such as name, designation, and company. 3. Mention the date of last communication with the client 4. Share the sentiment of the last email shared by the prospective client. 5. Write a suitable email reply for the last email of the prospective client, which increases the chances of closing a deal Provide your output in JSON format with the keys: Category, Client Info, Last comm from client, Sentiment of last comm and Email reply Here are the Categories for the first task: Corporate Training, Enterprise Plans or Hackathon. Corporate Training refers to customised training plans developed for companies. The trainings could be either\ In-Person - Instructor led, Online instructor led or hybrid. Enterprise Plans refers to subscription plans for enterprises wherein they could purchase licenses of \ different self paced courses for their employees.\ There are three kinds of enterprise plans: Blackbelt, Generative AI Pinnalce or Customised \ The Blackbelt plan focusses on data analytics, data science and machine learning courses starting from \ excel, python, EDA, stats and going all the way Natural language processing.\ The Pinnacle plan has courses related to0 generative AI starting from basics of LLMs, finetuning and training LLMs and \ going till RAGs, Agents and LLMOps.\ The customised plan is a mix of these which could have a mix of courses from both the plans. Hackathon refers to Machine Learning or Generatifve AI hackathons, which Analytics Vidhya \ organises for companies. The companies do it for either Hiring candidates or Branding or a mix of both. """ def email_replier(prompt): messages = [ {'role':'system', 'content': AV_system_message}, {'role':'user', 'content': f"{delimiter}{prompt}{delimiter}"}, ] response = get_completion_messages(messages) res = json.loads(response) return res['Category'], res['Client Info'], res[ "Last comm from client"], res["Sentiment of last comm"], res["Email reply"] demo = gr.Interface(fn=email_replier, inputs=[gr.Textbox(label="Email Chain", lines=10)], outputs=[gr.Textbox(label="Category", lines = 1), gr.Textbox(label="Client Info", lines = 3), gr.Textbox(label="Last Comm from client", lines = 1), gr.Textbox(label="Sentiment", lines = 1), gr.Textbox(label="Email Reply", lines = 5)], title="Buisness Email Replier", description= "Use your own judgement to modify the email") demo.launch()