Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
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 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
Email:
|
68 |
"""
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
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():
|