MohanadAfiffy commited on
Commit
6b18c99
·
1 Parent(s): d54307c

Update app.py

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