abhilashnl2006 commited on
Commit
5f687f6
·
verified ·
1 Parent(s): fc0ebd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -48,31 +48,51 @@ def generate_text(prompt):
48
  logger.error(f"Error in generate_text: {type(e).__name__}: {str(e)}")
49
  return f"An error occurred: {type(e).__name__}: {str(e)}"
50
 
 
 
 
 
 
 
 
51
  def generate_email(industry, recipient_role, company_details):
52
  try:
53
- logger.info(f"Generating email for {industry}, {recipient_role}")
54
- prompt = f"""Write a professional cold outreach email using the following details:
55
  Industry: {industry}
56
  Recipient Role: {recipient_role}
57
  Company Details: {company_details}
58
 
59
- The email should:
60
- 1. Have a clear and concise subject line
61
- 2. Start with a personalized greeting
62
- 3. Briefly introduce yourself and your company
63
- 4. Explain the value proposition relevant to the recipient's industry and role
64
- 5. Include a clear call to action
65
- 6. End with a professional closing
 
 
 
 
 
 
 
 
 
 
66
 
67
  Email:
68
  """
69
- response = generate_text(prompt)
70
- if isinstance(response, str) and response.startswith("An error occurred:"):
71
- logger.error(f"Error response from generate_text: {response}")
72
- return "I apologize, but I'm currently unable to generate an email. There might be an issue with the AI model access. Please try again later or contact support."
73
- return response
 
 
 
 
74
  except Exception as e:
75
- logger.error(f"Error in generate_email: {str(e)}")
76
  return "I apologize, but an unexpected error occurred. Please try again later or contact support."
77
 
78
  def test_model_connection():
 
48
  logger.error(f"Error in generate_text: {type(e).__name__}: {str(e)}")
49
  return f"An error occurred: {type(e).__name__}: {str(e)}"
50
 
51
+ try:
52
+ generator = pipeline('text-generation', model=model_name)
53
+ logger.info(f"Successfully loaded model: {model_name}")
54
+ except Exception as e:
55
+ logger.error(f"Failed to load model: {type(e).__name__}: {str(e)}")
56
+ raise
57
+
58
  def generate_email(industry, recipient_role, company_details):
59
  try:
60
+ prompt = f"""Generate a professional cold outreach email using the following details:
 
61
  Industry: {industry}
62
  Recipient Role: {recipient_role}
63
  Company Details: {company_details}
64
 
65
+ Format the email as follows:
66
+ Subject: [Insert catchy subject line related to the industry and recipient role]
67
+
68
+ Dear [Recipient's Name],
69
+
70
+ [Introduction paragraph: Briefly introduce yourself and your company]
71
+
72
+ [Value proposition paragraph: Explain how your company can benefit the recipient, citing specific details from the company information]
73
+
74
+ [Call to action paragraph: Suggest a meeting or call to discuss further]
75
+
76
+ [Closing paragraph: Thank the recipient and provide your contact information]
77
+
78
+ Best regards,
79
+ [Your Name]
80
+ [Your Title]
81
+ [Your Company]
82
 
83
  Email:
84
  """
85
+
86
+ response = generator(prompt, max_length=800, num_return_sequences=1, temperature=0.7)
87
+ generated_text = response[0]['generated_text']
88
+
89
+ # Remove the prompt from the generated text
90
+ email_content = generated_text[generated_text.find("Subject:"):].strip()
91
+
92
+ logger.info(f"Generated email for {industry}, {recipient_role}")
93
+ return email_content
94
  except Exception as e:
95
+ logger.error(f"Error in generate_email: {type(e).__name__}: {str(e)}")
96
  return "I apologize, but an unexpected error occurred. Please try again later or contact support."
97
 
98
  def test_model_connection():