Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import requests | |
import os | |
def main(): | |
BackendService=os.getenv("backend") | |
input_data=None | |
submitted=None | |
# Wrap everything inside a form | |
with st.sidebar: | |
uploaded_file = st.file_uploader("Kindly upload a CSV file that includes the names and websites of the companies", type=["csv"]) | |
if uploaded_file is not None: | |
try: | |
# Detect file type and read accordingly | |
file_type = uploaded_file.name.split('.')[-1] | |
if file_type == 'csv': | |
df = pd.read_csv(uploaded_file) | |
elif file_type == 'xlsx': | |
df = pd.read_excel(uploaded_file) | |
# Limiting the dataframe for processing | |
# Check if 'Website' column exists | |
if 'Website' not in df.columns: | |
all_columns = df.columns.tolist() | |
website_column = st.selectbox("Select the column for Website:", all_columns) | |
else: | |
website_column = 'Website' | |
# Check if 'Company Name for Emails' column exists | |
if 'Company Name for Emails' not in df.columns: | |
all_columns = df.columns.tolist() | |
company_column= st.selectbox("Select the column for Company Name for Emails:", all_columns) | |
else: | |
company_column = 'Company Name for Emails' | |
input_data=df | |
except Exception as E : | |
st.error("An error occured while processing the file") | |
with st.form(key='my_form'): | |
# Fetch the filtered data | |
prompt_notes= st.text_input("If applicable please mention the network name") | |
# List of predefined email addresses | |
email_options = [ | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]" | |
] | |
# Streamlit select box for choosing an email | |
email_receiver = st.selectbox("Please select an email address", email_options) | |
# If the button is clicked, it will return True for this run | |
button_clicked = st.form_submit_button("Submit") | |
# 2. Update session state for the button | |
if button_clicked: | |
submitted = True | |
# Set the session state to the new value | |
prompt_notes = prompt_notes | |
# 3. Use the session state variable to determine if the button was previously clicked | |
if submitted and input_data is not None: | |
df = input_data | |
df[website_column] = df[website_column].astype(str) | |
df=df[[website_column,company_column]] | |
df.columns = ["Website","Company Name for Emails"] | |
# Convert DataFrame to CSV for transmission | |
csv = df.to_csv(index=False) | |
# Construct the data to send | |
data_to_send = {"prompt_notes": prompt_notes, "dataframe": csv,"email_receiver":email_receiver} | |
# Sending the POST request to FastAPI | |
response = requests.post("https://ppxt7uqbmw.us-east-2.awsapprunner.com/receive_data/", json=data_to_send) | |
if response.status_code == 200: | |
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.") | |
else: | |
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]") | |
if __name__ == "__main__": | |
st.markdown( | |
""" | |
<style> | |
.higher-title { | |
font-size:35px !important; | |
color: #4A90E2; /* Shade of blue */ | |
text-align: center; | |
font-weight: bold; | |
margin-top: -20px; /* Adjust this value to control the height */ | |
} | |
</style> | |
""", | |
unsafe_allow_html=True, | |
) | |
st.markdown('<p class="higher-title">SalesIntel AI</p>', unsafe_allow_html=True) | |
logo_url = "https://i.imgur.com/WYnv26e.jpeg" # Replace this with your image's direct URL | |
st.markdown( | |
f""" | |
<style> | |
.logo {{ | |
position: fixed; | |
bottom: 5px; | |
right: 5px; | |
width: 100px; # Adjust width as needed | |
}} | |
</style> | |
<img src="{logo_url}" class="logo"> | |
""", | |
unsafe_allow_html=True, | |
) | |
main() | |