Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,10 @@ import requests
|
|
| 18 |
import streamlit.components.v1 as components
|
| 19 |
import smtplib
|
| 20 |
from email.mime.multipart import MIMEMultipart
|
| 21 |
-
from email.mime.text import
|
|
|
|
|
|
|
|
|
|
| 22 |
# Initialize logging and load environment variables
|
| 23 |
logging.basicConfig(level=logging.INFO)
|
| 24 |
logger = logging.getLogger(__name__)
|
|
@@ -108,35 +111,28 @@ def copy_to_clipboard(text):
|
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
-
def
|
| 112 |
-
"""
|
| 113 |
-
|
| 114 |
-
EMAIL_PASSWORD = os.getenv("Password") # Ensure this environment variable is set correctly
|
| 115 |
-
SMTP_SERVER = "smtp.office365.com"
|
| 116 |
-
SMTP_PORT = 465
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
try:
|
| 130 |
-
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT, timeout=10) as server:
|
| 131 |
-
server.set_debuglevel(1) # Enable debug output
|
| 132 |
-
server.starttls()
|
| 133 |
-
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
|
| 134 |
-
server.send_message(msg)
|
| 135 |
-
st.success("Feedback sent successfully!")
|
| 136 |
-
except smtplib.SMTPException as e:
|
| 137 |
-
st.error(f"SMTP error: {e}")
|
| 138 |
-
except Exception as e:
|
| 139 |
-
st.error(f"Error sending email: {e}")
|
| 140 |
|
| 141 |
def side():
|
| 142 |
with st.sidebar.form(key='feedback_form'):
|
|
@@ -187,7 +183,7 @@ def side():
|
|
| 187 |
if submit_button:
|
| 188 |
if feedback_name and feedback_email_input and feedback_text:
|
| 189 |
with st.spinner('Sending email'):
|
| 190 |
-
|
| 191 |
st.success("Thank you for your feedback!")
|
| 192 |
else:
|
| 193 |
st.error("Please fill in all fields.")
|
|
|
|
| 18 |
import streamlit.components.v1 as components
|
| 19 |
import smtplib
|
| 20 |
from email.mime.multipart import MIMEMultipart
|
| 21 |
+
from email.mime.text import
|
| 22 |
+
from datetime import datetime
|
| 23 |
+
import pandas as pd
|
| 24 |
+
|
| 25 |
# Initialize logging and load environment variables
|
| 26 |
logging.basicConfig(level=logging.INFO)
|
| 27 |
logger = logging.getLogger(__name__)
|
|
|
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
+
def save_feedback_to_excel(name, email, feedback):
|
| 115 |
+
"""Saves feedback to an Excel file."""
|
| 116 |
+
feedback_file = 'feedbacks.xlsx'
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
# Create a DataFrame with the feedback
|
| 119 |
+
data = {
|
| 120 |
+
'Timestamp': [datetime.now()],
|
| 121 |
+
'Name': [name],
|
| 122 |
+
'Email': [email],
|
| 123 |
+
'Feedback': [feedback]
|
| 124 |
+
}
|
| 125 |
+
df = pd.DataFrame(data)
|
| 126 |
|
| 127 |
+
# Check if the file already exists
|
| 128 |
+
if os.path.exists(feedback_file):
|
| 129 |
+
# Append to existing file
|
| 130 |
+
existing_df = pd.read_excel(feedback_file)
|
| 131 |
+
df = pd.concat([existing_df, df], ignore_index=True)
|
| 132 |
+
|
| 133 |
+
# Save to Excel
|
| 134 |
+
df.to_excel(feedback_file, index=False, engine='openpyxl')
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
def side():
|
| 138 |
with st.sidebar.form(key='feedback_form'):
|
|
|
|
| 183 |
if submit_button:
|
| 184 |
if feedback_name and feedback_email_input and feedback_text:
|
| 185 |
with st.spinner('Sending email'):
|
| 186 |
+
save_feedback_to_excel(feedback_name, feedback_email_input, feedback_text)
|
| 187 |
st.success("Thank you for your feedback!")
|
| 188 |
else:
|
| 189 |
st.error("Please fill in all fields.")
|