siddhartharya commited on
Commit
656c777
·
verified ·
1 Parent(s): 8b6b365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -112,15 +112,15 @@ class AutonomousEmailAgent:
112
  return "Error: Unable to generate response."
113
 
114
  def format_email(self, llm_response):
115
- # Clean and format the email into paragraphs
116
  paragraphs = [line.strip() for line in llm_response.split("\n") if line.strip()]
117
  formatted_email = "\n\n".join(paragraphs)
118
 
119
- # Truncate the email if it exceeds the word limit
120
  words = formatted_email.split()
121
  if len(words) > self.word_limit:
122
- truncated_email = " ".join(words[:self.word_limit]) + "..."
123
- formatted_email = truncated_email
124
 
125
  # Add the closing section with a call to action
126
  closing_section = (
@@ -138,11 +138,11 @@ class AutonomousEmailAgent:
138
  f"LinkedIn: {self.linkedin}"
139
  )
140
 
141
- # Ensure only one "Best regards" section and remove any duplicate signatures
142
  if "Best regards" in formatted_email:
143
  formatted_email = formatted_email.split("Best regards")[0].strip()
144
 
145
- return f"{formatted_email}\n{closing_section}\n{signature}"
146
 
147
  # Gradio UI setup remains unchanged
148
  def gradio_ui():
 
112
  return "Error: Unable to generate response."
113
 
114
  def format_email(self, llm_response):
115
+ # Split the response into paragraphs for better formatting
116
  paragraphs = [line.strip() for line in llm_response.split("\n") if line.strip()]
117
  formatted_email = "\n\n".join(paragraphs)
118
 
119
+ # Enforce word limit without breaking the structure
120
  words = formatted_email.split()
121
  if len(words) > self.word_limit:
122
+ truncated_email = " ".join(words[:self.word_limit])
123
+ formatted_email = truncated_email + "..."
124
 
125
  # Add the closing section with a call to action
126
  closing_section = (
 
138
  f"LinkedIn: {self.linkedin}"
139
  )
140
 
141
+ # Ensure the signature and closing are not duplicated and formatted neatly
142
  if "Best regards" in formatted_email:
143
  formatted_email = formatted_email.split("Best regards")[0].strip()
144
 
145
+ return f"{formatted_email}{closing_section}\n{signature}"
146
 
147
  # Gradio UI setup remains unchanged
148
  def gradio_ui():