curiousgeorge1292 commited on
Commit
2455f1a
·
verified ·
1 Parent(s): bf42e45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -12,7 +12,7 @@ from google_auth_oauthlib.flow import Flow
12
  import base64
13
 
14
  # Flask app setup
15
- app = Flask(__name__)
16
  app.secret_key = os.environ.get("FLASK_SECRET_KEY")
17
  REDIRECT_URI = "https://huggingface.co/spaces/curiousgeorge1292/Custom_Profile_Email_Generator/oauth2callback"
18
  GMAIL_SCOPES = ["https://www.googleapis.com/auth/gmail.compose"]
@@ -58,6 +58,13 @@ def oauth2callback():
58
  }
59
  return "Authorization successful. You can now save emails to Gmail drafts"
60
 
 
 
 
 
 
 
 
61
 
62
  @app.route('/check_credentials')
63
  def check_credentials():
@@ -279,19 +286,14 @@ def generate_email(name, email, prospect_name, linkedin_url, website_url, contex
279
  return f"Error generating email: {str(e)}"
280
 
281
  # Step 2: Email generation UI
282
- def email_agent(name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background):
283
 
284
  try:
285
  # Generate the email content
286
  email_content = generate_email(name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background)
287
 
288
  # Save to Gmail drafts
289
- try:
290
- if 'credentials' not in session:
291
- raise ValueError("Credentials not found. Please authorize first.")
292
-
293
- credentials_info = session['credentials']
294
-
295
  save_to_gmail_drafts(credentials_info,
296
  subject="Generated Email Subject",
297
  body=email_content,
@@ -400,9 +402,12 @@ with gr.Blocks() as ui:
400
  generated_email = gr.HTML(label="Generated Email")
401
 
402
  email_button.click(
403
- email_agent,
404
- inputs=[
 
405
  name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background
 
 
406
  ],
407
  outputs=[email_status, generated_email]
408
  )
 
12
  import base64
13
 
14
  # Flask app setup
15
+ app = flask.Flask(__name__)
16
  app.secret_key = os.environ.get("FLASK_SECRET_KEY")
17
  REDIRECT_URI = "https://huggingface.co/spaces/curiousgeorge1292/Custom_Profile_Email_Generator/oauth2callback"
18
  GMAIL_SCOPES = ["https://www.googleapis.com/auth/gmail.compose"]
 
58
  }
59
  return "Authorization successful. You can now save emails to Gmail drafts"
60
 
61
+ @app.route('/authenticate_gmail')
62
+ def authenticate_gmail():
63
+ # Gmail OAuth2 logic here
64
+ # After successful authentication:
65
+ credentials = get_credentials_from_oauth() # Replace with actual method
66
+ session['credentials'] = credentials
67
+ return "Authentication successful!"
68
 
69
  @app.route('/check_credentials')
70
  def check_credentials():
 
286
  return f"Error generating email: {str(e)}"
287
 
288
  # Step 2: Email generation UI
289
+ def email_agent(credentials_info, name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background):
290
 
291
  try:
292
  # Generate the email content
293
  email_content = generate_email(name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background)
294
 
295
  # Save to Gmail drafts
296
+ try:
 
 
 
 
 
297
  save_to_gmail_drafts(credentials_info,
298
  subject="Generated Email Subject",
299
  body=email_content,
 
402
  generated_email = gr.HTML(label="Generated Email")
403
 
404
  email_button.click(
405
+ lambda name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background: email_agent(
406
+ # Check and fetch credentials from Flask session
407
+ session.get('credentials'), # Securely fetch the credentials
408
  name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background
409
+ ) if session.get('credentials') else "Please authenticate with Gmail first.",
410
+ inputs=[name, email, prospect_name, linkedin_url, website_url, context_url, word_count, email_purpose, interested_position, company_url, professional_title, personal_background
411
  ],
412
  outputs=[email_status, generated_email]
413
  )