Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import json | |
| import time | |
| import requests | |
| # Nosey fucker arent you :) | |
| def email(linkedin_url, description_of_what_you_are_selling , description_of_who_you_are , type_of_email = "", calendly_link = ""): | |
| human_url = os.environ["HUMAN_URL"] | |
| model_url = os.environ["MODEL_URL"] | |
| if description_of_what_you_are_selling == "": | |
| description_of_what_you_are_selling = "Generai, a YCombinator startup building a flowchart tool to build ML aplications" | |
| if description_of_who_you_are == "": | |
| description_of_who_you_are = "Jan Schnyder, Co-Founder of Generai" | |
| data = { | |
| "api_key": os.environ["HUMAN_API_KEY"], | |
| "linkedin_url" : linkedin_url | |
| } | |
| headers = { | |
| 'Cache-Control': 'no-cache', | |
| 'Content-Type': 'application/json' | |
| } | |
| response = requests.request("POST", human_url, headers=headers, json=data) | |
| resp= json.loads(response.text) | |
| print(resp) | |
| print("the email is: " + str(resp["person"]["email"])) | |
| email_address = str(resp["person"]["email"]) | |
| # shorten the json if too long, otherwise 400 for openai | |
| if len(str(resp)) > 8000: | |
| resp = str(resp)[0:8000] | |
| # summarize | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer " + os.environ["MODEL_API_KEY"] | |
| } | |
| data = { | |
| "model": os.environ["MODEL_NAME"], | |
| "prompt": "summarize this json in a very detailed and readable paragraph describing the person. Dont include any ID or number combinations :" + str(resp), | |
| "temperature": 0, | |
| "max_tokens": 300 | |
| } | |
| response = requests.post(model_url, headers=headers, json=data) | |
| if response.status_code == 200: | |
| response_json = response.json() | |
| summary = response_json["choices"][0]["text"] | |
| else: | |
| print("Request failed with status code:", response.status_code) | |
| return "Request failed with status code:", response.status_code | |
| # write the mail | |
| 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. " | |
| if calendly_link != "": | |
| prompt = prompt + "The person can schedule a call here: " + str(calendly_link) | |
| data = { | |
| "model": os.environ["MODEL_NAME"], | |
| "prompt": prompt, | |
| "temperature": 0, | |
| "max_tokens": 300 | |
| } | |
| response = requests.post(model_url, headers=headers, json=data) | |
| if response.status_code == 200: | |
| response_json = response.json() | |
| text = response_json["choices"][0]["text"] | |
| print(text) | |
| else: | |
| print("Request failed with status code:", response.status_code) | |
| return "Request failed with status code:", response.status_code | |
| 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/" | |
| demo = gr.Interface( | |
| email, | |
| [ | |
| gr.Textbox(lines=1, label="LinkedIn URL"), | |
| gr.Textbox(lines=1, label="Description of what you are selling (Name, Product, Service))"), | |
| gr.Textbox(lines=1, label="Description of who you are (Name, Company, Position))"), | |
| gr.Textbox(lines=1, label="(Optional) Describe the style of the email (funny, formal, short, long))"), | |
| gr.Textbox(lines=1, label="(Optional) Add your Calendly link here") | |
| ], | |
| gr.Textbox(lines=15, placeholder="Name Here...", label="Output"), | |
| title="LinkedIn Email Generai-tor", | |
| description="From Linked in profile to personalized email in 1 click! API might be down sometimes. For questions team@generai.art", | |
| ) | |
| demo.launch() |