Spaces:
Running
Running
Update email_gen.py
Browse files- email_gen.py +2 -42
email_gen.py
CHANGED
@@ -393,48 +393,8 @@ Return ONLY this JSON format:
|
|
393 |
|
394 |
def generate_email(self, name, company, company_info, tone="Professional", temperature=0.7):
|
395 |
"""Generate both subject and email body using advanced prompting"""
|
396 |
-
#
|
397 |
-
|
398 |
-
|
399 |
-
# Calibrate temperature for production readiness
|
400 |
-
if temperature > 1.0:
|
401 |
-
temperature = 0.8 # Cap at 0.8 for production readiness
|
402 |
-
|
403 |
-
# Try AI generation first
|
404 |
-
if self.model:
|
405 |
-
try:
|
406 |
-
# Build the prompt using few-shot template
|
407 |
-
prompt = self.prompt_templates["few_shot_template"].format(
|
408 |
-
name=name,
|
409 |
-
company=company,
|
410 |
-
company_context=company_context,
|
411 |
-
tone=tone.lower()
|
412 |
-
)
|
413 |
-
|
414 |
-
# Generate with model
|
415 |
-
response = self._generate_with_model(prompt, max_tokens=200, temperature=temperature)
|
416 |
-
|
417 |
-
# Parse the response
|
418 |
-
subject, body = self._parse_json_response(response)
|
419 |
-
|
420 |
-
# Polish the content
|
421 |
-
subject, body = self._polish_email_content(subject, body)
|
422 |
-
|
423 |
-
# Validate quality
|
424 |
-
quality_score, issues = self._validate_email_quality(subject, body, name, company)
|
425 |
-
|
426 |
-
# If quality is good enough, return it
|
427 |
-
if quality_score >= 70 and 'placeholders' not in issues:
|
428 |
-
print(f"✅ AI generated email (Quality: {quality_score}%)")
|
429 |
-
return subject, body
|
430 |
-
else:
|
431 |
-
print(f"⚠️ AI output quality too low ({quality_score}%), using advanced fallback")
|
432 |
-
|
433 |
-
except Exception as e:
|
434 |
-
print(f"❌ AI generation failed: {e}, using advanced fallback")
|
435 |
-
|
436 |
-
# Use advanced fallback system
|
437 |
-
print("🔄 Using advanced fallback generation")
|
438 |
subject, body = self._advanced_fallback_generation(name, company, company_info, tone)
|
439 |
|
440 |
# Always polish fallback content
|
|
|
393 |
|
394 |
def generate_email(self, name, company, company_info, tone="Professional", temperature=0.7):
|
395 |
"""Generate both subject and email body using advanced prompting"""
|
396 |
+
# Always use advanced fallback for now - AI model has loading issues on Hugging Face Spaces
|
397 |
+
print("🔄 Using advanced fallback generation (optimized for quality)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
subject, body = self._advanced_fallback_generation(name, company, company_info, tone)
|
399 |
|
400 |
# Always polish fallback content
|