Spaces:
Sleeping
Sleeping
Commit
·
5fba847
1
Parent(s):
4bc186d
Update app.py
Browse files
app.py
CHANGED
@@ -1,153 +1,153 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
st.write("weekend break ")
|
3 |
# import streamlit as st
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
#
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
#
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
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 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
|
101 |
-
|
102 |
-
#
|
103 |
-
|
104 |
|
105 |
-
#
|
106 |
-
|
107 |
|
108 |
-
#
|
109 |
-
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
|
133 |
-
|
134 |
|
135 |
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
|
|
|
|
|
|
|
1 |
# import streamlit as st
|
2 |
+
# st.write("weekend break ")
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
import requests
|
6 |
+
import os
|
7 |
|
8 |
+
def main():
|
9 |
|
10 |
+
BackendService=os.getenv("backend")
|
11 |
+
input_data=None
|
12 |
+
submitted=None
|
13 |
+
# Wrap everything inside a form
|
14 |
+
with st.sidebar:
|
15 |
|
16 |
+
uploaded_file = st.file_uploader("Kindly upload a CSV file that includes the names and websites of the companies", type=["csv"])
|
17 |
+
opt_out_scraping = st.checkbox("Opt out of scraping")
|
18 |
+
if uploaded_file is not None:
|
19 |
+
try:
|
20 |
+
# Detect file type and read accordingly
|
21 |
+
file_type = uploaded_file.name.split('.')[-1]
|
22 |
+
if file_type == 'csv':
|
23 |
+
df = pd.read_csv(uploaded_file)
|
24 |
+
elif file_type == 'xlsx':
|
25 |
+
df = pd.read_excel(uploaded_file)
|
26 |
|
27 |
+
# Limiting the dataframe for processing
|
28 |
|
29 |
+
# Check if 'Website' column exists
|
30 |
+
if 'Website' not in df.columns:
|
31 |
+
all_columns = df.columns.tolist()
|
32 |
+
website_column = st.selectbox("Select the column for Website:", all_columns)
|
33 |
+
else:
|
34 |
+
website_column = 'Website'
|
35 |
|
36 |
|
37 |
+
# Check if 'Company Name for Emails' column exists
|
38 |
+
if 'Company Name for Emails' not in df.columns:
|
39 |
+
all_columns = df.columns.tolist()
|
40 |
+
company_column= st.selectbox("Select the column for Company Name for Emails:", all_columns)
|
41 |
+
else:
|
42 |
+
company_column = 'Company Name for Emails'
|
43 |
|
44 |
+
if opt_out_scraping:
|
45 |
+
if 'Description' not in df.columns:
|
46 |
+
all_columns = df.columns.tolist()
|
47 |
+
description_column = st.selectbox("Select the column for Description:", all_columns)
|
48 |
+
df.rename(columns={description_column: 'scraped_content'}, inplace=True)
|
49 |
+
else:
|
50 |
+
df.rename(columns={'Description': 'scraped_content'}, inplace=True)
|
51 |
|
52 |
+
input_data=df
|
53 |
|
54 |
+
except Exception as E :
|
55 |
+
st.error("An error occured while processing the file")
|
56 |
|
57 |
+
with st.form(key='my_form'):
|
58 |
+
# Fetch the filtered data
|
59 |
+
prompt_notes= st.text_input("If applicable please mention the network name")
|
60 |
|
61 |
+
# List of predefined email addresses
|
62 |
+
email_options = [
|
63 |
+
"[email protected]",
|
64 |
+
"[email protected]",
|
65 |
+
"[email protected]",
|
66 |
+
"[email protected]",
|
67 |
+
"[email protected]",
|
68 |
+
"[email protected]",
|
69 | |
70 |
+
]
|
71 |
|
72 |
+
# Streamlit select box for choosing an email
|
73 |
+
email_receiver = st.selectbox("Please select an email address", email_options)
|
74 |
|
75 |
|
76 |
+
# If the button is clicked, it will return True for this run
|
77 |
+
button_clicked = st.form_submit_button("Submit")
|
78 |
|
79 |
+
# 2. Update session state for the button
|
80 |
+
if button_clicked:
|
81 |
+
submitted = True
|
82 |
+
# Set the session state to the new value
|
83 |
+
prompt_notes = prompt_notes
|
84 |
+
# 3. Use the session state variable to determine if the button was previously clicked
|
85 |
+
if submitted and input_data is not None:
|
86 |
+
df = input_data
|
87 |
+
if not opt_out_scraping:
|
88 |
+
df[website_column] = df[website_column].astype(str)
|
89 |
+
df=df[[website_column,company_column]]
|
90 |
+
df.columns = ["Website","Company Name for Emails"]
|
91 |
+
df = df.drop_duplicates(subset="Website", keep='first')
|
92 |
+
df = df.dropna().loc[~(df == '').all(axis=1)]
|
93 |
+
else:
|
94 |
+
df[website_column] = df[website_column].astype(str)
|
95 |
+
df=df[[website_column,company_column,"scraped_content"]]
|
96 |
+
df.columns = ["Website","Company Name for Emails","scraped_content"]
|
97 |
+
df = df.drop_duplicates(subset="Website", keep='first')
|
98 |
+
df = df.dropna().loc[~(df == '').all(axis=1)]
|
99 |
|
100 |
|
101 |
+
st.write(df)
|
102 |
+
# Convert DataFrame to CSV for transmission
|
103 |
+
csv = df.to_csv(index=False)
|
104 |
|
105 |
+
# Construct the data to send
|
106 |
+
data_to_send = {"prompt_notes": prompt_notes, "dataframe": csv,"email_receiver":email_receiver}
|
107 |
|
108 |
+
# Sending the POST request to FastAPI
|
109 |
+
response = requests.post(BackendService, json=data_to_send)
|
110 |
|
111 |
+
if response.status_code == 200:
|
112 |
+
st.info(f"We're processing your request. You can close the app now. An email will be sent to {email_receiver} once the process is finished.")
|
113 |
+
else:
|
114 |
+
st.error("Data transmission failed. Please verify that your file contains the labels 'Company Website' and 'Company Name'. Additionally, ensure that your file is valid and contains records and try again , if the problem persists please contact us at [email protected]")
|
115 |
|
116 |
|
117 |
+
if __name__ == "__main__":
|
118 |
+
st.markdown(
|
119 |
+
"""
|
120 |
+
<style>
|
121 |
+
.higher-title {
|
122 |
+
font-size:35px !important;
|
123 |
+
color: #4A90E2; /* Shade of blue */
|
124 |
+
text-align: center;
|
125 |
+
font-weight: bold;
|
126 |
+
margin-top: -20px; /* Adjust this value to control the height */
|
127 |
+
}
|
128 |
+
</style>
|
129 |
+
""",
|
130 |
+
unsafe_allow_html=True,
|
131 |
+
)
|
132 |
|
133 |
+
st.markdown('<p class="higher-title">SalesIntel AI</p>', unsafe_allow_html=True)
|
134 |
|
135 |
|
136 |
|
137 |
+
logo_url = "https://i.imgur.com/WYnv26e.jpeg" # Replace this with your image's direct URL
|
138 |
+
st.markdown(
|
139 |
+
f"""
|
140 |
+
<style>
|
141 |
+
.logo {{
|
142 |
+
position: fixed;
|
143 |
+
bottom: 5px;
|
144 |
+
right: 5px;
|
145 |
+
width: 100px; # Adjust width as needed
|
146 |
+
}}
|
147 |
+
</style>
|
148 |
+
<img src="{logo_url}" class="logo">
|
149 |
+
""",
|
150 |
+
unsafe_allow_html=True,
|
151 |
+
)
|
152 |
+
main()
|
153 |
|