Ronio Jerico Roque commited on
Commit ·
db80347
1
Parent(s): 3945218
feat: added relevancy options for users
Browse files- .env +2 -1
- classes/Target_Market.py +75 -28
.env
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
email=shore360
|
| 2 |
-
password=shoreai
|
|
|
|
|
|
| 1 |
email=shore360
|
| 2 |
+
password=shoreai
|
| 3 |
+
apiKey=ae72168bf4064434bef650d038624373
|
classes/Target_Market.py
CHANGED
|
@@ -9,10 +9,11 @@ from helper.button_behaviour import hide_button
|
|
| 9 |
from helper.initialize_analyze_session import initialize_analyze_session
|
| 10 |
import json
|
| 11 |
from newsapi import NewsApiClient
|
|
|
|
|
|
|
| 12 |
|
| 13 |
class TargetMarketAnalyst:
|
| 14 |
def __init__(self, model_url, analyst_name, data_src, analyst_description):
|
| 15 |
-
self.newsapi = NewsApiClient(api_key='ae72168bf4064434bef650d038624373')
|
| 16 |
self.model_url = model_url
|
| 17 |
self.analyst_name = analyst_name
|
| 18 |
self.data_src = data_src
|
|
@@ -29,9 +30,7 @@ class TargetMarketAnalyst:
|
|
| 29 |
|
| 30 |
# EVALUATION FORM LINK
|
| 31 |
url = os.getenv('Link')
|
| 32 |
-
st.write('Evaluation Form: [Link](%s)' % url)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
def request_model(self, payload_txt):
|
| 37 |
response = requests.post(self.model_url, json=payload_txt)
|
|
@@ -47,7 +46,7 @@ class TargetMarketAnalyst:
|
|
| 47 |
demographics = text["demographics"]
|
| 48 |
summary = text["summary"]
|
| 49 |
|
| 50 |
-
with st.expander("
|
| 51 |
st.write(f"**Target Market**:\n {target_market}\n")
|
| 52 |
st.write(f"\n**Product / Service Demographics**: {demographics}")
|
| 53 |
st.write(f"\n**Marketing Message Summary**: {summary}")
|
|
@@ -57,8 +56,27 @@ class TargetMarketAnalyst:
|
|
| 57 |
def row1(self):
|
| 58 |
col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
|
| 59 |
with col1:
|
| 60 |
-
self.topics = st.text_input("Topic
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
with col2:
|
| 63 |
st.write("") # FOR THE HIDE BUTTON
|
| 64 |
st.write("") # FOR THE HIDE BUTTON
|
|
@@ -69,41 +87,70 @@ class TargetMarketAnalyst:
|
|
| 69 |
start_time = time.time()
|
| 70 |
if analyze_button:
|
| 71 |
hide_button()
|
| 72 |
-
if self.topics
|
| 73 |
combined_text = ""
|
| 74 |
with st.spinner('Analyzing...', show_time=True):
|
| 75 |
st.write('')
|
| 76 |
# INITIALIZING SESSIONS
|
| 77 |
|
| 78 |
combined_text += f"Topic/s of Interest: {self.topics}\n"
|
| 79 |
-
|
| 80 |
-
|
| 81 |
# OUTPUT FOR SEO ANALYST
|
| 82 |
root = 'https://newsapi.org/v2/everything?'
|
| 83 |
-
|
| 84 |
-
response = requests.get(f'{root}{
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
end_time = time.time()
|
| 92 |
-
time_lapsed = end_time - start_time
|
| 93 |
-
debug_info = {
|
| 94 |
-
'analyst': self.analyst_name,
|
| 95 |
-
'time_lapsed': time_lapsed,
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
else:
|
| 106 |
-
st.info("Please
|
| 107 |
hide_button()
|
| 108 |
|
| 109 |
if __name__ == "__main__":
|
|
|
|
| 9 |
from helper.initialize_analyze_session import initialize_analyze_session
|
| 10 |
import json
|
| 11 |
from newsapi import NewsApiClient
|
| 12 |
+
import datetime
|
| 13 |
+
import requests
|
| 14 |
|
| 15 |
class TargetMarketAnalyst:
|
| 16 |
def __init__(self, model_url, analyst_name, data_src, analyst_description):
|
|
|
|
| 17 |
self.model_url = model_url
|
| 18 |
self.analyst_name = analyst_name
|
| 19 |
self.data_src = data_src
|
|
|
|
| 30 |
|
| 31 |
# EVALUATION FORM LINK
|
| 32 |
url = os.getenv('Link')
|
| 33 |
+
st.write('Evaluation Form: [Link](%s)' % url)
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def request_model(self, payload_txt):
|
| 36 |
response = requests.post(self.model_url, json=payload_txt)
|
|
|
|
| 46 |
demographics = text["demographics"]
|
| 47 |
summary = text["summary"]
|
| 48 |
|
| 49 |
+
with st.expander("News Available", expanded=True, icon="🤖"):
|
| 50 |
st.write(f"**Target Market**:\n {target_market}\n")
|
| 51 |
st.write(f"\n**Product / Service Demographics**: {demographics}")
|
| 52 |
st.write(f"\n**Marketing Message Summary**: {summary}")
|
|
|
|
| 56 |
def row1(self):
|
| 57 |
col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
|
| 58 |
with col1:
|
| 59 |
+
self.topics = st.text_input("Topic of Interest: ", placeholder='Enter Topic of Interest:', key='topic')
|
| 60 |
+
#self.start_date = st.date_input('Start Date:', value="today", key='start_date')
|
| 61 |
+
#self.end_date = st.date_input('End Date:', value="today", key='end_date')
|
| 62 |
+
|
| 63 |
+
self.sort = st.radio(
|
| 64 |
+
"Sort by:",
|
| 65 |
+
["Published At", "Popularity", "Relevancy"],
|
| 66 |
+
captions=[
|
| 67 |
+
"Newest articles come first",
|
| 68 |
+
"Articles from popular sources and publishers come first",
|
| 69 |
+
"Articles more closely related to topic come first",
|
| 70 |
+
],
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if self.sort == 'Relevancy':
|
| 74 |
+
self.sort = 'relevancy'
|
| 75 |
+
elif self.sort == 'Popularity':
|
| 76 |
+
self.sort = 'popularity'
|
| 77 |
+
elif self.sort == 'Published At':
|
| 78 |
+
self.sort = 'publishedAt'
|
| 79 |
+
|
| 80 |
with col2:
|
| 81 |
st.write("") # FOR THE HIDE BUTTON
|
| 82 |
st.write("") # FOR THE HIDE BUTTON
|
|
|
|
| 87 |
start_time = time.time()
|
| 88 |
if analyze_button:
|
| 89 |
hide_button()
|
| 90 |
+
if self.topics:
|
| 91 |
combined_text = ""
|
| 92 |
with st.spinner('Analyzing...', show_time=True):
|
| 93 |
st.write('')
|
| 94 |
# INITIALIZING SESSIONS
|
| 95 |
|
| 96 |
combined_text += f"Topic/s of Interest: {self.topics}\n"
|
|
|
|
|
|
|
| 97 |
# OUTPUT FOR SEO ANALYST
|
| 98 |
root = 'https://newsapi.org/v2/everything?'
|
| 99 |
+
language = "en"
|
| 100 |
+
response = requests.get(f'{root}q={self.topics}&language={language}&sortBy={self.sort}&language="en"&apiKey={os.getenv('apiKey')}')
|
| 101 |
+
try:
|
| 102 |
+
response.raise_for_status()
|
| 103 |
+
|
| 104 |
+
output = response.json()
|
| 105 |
+
with st.expander("Output", expanded=True):
|
| 106 |
+
text = output['articles']
|
| 107 |
+
|
| 108 |
+
for article in text:
|
| 109 |
+
source = article['source']['name']
|
| 110 |
+
published = article['publishedAt']
|
| 111 |
+
author = article['author']
|
| 112 |
+
title = article['title']
|
| 113 |
+
description = article['description']
|
| 114 |
+
url = article['url']
|
| 115 |
+
urlImage = article['urlToImage']
|
| 116 |
+
content = article['content']
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
left_co, cent_co,last_co = st.columns(3)
|
| 120 |
+
|
| 121 |
+
if urlImage:
|
| 122 |
+
with left_co:
|
| 123 |
+
st.image(urlImage, width=400)
|
| 124 |
+
st.write(f"**{title}**")
|
| 125 |
+
st.write(f"{description}")
|
| 126 |
+
st.write(f"**Author**: {author}")
|
| 127 |
+
st.write(f"**Source**: {source}")
|
| 128 |
+
st.write('Link: [URL](%s)' % url)
|
| 129 |
+
st.write(f"**Published At**: {published}")
|
| 130 |
+
|
| 131 |
+
st.write("---")
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
st.write(text)
|
| 135 |
+
|
| 136 |
+
end_time = time.time()
|
| 137 |
+
time_lapsed = end_time - start_time
|
| 138 |
+
debug_info = {
|
| 139 |
+
'analyst': self.analyst_name,
|
| 140 |
+
'time_lapsed': time_lapsed,
|
| 141 |
+
|
| 142 |
+
}
|
| 143 |
|
| 144 |
+
collect_telemetry(debug_info)
|
| 145 |
|
| 146 |
+
with st.expander("Debug information", icon="⚙"):
|
| 147 |
+
st.write(debug_info)
|
| 148 |
|
| 149 |
+
st.session_state['analyzing'] = False
|
| 150 |
+
except requests.exceptions.HTTPError:
|
| 151 |
+
st.info("Exceeded limit, please come back tomorrow")
|
| 152 |
else:
|
| 153 |
+
st.info("Please provide a topic of interest")
|
| 154 |
hide_button()
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|