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