chat_streaming
#1
by roniorque - opened
- classes/Target_Market.py +114 -27
- requirements.txt +0 -1
classes/Target_Market.py
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
import time
|
|
|
|
| 5 |
from helper.upload_File import uploadFile
|
|
|
|
|
|
|
| 6 |
import json
|
| 7 |
-
|
| 8 |
import requests
|
|
|
|
|
|
|
| 9 |
|
| 10 |
class TargetMarketAnalyst:
|
| 11 |
def __init__(self, model_url, analyst_name, data_src, analyst_description):
|
|
@@ -24,8 +30,8 @@ class TargetMarketAnalyst:
|
|
| 24 |
st.header(self.analyst_name)
|
| 25 |
|
| 26 |
# EVALUATION FORM LINK
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
def request_model(self, payload_txt):
|
| 31 |
response = requests.post(self.model_url, json=payload_txt)
|
|
@@ -52,9 +58,9 @@ class TargetMarketAnalyst:
|
|
| 52 |
return output
|
| 53 |
|
| 54 |
def row1(self):
|
| 55 |
-
|
|
|
|
| 56 |
prompt = st.chat_input("How can I help you today?")
|
| 57 |
-
|
| 58 |
#client = genai.Client(api_key="AIzaSyArNeCctdKaWhxprHTnHyISCd0CpKqB5dk")
|
| 59 |
|
| 60 |
payload_txt = {
|
|
@@ -79,16 +85,9 @@ class TargetMarketAnalyst:
|
|
| 79 |
|
| 80 |
url = "http://172.17.21.23:7860/api/v1/run/382ac239-3231-4f9b-89fe-f5ee26e4b1eb?stream=false"
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
for message in st.session_state.messages:
|
| 85 |
-
with st.chat_message(message["role"]):
|
| 86 |
-
st.markdown(message["content"])
|
| 87 |
if prompt:
|
| 88 |
-
st.chat_message("user").markdown(prompt)
|
| 89 |
-
# Add user message to chat history
|
| 90 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 91 |
-
|
| 92 |
response = requests.post(url, json=payload_txt, headers=headers, params={'stream': 'false'})
|
| 93 |
response.raise_for_status()
|
| 94 |
output = response.json()
|
|
@@ -98,19 +97,107 @@ class TargetMarketAnalyst:
|
|
| 98 |
return text.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
| 99 |
|
| 100 |
self.text = remove_escape_sequences(json.dumps(text, ensure_ascii=False).strip('"'))
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
if __name__ == "__main__":
|
| 115 |
st.set_page_config(layout="wide")
|
| 116 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
import time
|
| 6 |
+
from helper.telemetry import collect_telemetry
|
| 7 |
from helper.upload_File import uploadFile
|
| 8 |
+
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 |
import requests
|
| 13 |
+
from google import genai
|
| 14 |
+
from openai import OpenAI
|
| 15 |
|
| 16 |
class TargetMarketAnalyst:
|
| 17 |
def __init__(self, model_url, analyst_name, data_src, analyst_description):
|
|
|
|
| 30 |
st.header(self.analyst_name)
|
| 31 |
|
| 32 |
# EVALUATION FORM LINK
|
| 33 |
+
url = os.getenv('Link')
|
| 34 |
+
st.write('Evaluation Form: [Link](%s)' % url)
|
| 35 |
|
| 36 |
def request_model(self, payload_txt):
|
| 37 |
response = requests.post(self.model_url, json=payload_txt)
|
|
|
|
| 58 |
return output
|
| 59 |
|
| 60 |
def row1(self):
|
| 61 |
+
col1, col2 = st.columns(gap="medium", spec=[0.33, 0.66])
|
| 62 |
+
with col1:
|
| 63 |
prompt = st.chat_input("How can I help you today?")
|
|
|
|
| 64 |
#client = genai.Client(api_key="AIzaSyArNeCctdKaWhxprHTnHyISCd0CpKqB5dk")
|
| 65 |
|
| 66 |
payload_txt = {
|
|
|
|
| 85 |
|
| 86 |
url = "http://172.17.21.23:7860/api/v1/run/382ac239-3231-4f9b-89fe-f5ee26e4b1eb?stream=false"
|
| 87 |
|
| 88 |
+
|
| 89 |
+
|
|
|
|
|
|
|
|
|
|
| 90 |
if prompt:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
response = requests.post(url, json=payload_txt, headers=headers, params={'stream': 'false'})
|
| 92 |
response.raise_for_status()
|
| 93 |
output = response.json()
|
|
|
|
| 97 |
return text.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
| 98 |
|
| 99 |
self.text = remove_escape_sequences(json.dumps(text, ensure_ascii=False).strip('"'))
|
| 100 |
+
'''
|
| 101 |
+
self.topics = st.text_input("Topic of Interest: ", placeholder='Enter Topic of Interest:', key='topic')
|
| 102 |
+
#self.start_date = st.date_input('Start Date:', value="today", key='start_date')
|
| 103 |
+
#self.end_date = st.date_input('End Date:', value="today", key='end_date')
|
| 104 |
+
|
| 105 |
+
self.sort = st.radio(
|
| 106 |
+
"Sort by:",
|
| 107 |
+
["Published At", "Popularity", "Relevancy"],
|
| 108 |
+
captions=[
|
| 109 |
+
"Newest articles come first",
|
| 110 |
+
"Articles from popular sources and publishers come first",
|
| 111 |
+
"Articles more closely related to topic come first",
|
| 112 |
+
],
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
if self.sort == 'Relevancy':
|
| 116 |
+
self.sort = 'relevancy'
|
| 117 |
+
elif self.sort == 'Popularity':
|
| 118 |
+
self.sort = 'popularity'
|
| 119 |
+
elif self.sort == 'Published At':
|
| 120 |
+
self.sort = 'publishedAt'
|
| 121 |
+
'''
|
| 122 |
+
with col2:
|
| 123 |
+
#st.write("") # FOR THE HIDE BUTTON
|
| 124 |
+
#st.write("") # FOR THE HIDE BUTTON
|
| 125 |
+
st.write("Content: ")
|
| 126 |
+
#st.session_state['analyzing'] = False
|
| 127 |
+
#st.write("") # FOR THE HIDE BUTTON
|
| 128 |
+
if prompt:
|
| 129 |
+
st.write(self.text)
|
| 130 |
+
#analyze_button = st.button("", disabled=initialize_analyze_session())
|
| 131 |
+
start_time = time.time()
|
| 132 |
+
'''
|
| 133 |
+
if analyze_button:
|
| 134 |
+
hide_button()
|
| 135 |
+
if self.topics:
|
| 136 |
+
combined_text = ""
|
| 137 |
+
with st.spinner('Analyzing...', show_time=True):
|
| 138 |
+
st.write('')
|
| 139 |
+
# INITIALIZING SESSIONS
|
| 140 |
+
|
| 141 |
+
combined_text += f"Topic/s of Interest: {self.topics}\n"
|
| 142 |
+
# OUTPUT FOR SEO ANALYST
|
| 143 |
+
root = 'https://newsapi.org/v2/everything?'
|
| 144 |
+
language = "en"
|
| 145 |
+
api = os.getenv('apiKey')
|
| 146 |
+
response = requests.get(f'{root}q={self.topics}&language={language}&sortBy={self.sort}&language="en"&apiKey={api}')
|
| 147 |
+
try:
|
| 148 |
+
response.raise_for_status()
|
| 149 |
+
output = response.json()
|
| 150 |
+
with st.expander("Output", expanded=True):
|
| 151 |
+
text = output['articles']
|
| 152 |
+
|
| 153 |
+
for article in text:
|
| 154 |
+
source = article['source']['name']
|
| 155 |
+
published = article['publishedAt']
|
| 156 |
+
author = article['author']
|
| 157 |
+
title = article['title']
|
| 158 |
+
description = article['description']
|
| 159 |
+
url = article['url']
|
| 160 |
+
urlImage = article['urlToImage']
|
| 161 |
+
content = article['content']
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
left_co, cent_co,last_co = st.columns(3)
|
| 165 |
+
|
| 166 |
+
if urlImage:
|
| 167 |
+
with left_co:
|
| 168 |
+
st.image(urlImage, width=400)
|
| 169 |
+
st.write(f"**{title}**")
|
| 170 |
+
st.write(f"{description}")
|
| 171 |
+
st.write(f"**Author**: {author}")
|
| 172 |
+
st.write(f"**Source**: {source}")
|
| 173 |
+
st.write('Link: [URL](%s)' % url)
|
| 174 |
+
st.write(f"**Published At**: {published}")
|
| 175 |
+
|
| 176 |
+
st.write("---")
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
st.write(article)
|
| 180 |
+
|
| 181 |
+
end_time = time.time()
|
| 182 |
+
time_lapsed = end_time - start_time
|
| 183 |
+
debug_info = {
|
| 184 |
+
'analyst': self.analyst_name,
|
| 185 |
+
'time_lapsed': time_lapsed,
|
| 186 |
+
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
collect_telemetry(debug_info)
|
| 190 |
+
|
| 191 |
+
with st.expander("Debug information", icon="⚙"):
|
| 192 |
+
st.write(debug_info)
|
| 193 |
+
|
| 194 |
+
st.session_state['analyzing'] = False
|
| 195 |
+
except requests.exceptions.HTTPError:
|
| 196 |
+
st.info("Exceeded limit, please come back tomorrow")
|
| 197 |
+
else:
|
| 198 |
+
st.info("Please provide a topic of interest")
|
| 199 |
+
hide_button()
|
| 200 |
+
'''
|
| 201 |
if __name__ == "__main__":
|
| 202 |
st.set_page_config(layout="wide")
|
| 203 |
|
requirements.txt
CHANGED
|
@@ -9,4 +9,3 @@ streamlit_paste_button
|
|
| 9 |
pymupdf
|
| 10 |
pymongo
|
| 11 |
newsapi-python
|
| 12 |
-
openai
|
|
|
|
| 9 |
pymupdf
|
| 10 |
pymongo
|
| 11 |
newsapi-python
|
|
|