Spaces:
Runtime error
Runtime error
Ronio Jerico Roque commited on
Commit ·
51a0521
1
Parent(s): 2b4906a
fix: update return button navigation to point to home page and refine file uploader functionality
Browse files- classes/Lead_List.py +1 -1
- classes/Seo.py +2 -2
- classes/Seo_Off_Page.py +2 -2
- classes/Seo_On_Page.py +1 -1
- classes/Social_Media.py +1 -1
- classes/Target_Market.py +1 -1
- classes/test.py +219 -0
classes/Lead_List.py
CHANGED
|
@@ -32,7 +32,7 @@ class LeadListAnalyst:
|
|
| 32 |
# RETURN BUTTON
|
| 33 |
try:
|
| 34 |
if st.button("Return", type='primary'):
|
| 35 |
-
st.switch_page("./
|
| 36 |
except Exception:
|
| 37 |
pass
|
| 38 |
|
|
|
|
| 32 |
# RETURN BUTTON
|
| 33 |
try:
|
| 34 |
if st.button("Return", type='primary'):
|
| 35 |
+
st.switch_page("./pages/home.py")
|
| 36 |
except Exception:
|
| 37 |
pass
|
| 38 |
|
classes/Seo.py
CHANGED
|
@@ -36,7 +36,7 @@ class SeoAnalyst:
|
|
| 36 |
# RETURN BUTTON
|
| 37 |
try:
|
| 38 |
if st.button("Return", type='primary'):
|
| 39 |
-
st.switch_page("./
|
| 40 |
except Exception:
|
| 41 |
pass
|
| 42 |
|
|
@@ -171,7 +171,7 @@ class SeoAnalyst:
|
|
| 171 |
self.file_dict = upload.file_dict
|
| 172 |
|
| 173 |
st.write("") # FOR THE HIDE BUTTON
|
| 174 |
-
self.uploaded_file_seo = st.file_uploader("Upload SEO Keywords CSV (SEMRush)", type='csv'
|
| 175 |
if self.uploaded_file_seo:
|
| 176 |
self.delete_sessions()
|
| 177 |
try:
|
|
|
|
| 36 |
# RETURN BUTTON
|
| 37 |
try:
|
| 38 |
if st.button("Return", type='primary'):
|
| 39 |
+
st.switch_page("./pages/home.py")
|
| 40 |
except Exception:
|
| 41 |
pass
|
| 42 |
|
|
|
|
| 171 |
self.file_dict = upload.file_dict
|
| 172 |
|
| 173 |
st.write("") # FOR THE HIDE BUTTON
|
| 174 |
+
self.uploaded_file_seo = st.file_uploader("Upload SEO Keywords CSV (SEMRush)", type='csv')
|
| 175 |
if self.uploaded_file_seo:
|
| 176 |
self.delete_sessions()
|
| 177 |
try:
|
classes/Seo_Off_Page.py
CHANGED
|
@@ -34,7 +34,7 @@ class SeoOffPageAnalyst:
|
|
| 34 |
# RETURN BUTTON
|
| 35 |
try:
|
| 36 |
if st.button("Return", type='primary'):
|
| 37 |
-
st.switch_page("./
|
| 38 |
except Exception:
|
| 39 |
pass
|
| 40 |
|
|
@@ -81,7 +81,7 @@ class SeoOffPageAnalyst:
|
|
| 81 |
with col1:
|
| 82 |
st.write("") # FOR SPACING
|
| 83 |
st.write(self.data_src)
|
| 84 |
-
self.uploaded_files = st.file_uploader(self.analyst_description,
|
| 85 |
if self.uploaded_files:
|
| 86 |
upload.multiple_upload_file(self.uploaded_files)
|
| 87 |
|
|
|
|
| 34 |
# RETURN BUTTON
|
| 35 |
try:
|
| 36 |
if st.button("Return", type='primary'):
|
| 37 |
+
st.switch_page("./pages/home.py")
|
| 38 |
except Exception:
|
| 39 |
pass
|
| 40 |
|
|
|
|
| 81 |
with col1:
|
| 82 |
st.write("") # FOR SPACING
|
| 83 |
st.write(self.data_src)
|
| 84 |
+
self.uploaded_files = st.file_uploader(self.analyst_description, print("in"))
|
| 85 |
if self.uploaded_files:
|
| 86 |
upload.multiple_upload_file(self.uploaded_files)
|
| 87 |
|
classes/Seo_On_Page.py
CHANGED
|
@@ -36,7 +36,7 @@ class SeoOnPageAnalyst:
|
|
| 36 |
# RETURN BUTTON
|
| 37 |
try:
|
| 38 |
if st.button("Return", type='primary'):
|
| 39 |
-
st.switch_page("./
|
| 40 |
except Exception:
|
| 41 |
pass
|
| 42 |
|
|
|
|
| 36 |
# RETURN BUTTON
|
| 37 |
try:
|
| 38 |
if st.button("Return", type='primary'):
|
| 39 |
+
st.switch_page("./pages/home.py")
|
| 40 |
except Exception:
|
| 41 |
pass
|
| 42 |
|
classes/Social_Media.py
CHANGED
|
@@ -35,7 +35,7 @@ class SocialMediaAnalyst:
|
|
| 35 |
# RETURN BUTTON
|
| 36 |
try:
|
| 37 |
if st.button("Return", type='primary'):
|
| 38 |
-
st.switch_page("./
|
| 39 |
except Exception:
|
| 40 |
pass
|
| 41 |
|
|
|
|
| 35 |
# RETURN BUTTON
|
| 36 |
try:
|
| 37 |
if st.button("Return", type='primary'):
|
| 38 |
+
st.switch_page("./pages/home.py")
|
| 39 |
except Exception:
|
| 40 |
pass
|
| 41 |
|
classes/Target_Market.py
CHANGED
|
@@ -32,7 +32,7 @@ class TargetMarketAnalyst:
|
|
| 32 |
# RETURN BUTTON
|
| 33 |
try:
|
| 34 |
if st.button("Return", type='primary'):
|
| 35 |
-
st.switch_page("./
|
| 36 |
except Exception:
|
| 37 |
pass
|
| 38 |
|
|
|
|
| 32 |
# RETURN BUTTON
|
| 33 |
try:
|
| 34 |
if st.button("Return", type='primary'):
|
| 35 |
+
st.switch_page("./pages/home.py")
|
| 36 |
except Exception:
|
| 37 |
pass
|
| 38 |
|
classes/test.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import time
|
| 7 |
+
import chardet
|
| 8 |
+
from helper.telemetry import collect_telemetry
|
| 9 |
+
from helper.upload_File import uploadFile
|
| 10 |
+
from helper.button_behaviour import hide_button
|
| 11 |
+
from helper.initialize_analyze_session import initialize_analyze_session
|
| 12 |
+
|
| 13 |
+
class test:
|
| 14 |
+
def __init__(self, model_url, analyst_name, data_src, analyst_description):
|
| 15 |
+
self.uploaded_files = []
|
| 16 |
+
self.file_dict = {}
|
| 17 |
+
self.model_url = model_url
|
| 18 |
+
self.analyst_name = analyst_name
|
| 19 |
+
self.data_src = data_src
|
| 20 |
+
self.analyst_description = analyst_description
|
| 21 |
+
self.initialize()
|
| 22 |
+
self.row1()
|
| 23 |
+
|
| 24 |
+
def initialize(self):
|
| 25 |
+
# FOR ENV
|
| 26 |
+
load_dotenv()
|
| 27 |
+
|
| 28 |
+
# AGENT NAME
|
| 29 |
+
st.header(self.analyst_name)
|
| 30 |
+
|
| 31 |
+
# EVALUATION FORM LINK
|
| 32 |
+
url = os.getenv('Link')
|
| 33 |
+
st.write('Evaluation Form: [Link](%s)' % url)
|
| 34 |
+
|
| 35 |
+
# RETURN BUTTON
|
| 36 |
+
try:
|
| 37 |
+
if st.button("Return", type='primary'):
|
| 38 |
+
st.switch_page("./pages/home.py")
|
| 39 |
+
except Exception:
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
def request_model(self, payload_txt):
|
| 43 |
+
response = requests.post(self.model_url, json=payload_txt)
|
| 44 |
+
response.raise_for_status()
|
| 45 |
+
output = response.json()
|
| 46 |
+
|
| 47 |
+
categories = []
|
| 48 |
+
current_footprint = []
|
| 49 |
+
number_of_backlinks = []
|
| 50 |
+
|
| 51 |
+
for key, value in output.items():
|
| 52 |
+
if key == 'json':
|
| 53 |
+
for item in value:
|
| 54 |
+
categories.append(item.get('category', 'N/A').replace('_', ' ').title())
|
| 55 |
+
current_footprint.append(item.get('current_footprint', 'N/A'))
|
| 56 |
+
number_of_backlinks.append(item.get('best_of_breed_solution', 'N/A'))
|
| 57 |
+
|
| 58 |
+
output = ""
|
| 59 |
+
for i in range(len(categories)):
|
| 60 |
+
output += f"\n\n---\n **Category:** {categories[i]}"
|
| 61 |
+
output += f"\n\n **Count:** {current_footprint[i]}\n\n"
|
| 62 |
+
output += f"**Best of Breed Solution:** {number_of_backlinks[i]}"
|
| 63 |
+
|
| 64 |
+
data = {
|
| 65 |
+
"": [str(category) for category in categories],
|
| 66 |
+
"Current Footprint": [str(footprint) for footprint in current_footprint],
|
| 67 |
+
"Best of Breed Solution": [str(backlink) for backlink in number_of_backlinks]
|
| 68 |
+
}
|
| 69 |
+
df_output = pd.DataFrame(data)
|
| 70 |
+
with st.expander("AI Analysis", expanded=True, icon="🤖"):
|
| 71 |
+
st.table(df_output.style.set_table_styles(
|
| 72 |
+
[{'selector': 'th:first-child, td:first-child', 'props': [('width', '20px')]},
|
| 73 |
+
{'selector': 'th, td', 'props': [('width', '150px'), ('text-align', 'center')]}]
|
| 74 |
+
).set_properties(**{'text-align': 'center'}))
|
| 75 |
+
|
| 76 |
+
return output
|
| 77 |
+
|
| 78 |
+
def detect_encoding(self, uploaded_file):
|
| 79 |
+
result = chardet.detect(uploaded_file.read(100000))
|
| 80 |
+
uploaded_file.seek(0) # Reset file pointer to the beginning
|
| 81 |
+
return result['encoding']
|
| 82 |
+
|
| 83 |
+
def facebook(self, facebook_organic_post, facebook_ad_campaign):
|
| 84 |
+
try:
|
| 85 |
+
facebook_engagement_rate = (facebook_organic_post['Reactions, Comments and Shares'].mean() / self.facebooks).round(2)
|
| 86 |
+
st.session_state['facebook_engagement_rate'] = facebook_engagement_rate
|
| 87 |
+
except TypeError:
|
| 88 |
+
pass
|
| 89 |
+
# Post Frequency
|
| 90 |
+
facebook_post_frequency = facebook_organic_post[~facebook_organic_post['Post ID'].isna()].shape[0]
|
| 91 |
+
|
| 92 |
+
# Ads
|
| 93 |
+
facebook_ads = facebook_ad_campaign[~facebook_ad_campaign['Ad name'].isna()].shape[0]
|
| 94 |
+
|
| 95 |
+
st.session_state['facebook_review_rate'] = self.facebook_rr
|
| 96 |
+
st.session_state['facebook_ads'] = facebook_ads
|
| 97 |
+
st.session_state['facebook_post_frequency'] = facebook_post_frequency
|
| 98 |
+
st.session_state['facebook_followers'] = self.facebooks
|
| 99 |
+
|
| 100 |
+
try:
|
| 101 |
+
return facebook_engagement_rate, facebook_ads, facebook_post_frequency
|
| 102 |
+
except UnboundLocalError:
|
| 103 |
+
return facebook_ads, facebook_post_frequency
|
| 104 |
+
|
| 105 |
+
def terminate_session(self, session):
|
| 106 |
+
try:
|
| 107 |
+
del st.session_state[session]
|
| 108 |
+
except KeyError:
|
| 109 |
+
pass
|
| 110 |
+
|
| 111 |
+
def row1(self):
|
| 112 |
+
col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
|
| 113 |
+
with col1:
|
| 114 |
+
intensity = st.select_slider(
|
| 115 |
+
"Vague - Precise",
|
| 116 |
+
options=[0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
|
| 117 |
+
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
self.facebooks = st.number_input('Facebook Followers:', min_value=1, max_value=99999999, value=None, step=1, placeholder='Enter Facebook Followers')
|
| 122 |
+
self.facebook_rr = st.text_input("Facebook Review Rate:", placeholder='Enter Facebook Review Rate')
|
| 123 |
+
|
| 124 |
+
self.instagram = st.text_input("Instagram Followers:", placeholder='Enter Instagram Followers')
|
| 125 |
+
self.instagram_er = st.text_input("Instagram Audience Engagement Rate:", placeholder='Enter Instagram Audience Engagement Rate')
|
| 126 |
+
self.instagram_pf = st.text_input("Instagram Post Frequency:", placeholder='Enter Instagram Post Frequency')
|
| 127 |
+
|
| 128 |
+
followers = {
|
| 129 |
+
'Facebook Followers': self.facebooks if self.facebooks else 'N/A',
|
| 130 |
+
'Facebook Review Rate': self.facebook_rr if self.facebook_rr else 'N/A',
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
with col2:
|
| 134 |
+
st.write("") # FOR THE HIDE BUTTON
|
| 135 |
+
st.write("") # FOR THE HIDE BUTTON
|
| 136 |
+
st.write("AI Analyst Output: ")
|
| 137 |
+
st.session_state['analyzing'] = False
|
| 138 |
+
st.write("") # FOR THE HIDE BUTTON
|
| 139 |
+
analyze_button = st.button("Analyze", disabled=initialize_analyze_session())
|
| 140 |
+
start_time = time.time()
|
| 141 |
+
if analyze_button:
|
| 142 |
+
hide_button()
|
| 143 |
+
try:
|
| 144 |
+
if self.facebooks:
|
| 145 |
+
combined_text = ""
|
| 146 |
+
with st.spinner('Analyzing...', show_time=True):
|
| 147 |
+
st.write('')
|
| 148 |
+
|
| 149 |
+
intensity = str(intensity)
|
| 150 |
+
combined_text += f"Intensity: {intensity}\n"
|
| 151 |
+
# INITIALIZING SESSIONS
|
| 152 |
+
try:
|
| 153 |
+
facebook_organic_post = st.session_state['facebook_organic_post']
|
| 154 |
+
facebook_ad_campaign = st.session_state['facebook_ad_campaign']
|
| 155 |
+
|
| 156 |
+
self.facebook(facebook_organic_post, facebook_ad_campaign)
|
| 157 |
+
try:
|
| 158 |
+
facebook_engagement_rate = st.session_state['facebook_engagement_rate']
|
| 159 |
+
combined_text += f"\nFacebook Audience Engagement Rate: {facebook_engagement_rate}%"
|
| 160 |
+
except KeyError:
|
| 161 |
+
pass
|
| 162 |
+
facebook_ads = st.session_state['facebook_ads']
|
| 163 |
+
facebook_post_frequency = st.session_state['facebook_post_frequency']
|
| 164 |
+
combined_text += f"\nFacebook Followers: {self.facebooks}"
|
| 165 |
+
combined_text += f"\nFacebook Review Rate: {self.facebook_rr}"
|
| 166 |
+
combined_text += f"\nFacebook Ads: {facebook_ads}"
|
| 167 |
+
combined_text += f"\nFacebook Post Frequency: {facebook_post_frequency}"
|
| 168 |
+
|
| 169 |
+
combined_text += facebook_organic_post.to_csv(index=True)
|
| 170 |
+
combined_text += facebook_ad_campaign.to_csv(index=True)
|
| 171 |
+
except KeyError:
|
| 172 |
+
pass
|
| 173 |
+
|
| 174 |
+
try:
|
| 175 |
+
combined_text += f"Instagram Followers: {self.instagram}\n"
|
| 176 |
+
combined_text += f"Instagram Audience Engagement Rate: {self.instagram_er}%\n"
|
| 177 |
+
combined_text += f"Instagram Post Frequency: {self.instagram_pf}\n"
|
| 178 |
+
except KeyError:
|
| 179 |
+
pass
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
# OUTPUT FOR SEO ANALYST
|
| 184 |
+
payload_txt = {"question": combined_text}
|
| 185 |
+
result = self.request_model(payload_txt)
|
| 186 |
+
|
| 187 |
+
end_time = time.time()
|
| 188 |
+
time_lapsed = end_time - start_time
|
| 189 |
+
debug_info = {
|
| 190 |
+
'analyst': self.analyst_name,
|
| 191 |
+
'url_uuid': self.model_url.split("-")[-1],
|
| 192 |
+
'time_lapsed': time_lapsed,
|
| 193 |
+
#'backlink_files': [*st.session_state['uploaded_files']],
|
| 194 |
+
'payload': payload_txt,
|
| 195 |
+
'result': result,
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
collect_telemetry(debug_info)
|
| 199 |
+
|
| 200 |
+
with st.expander("Debug information", icon="⚙"):
|
| 201 |
+
st.write(debug_info)
|
| 202 |
+
|
| 203 |
+
for df in st.session_state.keys():
|
| 204 |
+
del st.session_state[df]
|
| 205 |
+
for facebook_ad_campaign in st.session_state.keys():
|
| 206 |
+
del st.session_state[facebook_ad_campaign]
|
| 207 |
+
|
| 208 |
+
st.session_state['analyzing'] = False
|
| 209 |
+
else:
|
| 210 |
+
st.info("Please upload CSV or PDF files first.")
|
| 211 |
+
hide_button()
|
| 212 |
+
except AttributeError:
|
| 213 |
+
st.info("Please upload CSV or PDF files first.")
|
| 214 |
+
hide_button()
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
st.set_page_config(layout="wide")
|
| 218 |
+
|
| 219 |
+
upload = uploadFile()
|