Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,21 @@ from docx import Document
|
|
3 |
import re
|
4 |
import io
|
5 |
import os
|
|
|
|
|
|
|
6 |
import smtplib
|
7 |
from email.mime.multipart import MIMEMultipart
|
8 |
from email.mime.base import MIMEBase
|
9 |
from email import encoders
|
10 |
from email.mime.text import MIMEText
|
11 |
-
from retrying import retry
|
12 |
-
from functions import *
|
13 |
|
14 |
# Declare the Exa search API
|
15 |
exa = Exa(api_key=os.getenv("EXA_API_KEY"))
|
16 |
|
17 |
# Initialize available Groq APIs from Hugging Face secrets
|
18 |
groq_api_keys = st.secrets["GROQ_API_KEYS"].split(",") # Split the comma-separated string into a list
|
19 |
-
|
20 |
available_groq_apis = [Groq(api_key=key.strip()) for key in groq_api_keys if key.strip()] # Create Groq instances
|
21 |
-
|
22 |
current_api_index = 0
|
23 |
utilized_model = "llama3-70b-8192"
|
24 |
|
@@ -49,7 +48,6 @@ st.markdown("""
|
|
49 |
**راههای ارتباطی:**
|
50 |
- **ایمیل:** [ایمیل را اینجا وارد کنید](mailto:ایمیل) # Replace with actual email
|
51 |
- **اینستاگرام:** [Instagram](https://www.instagram.com/your_instagram_handle) # Replace with actual Instagram link
|
52 |
-
|
53 |
""")
|
54 |
|
55 |
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
|
@@ -106,6 +104,34 @@ def sanitize_filename(filename, max_length=100):
|
|
106 |
sanitized = re.sub(r'[<>:"/\\|?*]', '', filename)
|
107 |
return sanitized[:max_length]
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
def collect_basic_info():
|
110 |
st.title("Business Proposal Generator")
|
111 |
|
@@ -179,4 +205,10 @@ def collect_basic_info():
|
|
179 |
file_name=f"{filename_prefix}.docx",
|
180 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
181 |
)
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import re
|
4 |
import io
|
5 |
import os
|
6 |
+
import requests
|
7 |
+
from retrying import retry
|
8 |
+
from functions import *
|
9 |
import smtplib
|
10 |
from email.mime.multipart import MIMEMultipart
|
11 |
from email.mime.base import MIMEBase
|
12 |
from email import encoders
|
13 |
from email.mime.text import MIMEText
|
|
|
|
|
14 |
|
15 |
# Declare the Exa search API
|
16 |
exa = Exa(api_key=os.getenv("EXA_API_KEY"))
|
17 |
|
18 |
# Initialize available Groq APIs from Hugging Face secrets
|
19 |
groq_api_keys = st.secrets["GROQ_API_KEYS"].split(",") # Split the comma-separated string into a list
|
|
|
20 |
available_groq_apis = [Groq(api_key=key.strip()) for key in groq_api_keys if key.strip()] # Create Groq instances
|
|
|
21 |
current_api_index = 0
|
22 |
utilized_model = "llama3-70b-8192"
|
23 |
|
|
|
48 |
**راههای ارتباطی:**
|
49 |
- **ایمیل:** [ایمیل را اینجا وارد کنید](mailto:ایمیل) # Replace with actual email
|
50 |
- **اینستاگرام:** [Instagram](https://www.instagram.com/your_instagram_handle) # Replace with actual Instagram link
|
|
|
51 |
""")
|
52 |
|
53 |
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
|
|
|
104 |
sanitized = re.sub(r'[<>:"/\\|?*]', '', filename)
|
105 |
return sanitized[:max_length]
|
106 |
|
107 |
+
def send_email_with_attachment(email, file_path):
|
108 |
+
sender_email = "your_sender_email@example.com" # Replace with your sender email
|
109 |
+
sender_password = "your_sender_password" # Replace with sender email password
|
110 |
+
subject = "Business Proposal Document"
|
111 |
+
|
112 |
+
# Create the email
|
113 |
+
msg = MIMEMultipart()
|
114 |
+
msg['From'] = sender_email
|
115 |
+
msg['To'] = email
|
116 |
+
msg['Subject'] = subject
|
117 |
+
|
118 |
+
# Attach the document
|
119 |
+
part = MIMEBase('application', 'octet-stream')
|
120 |
+
part.set_payload(open(file_path, "rb").read())
|
121 |
+
encoders.encode_base64(part)
|
122 |
+
part.add_header('Content-Disposition', f"attachment; filename= {os.path.basename(file_path)}")
|
123 |
+
msg.attach(part)
|
124 |
+
|
125 |
+
# Send the email
|
126 |
+
try:
|
127 |
+
with smtplib.SMTP('smtp.example.com', 587) as server: # Use your SMTP server
|
128 |
+
server.starttls()
|
129 |
+
server.login(sender_email, sender_password)
|
130 |
+
server.send_message(msg)
|
131 |
+
st.success(f"Proposal sent to {email} successfully.")
|
132 |
+
except Exception as e:
|
133 |
+
st.error(f"Error sending email: {str(e)}")
|
134 |
+
|
135 |
def collect_basic_info():
|
136 |
st.title("Business Proposal Generator")
|
137 |
|
|
|
205 |
file_name=f"{filename_prefix}.docx",
|
206 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
207 |
)
|
208 |
+
|
209 |
+
# Send email after generating the document
|
210 |
+
if data['email']:
|
211 |
+
email_file_path = f"/mnt/data/{filename_prefix}.docx" # Path for the email attachment
|
212 |
+
send_email_with_attachment(data['email'], email_file_path)
|
213 |
+
|
214 |
+
collect_basic_info()
|