Wajahat698 commited on
Commit
35d9025
·
verified ·
1 Parent(s): 67f23d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -44
app.py CHANGED
@@ -112,49 +112,34 @@ def copy_to_clipboard(text):
112
  components.html(copy_icon_html, height=60)
113
 
114
 
115
- def save_feedback_to_excel(name, email, feedback):
116
- """Saves feedback to an Excel file."""
117
- feedback_file = 'feedbacks.xlsx'
 
 
 
 
 
 
 
 
118
 
119
- # Create a DataFrame with the feedback
120
- data = {
121
- 'Timestamp': [datetime.now()],
122
- 'Name': [name],
123
- 'Email': [email],
124
- 'Feedback': [feedback]
125
- }
126
- df = pd.DataFrame(data)
127
 
128
- if os.path.exists(feedback_file):
129
- try:
130
- # Attempt to load the existing file
131
- existing_df = pd.read_excel(feedback_file, engine='openpyxl')
132
- # Append the new feedback
133
- df = pd.concat([existing_df, df], ignore_index=True)
134
- except ValueError as e:
135
- st.error(f"ValueError: {e} - The file might be corrupted or not an Excel file.")
136
- # Create a new file if reading fails
137
- df.to_excel(feedback_file, index=False, engine='openpyxl')
138
- st.success("New feedback file created and feedback saved!")
139
- return
140
- except Exception as e:
141
- st.error(f"Error reading existing feedback file: {e}")
142
- # Create a new file if reading fails
143
- df.to_excel(feedback_file, index=False, engine='openpyxl')
144
- st.success("New feedback file created and feedback saved!")
145
- return
146
- else:
147
- # File doesn't exist, just create it
148
- df.to_excel(feedback_file, index=False, engine='openpyxl')
149
- st.success("Feedback file created and feedback saved!")
150
- return
151
-
152
  try:
153
- # Save to Excel using the openpyxl engine
154
- df.to_excel(feedback_file, index=False, engine='openpyxl')
155
- st.success("Feedback saved successfully!")
 
 
 
 
 
 
 
156
  except Exception as e:
157
- st.error(f"Error saving feedback to Excel: {e}")
158
 
159
 
160
  def clean_text(text):
@@ -166,9 +151,11 @@ def clean_text(text):
166
  text = re.sub(r'</span>', '', text)
167
  text = re.sub(r'<i[^>]*>', '', text)
168
  text = re.sub(r'</i>', '', text)
 
 
169
 
170
- # Preserve and correctly format markdown links
171
- text = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+)\)', r'\1: \2', text)
172
 
173
  # Split the text into paragraphs
174
  paragraphs = text.split('\n\n')
@@ -346,8 +333,11 @@ prompt_message = f"""
346
  Strictly DO NOT generate imaginary/Creative content .
347
  When asking for trust builders it has tibe returned short/concised facts & figures as dot points.
348
  All the outputs should be in paragraph tags except heading .
349
- Always provide clickable source links.
 
350
  Respond directly to the query.
 
 
351
  - DO NOT include column names like "Stability Trust," "Development Trust," "Relationship Trust," "Competence Trust," "Benefit Trust," or "Vision Trust" in tables or anywhere in the response.
352
 
353
  - When creating tables, replace the trust bucket names with descriptive phrases:
@@ -584,7 +574,7 @@ if prompt :
584
  try:
585
  # Generate response using the agent executor
586
  output = agent_executor.invoke({
587
- "input": f" {prompt} . Always INCLUDE & Be specific with -numbers, -dates,-people, and -[$ dollar amounts] .* Search and provide accurate source links. Respond directly to the query without any introductory phrases or meta-commentary. Your response should be natural and read as if it's addressing the query immediately, without any preamble. Use creative techniques like metaphors, analogies, and juxtaposition to enhance the content. Interconnect ideas smoothly to create meaning for the reader.Always write in nicely flowing text and create an active language headline. Avoid using colons in the sub-headings and incorporate a creative technique in every headline and sub-header. Interweave the examples contextually to create meaning for donors and beneficiaries. When asked about to write annual report ONLY THEN write report in 2-3 pargagraphs(with no sub-headings) and end then : do mention these 3 in sub headings with example related to the report: -example proof points , -Heuristics used , -creative techniques used (DO-NOT MENTION THIS WHEN ASKED TO WRITE EMAIL or news letter). When asked about email news letter or news letter it should be in proper email format . DO NOT USE COLONS in the sub-headers Otherwise ignore it . DONOT WRITE CONCLUSION in the end related to given prompt. remove all tags present with your response so response format is great. ",
588
  "chat_history": st.session_state.chat_history
589
  })
590
  full_response = output["output"]
@@ -597,7 +587,7 @@ if prompt :
597
  suggestion = random.choice(suggestions)
598
  cleaned_text += f"\n\n**Trust Tip**: {trust_tip} \n\n **Suggestion**: {suggestion}"
599
 
600
- st.write(cleaned_text, unsafe_allow_html=True)
601
 
602
 
603
 
 
112
  components.html(copy_icon_html, height=60)
113
 
114
 
115
+ def send_feedback_via_email(name, email, feedback):
116
+ """Sends an email with feedback details."""
117
+ smtp_server = 'smtp.office365.com'
118
+ smtp_port = 465 # Typically 587 for TLS, 465 for SSL
119
+ smtp_user = os.getenv("EMAIL_ADDRESS")
120
+ smtp_password = os.getenv("Password")
121
+
122
+ msg = MIMEMultipart()
123
+ msg['From'] = smtp_user
124
+ msg['To'] = "wajahat698@gmail.com"
125
+ msg['Subject'] = 'Feedback Received'
126
 
127
+ body = f"Feedback received from {name}:\n\n{feedback}"
128
+ msg.attach(MIMEText(body, 'plain'))
 
 
 
 
 
 
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  try:
131
+ with smtplib.SMTP(smtp_server, smtp_port, timeout=10) as server:
132
+ server.set_debuglevel(1) # Enable debug output for troubleshooting
133
+ server.starttls()
134
+ server.login(smtp_user, smtp_password)
135
+ server.sendmail(smtp_user, email, msg.as_string())
136
+ st.success("Feedback sent via email successfully!")
137
+ except smtplib.SMTPConnectError:
138
+ st.error("Failed to connect to the SMTP server. Check server settings and network connectivity.")
139
+ except smtplib.SMTPAuthenticationError:
140
+ st.error("Authentication failed. Check email and password.")
141
  except Exception as e:
142
+ st.error(f"Error sending email: {e}")
143
 
144
 
145
  def clean_text(text):
 
151
  text = re.sub(r'</span>', '', text)
152
  text = re.sub(r'<i[^>]*>', '', text)
153
  text = re.sub(r'</i>', '', text)
154
+
155
+
156
 
157
+ # Preserve and correctly format markdown links (don't modify URLs)
158
+ #text = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+)\)', r'\1: \2', text)
159
 
160
  # Split the text into paragraphs
161
  paragraphs = text.split('\n\n')
 
333
  Strictly DO NOT generate imaginary/Creative content .
334
  When asking for trust builders it has tibe returned short/concised facts & figures as dot points.
335
  All the outputs should be in paragraph tags except heading .
336
+ Always Search and Provide relevant clickable source links directly related to the point mentioned.
337
+
338
  Respond directly to the query.
339
+ Strictly DO NOT include `<span>`, '<i>', or any other unnecessary HTML tags in your response.
340
+
341
  - DO NOT include column names like "Stability Trust," "Development Trust," "Relationship Trust," "Competence Trust," "Benefit Trust," or "Vision Trust" in tables or anywhere in the response.
342
 
343
  - When creating tables, replace the trust bucket names with descriptive phrases:
 
574
  try:
575
  # Generate response using the agent executor
576
  output = agent_executor.invoke({
577
+ "input": f" {prompt} . Always Be specific with numbers, dates, people, and $dollar amounts( Do Mention them ). **Important** -Search and provide correct source links for each point . Respond directly to the query without any introductory phrases or meta-commentary. Your response should be natural and read as if it's addressing the query immediately, without any preamble. Use creative techniques like metaphors, analogies, and juxtaposition to enhance the content. Interconnect ideas smoothly to create meaning for the reader.Always write in nicely flowing text and create an active language headline. Avoid using colons in the sub-headings and incorporate a creative technique in every headline and sub-header. Interweave the examples contextually to create meaning for donors and beneficiaries. When asked about to write annual report ONLY THEN write report in 2-3 pargagraphs(with no sub-headings) and end then : do mention these 3 in sub headings with example related to the report: -example proof points , -Heuristics used , -creative techniques used (DO-NOT MENTION THIS WHEN ASKED TO WRITE EMAIL or news letter). When asked about email news letter or news letter it should be in proper email format . DO NOT USE COLONS in the sub-headers Otherwise ignore it . DONOT WRITE CONCLUSION in the end related to given prompt. remove all tags present with your response so response format is great. ",
578
  "chat_history": st.session_state.chat_history
579
  })
580
  full_response = output["output"]
 
587
  suggestion = random.choice(suggestions)
588
  cleaned_text += f"\n\n**Trust Tip**: {trust_tip} \n\n **Suggestion**: {suggestion}"
589
 
590
+ st.markdown(cleaned_text , unsafe_allow_html=True)
591
 
592
 
593