-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailcontent.py
More file actions
38 lines (29 loc) · 1.37 KB
/
emailcontent.py
File metadata and controls
38 lines (29 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import google.generativeai as genai
# Configure your Gemini API key
genai.configure(api_key="YOUR API")
def emailgenerator(prompt, receiver):
try:
model = genai.GenerativeModel("models/gemini-1.5-flash")
prompt_text = (
f"Write a professional, properly structured email to {receiver} "
f"about: {prompt}. Format it clearly with:\n"
f"- Subject line\n"
f"- A greeting (e.g., Dear Sir/Madam)\n"
f"- Separate, short paragraphs with line breaks\n"
f"- A formal closing\n"
f"- Include the sender’s full name and phone number at the end:\n"
f" Name: Furkan Khan\n"
f" Phone: +91-9871601543\n"
f"Ensure it looks like a real professional plain-text email."
)
response = model.generate_content(prompt_text)
# Extract and clean response
content = response.text.strip() if hasattr(response, 'text') else "No response from Gemini."
# Ensure clean formatting with proper newlines
formatted_content = "\n".join(line.strip() for line in content.split('\n') if line.strip())
print("🔍 Gemini formatted email:")
print(formatted_content)
return formatted_content
except Exception as e:
print(f"⚠️ Error generating email: {e}")
return "Error generating email."