shnippi/Email_Generai-tor
3
1import gradio as gr2import os3import json4import time5import requests6 7# Nosey fucker arent you :)8 9def email(linkedin_url, description_of_what_you_are_selling , description_of_who_you_are , type_of_email = "", calendly_link = ""):10 11 human_url = os.environ["HUMAN_URL"]12 model_url = os.environ["MODEL_URL"]13 14 if description_of_what_you_are_selling == "":15 description_of_what_you_are_selling = "Generai, a YCombinator startup building a flowchart tool to build ML aplications"16 if description_of_who_you_are == "":17 description_of_who_you_are = "Jan Schnyder, Co-Founder of Generai"18 19 20 data = {21 "api_key": os.environ["HUMAN_API_KEY"],22 "linkedin_url" : linkedin_url23 }24 25 headers = {26 'Cache-Control': 'no-cache',27 'Content-Type': 'application/json'28 }29 30 response = requests.request("POST", human_url, headers=headers, json=data)31 resp= json.loads(response.text)32 33 print(resp)34 print("the email is: " + str(resp["person"]["email"]))35 36 37 email_address = str(resp["person"]["email"])38 39 # shorten the json if too long, otherwise 400 for openai40 if len(str(resp)) > 8000:41 resp = str(resp)[0:8000]42 43 44 # summarize45 46 headers = {47 "Content-Type": "application/json",48 "Authorization": "Bearer " + os.environ["MODEL_API_KEY"]49 }50 51 data = {52 "model": os.environ["MODEL_NAME"],53 "prompt": "summarize this json in a very detailed and readable paragraph describing the person. Dont include any ID or number combinations :" + str(resp),54 "temperature": 0,55 "max_tokens": 30056 }57 58 response = requests.post(model_url, headers=headers, json=data)59 60 if response.status_code == 200:61 response_json = response.json()62 summary = response_json["choices"][0]["text"]63 else:64 print("Request failed with status code:", response.status_code)65 return "Request failed with status code:", response.status_code66 67 68 # write the mail69 70 prompt = "now write me a " + type_of_email + " cold outreach email to this person that is highly personalized with the following information: " + summary + ". \n The email should be about selling " + description_of_what_you_are_selling + "The email is from " + description_of_who_you_are + " . Don't use placeholders. "71 72 if calendly_link != "":73 prompt = prompt + "The person can schedule a call here: " + str(calendly_link)74 75 data = {76 "model": os.environ["MODEL_NAME"],77 "prompt": prompt,78 "temperature": 0,79 "max_tokens": 30080 }81 82 response = requests.post(model_url, headers=headers, json=data)83 84 if response.status_code == 200:85 response_json = response.json()86 text = response_json["choices"][0]["text"]87 print(text)88 else:89 print("Request failed with status code:", response.status_code)90 return "Request failed with status code:", response.status_code91 92 return "email address: \n" + email_address + " \n\n" + text + " \n\n- " + "P.S: This email was generated using our tool ;) , built with " + "https://flow.generai.art/"93 94demo = gr.Interface(95 email,96 [97 gr.Textbox(lines=1, label="LinkedIn URL"),98 gr.Textbox(lines=1, label="Description of what you are selling (Name, Product, Service))"),99 gr.Textbox(lines=1, label="Description of who you are (Name, Company, Position))"),100 gr.Textbox(lines=1, label="(Optional) Describe the style of the email (funny, formal, short, long))"),101 gr.Textbox(lines=1, label="(Optional) Add your Calendly link here")102 ],103 gr.Textbox(lines=15, placeholder="Name Here...", label="Output"),104 title="LinkedIn Email Generai-tor",105 description="From Linked in profile to personalized email in 1 click! API might be down sometimes. For questions team@generai.art",106)107demo.launch()