Spaces:
Sleeping
Sleeping
abhlash
commited on
Commit
·
0979a5b
1
Parent(s):
924bd16
updated app
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from dotenv import load_dotenv
|
|
| 5 |
import logging
|
| 6 |
import sys # Ensure sys is imported
|
| 7 |
from huggingface_hub import login, HfApi
|
|
|
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
load_dotenv()
|
|
@@ -51,41 +52,42 @@ except Exception as e:
|
|
| 51 |
# Function to generate a formatted email
|
| 52 |
def generate_email(recipient_name, recipient_email, industry, recipient_role, details):
|
| 53 |
prompt = (
|
| 54 |
-
f"Write a
|
| 55 |
-
f"
|
| 56 |
-
"
|
| 57 |
)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
Albertsons
|
| 86 |
-
[Your Contact Information]
|
| 87 |
"""
|
| 88 |
-
|
| 89 |
|
| 90 |
# Create Gradio interface
|
| 91 |
iface = gr.Interface(
|
|
|
|
| 5 |
import logging
|
| 6 |
import sys # Ensure sys is imported
|
| 7 |
from huggingface_hub import login, HfApi
|
| 8 |
+
import torch
|
| 9 |
|
| 10 |
# Load environment variables
|
| 11 |
load_dotenv()
|
|
|
|
| 52 |
# Function to generate a formatted email
|
| 53 |
def generate_email(recipient_name, recipient_email, industry, recipient_role, details):
|
| 54 |
prompt = (
|
| 55 |
+
f"Write a short professional email to {recipient_name}, "
|
| 56 |
+
f"a {recipient_role} in the {industry} industry. "
|
| 57 |
+
f"Mention: {details}. Keep it under 100 words."
|
| 58 |
)
|
| 59 |
+
try:
|
| 60 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 61 |
+
|
| 62 |
+
# Check if we're using CPU or GPU
|
| 63 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 64 |
+
model.to(device)
|
| 65 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 66 |
+
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
outputs = model.generate(
|
| 69 |
+
**inputs,
|
| 70 |
+
max_length=200, # Reduced max length
|
| 71 |
+
num_return_sequences=1,
|
| 72 |
+
temperature=0.7,
|
| 73 |
+
top_k=50,
|
| 74 |
+
top_p=0.95,
|
| 75 |
+
do_sample=True
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
email_body = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 79 |
+
logging.info(f"Generated raw email body: {email_body}")
|
| 80 |
|
| 81 |
+
# Minimal cleaning
|
| 82 |
+
email_body = email_body.strip()
|
| 83 |
+
if not email_body:
|
| 84 |
+
raise ValueError("Generated email body is empty")
|
| 85 |
|
| 86 |
+
# Format the email
|
| 87 |
+
formatted_email = f"""\
|
| 88 |
+
To: {recipient_name}
|
|
|
|
|
|
|
| 89 |
"""
|
| 90 |
+
return formatted_email
|
| 91 |
|
| 92 |
# Create Gradio interface
|
| 93 |
iface = gr.Interface(
|