curiousgeorge1292 commited on
Commit
3cc3c22
·
verified ·
1 Parent(s): 20d517d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -13
app.py CHANGED
@@ -3,10 +3,38 @@ import requests
3
  from bs4 import BeautifulSoup
4
  import gradio as gr
5
  from groq import Groq
 
 
6
 
7
  # Initialize Groq client
8
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Function to extract content from a URL
11
  def extract_content(url):
12
  try:
@@ -36,7 +64,7 @@ def fetch_linkedin_insights(profile_url):
36
  return f"Error fetching LinkedIn insights: {str(e)}"
37
 
38
  # Function to generate email using Llama
39
- def generate_email(name, linkedin_url, website_url, context_url, word_count):
40
  # Fetch insights from LinkedIn and reference URLs
41
  linkedin_insights = fetch_linkedin_insights(linkedin_url)
42
  website_content = extract_content(website_url)
@@ -45,20 +73,23 @@ def generate_email(name, linkedin_url, website_url, context_url, word_count):
45
  # Fetch details from AdTech company website
46
  adtech_content = extract_content("https://www.abcd.com")
47
 
 
 
 
 
 
 
48
  # Construct the prompt for Llama
49
  prompt = f"""
50
- You are an AI assistant helping an AdTech company draft personalized sales emails.
51
  Here are the details of the prospect:
52
  - Name: {name}
53
  - LinkedIn Insights: {linkedin_insights}
54
  - Website Content: {website_content}
55
  - Additional Context: {context_content}
56
-
57
  The company provides the following offerings:
58
  {adtech_content}
59
-
60
- Draft a personalized email addressing the prospect's specific needs and pain points.
61
- Focus on highlighting only relevant solutions from the company offerings.
62
  Ensure the email is professional, engaging, and stays within {word_count} words (5-10% flexibility).
63
  Output the email in HTML format.
64
  """
@@ -74,11 +105,28 @@ def generate_email(name, linkedin_url, website_url, context_url, word_count):
74
  except Exception as e:
75
  return f"Error generating email: {str(e)}"
76
 
77
- # Gradio Interface
78
- def email_agent(name, linkedin_url, website_url, context_url, word_count):
79
- return "<div style='font-style: italic;'>Hold on tight, your personalized email is on the way...</div>", generate_email(name, linkedin_url, website_url, context_url, word_count)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
- iface = gr.Interface(
82
  fn=email_agent,
83
  inputs=[
84
  gr.Textbox(label="Prospect's Name"),
@@ -86,13 +134,16 @@ iface = gr.Interface(
86
  gr.Textbox(label="Publishing Website URL"),
87
  gr.Textbox(label="Additional Context URL (optional)"),
88
  gr.Slider(label="Email Length (words)", minimum=150, maximum=500, step=10, value=300),
 
89
  ],
90
  outputs=[
91
  gr.HTML(label="Status"),
92
  gr.HTML(label="Generated Email")
93
  ],
94
- title="Personalized Email Agent",
95
- description="Generate highly personalized sales emails for AdTech prospects."
96
  )
97
 
98
- iface.launch(share=True)
 
 
 
3
  from bs4 import BeautifulSoup
4
  import gradio as gr
5
  from groq import Groq
6
+ from googleapiclient.discovery import build
7
+ from google.oauth2.service_account import Credentials
8
 
9
  # Initialize Groq client
10
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
11
 
12
+ # Google Sheets setup
13
+ SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
14
+ SERVICE_ACCOUNT_FILE = 'path_to_service_account.json' # Update with your service account file path
15
+ SPREADSHEET_ID = 'your_google_sheet_id' # Update with your Google Sheet ID
16
+
17
+ credentials = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
18
+ service = build('sheets', 'v4', credentials=credentials)
19
+ sheet = service.spreadsheets()
20
+
21
+ # Save user information to Google Sheets
22
+ def save_user_info(name, email, title, industry, target_audience, personal_background, company_background):
23
+ data = [[name, email, title, industry, target_audience, personal_background, company_background]]
24
+ sheet.values().append(
25
+ spreadsheetId=SPREADSHEET_ID,
26
+ range="Sheet1!A2", # Assuming headers are in row 1
27
+ valueInputOption="RAW",
28
+ insertDataOption="INSERT_ROWS",
29
+ body={"values": data}
30
+ ).execute()
31
+ return "User information saved successfully!"
32
+
33
+ # Step 1: User profile management UI
34
+ def user_profile(name, email, title, industry, target_audience, personal_background, company_background):
35
+ save_user_info(name, email, title, industry, target_audience, personal_background, company_background)
36
+ return "Your information has been saved! Proceed to Step 2 for email generation."
37
+
38
  # Function to extract content from a URL
39
  def extract_content(url):
40
  try:
 
64
  return f"Error fetching LinkedIn insights: {str(e)}"
65
 
66
  # Function to generate email using Llama
67
+ def generate_email(name, linkedin_url, website_url, context_url, word_count, email_purpose):
68
  # Fetch insights from LinkedIn and reference URLs
69
  linkedin_insights = fetch_linkedin_insights(linkedin_url)
70
  website_content = extract_content(website_url)
 
73
  # Fetch details from AdTech company website
74
  adtech_content = extract_content("https://www.abcd.com")
75
 
76
+ # Adjust prompt based on email purpose
77
+ purpose_prompt = {
78
+ "Job Application": "Draft a job application email tailored to the prospect's company and position.",
79
+ "Sales Cold Email": "Draft a sales email focusing on the prospect's specific needs and how our solutions can help."
80
+ }.get(email_purpose, "")
81
+
82
  # Construct the prompt for Llama
83
  prompt = f"""
84
+ You are an AI assistant helping an AdTech company draft personalized emails.
85
  Here are the details of the prospect:
86
  - Name: {name}
87
  - LinkedIn Insights: {linkedin_insights}
88
  - Website Content: {website_content}
89
  - Additional Context: {context_content}
 
90
  The company provides the following offerings:
91
  {adtech_content}
92
+ {purpose_prompt}
 
 
93
  Ensure the email is professional, engaging, and stays within {word_count} words (5-10% flexibility).
94
  Output the email in HTML format.
95
  """
 
105
  except Exception as e:
106
  return f"Error generating email: {str(e)}"
107
 
108
+ # Step 2: Email generation UI
109
+ def email_agent(name, linkedin_url, website_url, context_url, word_count, email_purpose):
110
+ return "<div style='font-style: italic;'>Hold on tight, your personalized email is on the way...</div>", generate_email(name, linkedin_url, website_url, context_url, word_count, email_purpose)
111
+
112
+ # Gradio Interfaces
113
+ profile_iface = gr.Interface(
114
+ fn=user_profile,
115
+ inputs=[
116
+ gr.Textbox(label="Your Name"),
117
+ gr.Textbox(label="Your Email ID"),
118
+ gr.Textbox(label="Professional Title"),
119
+ gr.Textbox(label="Industry"),
120
+ gr.Textbox(label="Target Audience"),
121
+ gr.Textbox(label="Personal Background"),
122
+ gr.Textbox(label="Company Background"),
123
+ ],
124
+ outputs="text",
125
+ title="Step 1: User Profile",
126
+ description="Enter and save your personal and company information."
127
+ )
128
 
129
+ email_iface = gr.Interface(
130
  fn=email_agent,
131
  inputs=[
132
  gr.Textbox(label="Prospect's Name"),
 
134
  gr.Textbox(label="Publishing Website URL"),
135
  gr.Textbox(label="Additional Context URL (optional)"),
136
  gr.Slider(label="Email Length (words)", minimum=150, maximum=500, step=10, value=300),
137
+ gr.Dropdown(label="Email Purpose", choices=["Job Application", "Sales Cold Email"], value="Sales Cold Email")
138
  ],
139
  outputs=[
140
  gr.HTML(label="Status"),
141
  gr.HTML(label="Generated Email")
142
  ],
143
+ title="Step 2: Email Generation",
144
+ description="Generate highly personalized emails for your specific purpose."
145
  )
146
 
147
+ # Combine steps into one Gradio app
148
+ app = gr.TabbedInterface([profile_iface, email_iface], ["Step 1: Profile", "Step 2: Email Generation"])
149
+ app.launch(share=True)