import openai import gradio as gr import os open_ai_key = os.environ["open_ai_key"] openai.api_key = open_ai_key def openai_chat(prompt): completion = openai.completions.create( model="text-davinci-003", prompt=prompt, max_tokens=2048, temperature=0.5, top_p=1, frequency_penalty=0, presence_penalty=0 ) message = completion.choices[0].text return message.strip() def build_type_1(content_url, Email_Type, industry,job_role,prospect_context): return f"Write a {Email_Type} email to sell Bluemetra solutions to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} and is relevant for job {job_role}" def build_type_2(content_url, Email_Type, industry,job_role,prospect_context): return f"Write a {Email_Type} email to sell Bluemetra solutions to a prospect in {industry} based on their information extracted from {prospect_context} by analyzing and summarizing this content {content_url} and is relevant for job {job_role}.Start with congratulating {job_role} for the new role" def call_email(Email_Type,industry,content_url,job_role_change, job_role,prospect_context, history=[]): if job_role_change=="Yes": input_agg = build_type_2(content_url,Email_Type, industry,job_role,prospect_context) elif job_role_change=="No": input_agg = build_type_1(content_url,Email_Type, industry,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"],value="First Touch"),"text","text",gr.Dropdown(["Yes", "No"],value="No"),"text",'text','state'], outputs = ["chatbot",'state']).launch(debug = True) gr.launch(share=True)