-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
129 lines (107 loc) · 4.53 KB
/
main.py
1
2
3
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
import streamlit as st
import pandas as pd
from io import StringIO
import base64
import plotly.express as px
from helper.scrap import scraper # Ensure your scraper function returns the DataFrame as described
st.set_page_config(page_title="Social Media Lead Generation", page_icon="🎯")
# Function to convert image to base64 string
def image_to_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode()
background=image_to_base64('data/background.png')
st.markdown(f"""
<style>
.stApp {{
background-image: url("data:image/png;base64,{background}");
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}}
</style>
""", unsafe_allow_html=True)
# Convert logo to base64
logo_base64 = image_to_base64("data/logo.png")
# Add the title with logo positioned to the right
# Set the page title and icon
st.markdown(f"""
<div style="display: flex; align-items: center; justify-content: space-between; padding: 10px 0;">
<h1 style="margin: 0;">Social Media Lead Generation</h1>
<img src="data:image/png;base64,{logo_base64}" style="width: 100px; height: 100px; margin-left: auto;">
</div>
""", unsafe_allow_html=True)
st.divider()
# Sidebar for settings and credentials
st.sidebar.title("Platforms")
# Platform selection
lead_filter = st.sidebar.radio("Choose a Platform", ["LinkedIn", "Instagram", "X"])
# Input fields for credentials in sidebar
st.sidebar.markdown(f"### {lead_filter} Login")
email = st.sidebar.text_input("Email")
password = st.sidebar.text_input("Password", type="password")
# Logos for platforms
x_logo_base64 = image_to_base64("data/x logo.png")
insta_logo_base64 = image_to_base64("data/insta logo.png")
linkedin_logo_base64 = image_to_base64("data/linkedin logo.png")
logos = {'LinkedIn': linkedin_logo_base64, "Instagram": insta_logo_base64, "X": x_logo_base64}
# Display chosen platform's logo
st.markdown(f"""
<div style="display: flex; align-items: center;">
<img src="data:image/png;base64,{logos[lead_filter]}" style="width: 30px; height: 30px;">
<h2 style="margin-left: 10px;">{lead_filter} Lead Generation</h2>
</div>
""", unsafe_allow_html=True)
# Input URL from user
url = st.text_input(f"Enter {lead_filter} Post URL:")
# Generate button
generate_button = st.button("Generate")
# LinkedIn lead generation logic
if lead_filter == "LinkedIn":
if url and email and password and generate_button:
with st.spinner('Processing...'):
try:
# Pass the user credentials and URL to scraper function
dataframe_result = scraper(url, email, password)
print(dataframe_result,"***********************")
# Display the DataFrame as a table
st.markdown("### Potential Leads:")
st.dataframe(dataframe_result)
st.markdown("### Analysis")
tab1, tab2, tab3 = st.tabs(["Pie Chart", "Histogram", "Bar Chart"])
with tab1:
fig = px.pie(dataframe_result, names="Is Lead")
st.plotly_chart(fig, use_container_width=True)
with tab2:
st.info("Histogram is coming soon!")
with tab3:
st.info("Bar Chart is coming soon!")
# Download button for CSV file
def convert_df_to_csv(df):
output = StringIO()
df.to_csv(output, index=False)
return output.getvalue()
csv_data = convert_df_to_csv(dataframe_result)
# Show download button for CSV
st.download_button(
label="Download as CSV",
data=csv_data,
file_name="dataframe_result.csv",
mime="text/csv"
)
except Exception as e:
st.error(f"Error processing URL: {e}")
else:
st.warning("Please enter LinkedIn credentials and a URL.")
else:
# Show "Coming Soon" message for Instagram and X
st.info(f"{lead_filter} functionality is coming soon!")
# Help section
st.divider()
st.markdown(f"""
### How to Use
1. Enter {lead_filter} credentials and a {lead_filter} post URL in the text box.
2. Click on **Generate** to extract potential leads.
3. Download the data as a CSV file if needed.
""")
st.divider()