File size: 3,550 Bytes
73c998c a0fa350 73c998c 85b2d30 73c998c a0fa350 73c998c |
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 |
import streamlit as st
from exa_py import Exa
from groq import Groq
# Streamlit App Title
st.title("Company Website Analysis Tool with Exa and Groq")
# Input fields for EXA and GROQ API keys and company URL
EXA_API_KEY = st.text_input("EXA API Key", type="password")
GROQ_API_KEY = st.text_input("GROQ API Key - This demo uses llama-3.2-90b-text-preview", type="password")
input_url = st.text_input("Company URL", placeholder="huggingface.co")
# Sliders for Groq model settings
max_tokens = st.slider("Max Tokens", min_value=1024, max_value=8192, value=4096, step=1024)
temperature = st.slider("Temperature", min_value=0.1, max_value=2.0, value=1.0, step=0.1)
# Button to trigger the analysis
if st.button("Analyze Company"):
if EXA_API_KEY and GROQ_API_KEY and input_url:
try:
# Initialize EXA client
exa = Exa(api_key=EXA_API_KEY)
# Get 5 similar companies
search_response = exa.find_similar_and_contents(
input_url,
highlights={"num_sentences": 2},
num_results=5
)
companies = search_response.results
# Extract the first company's data for demonstration
c = companies[0]
all_contents = ""
search_response = exa.search_and_contents(
c.url, # Input the company's URL
type="keyword",
num_results=3
)
research_response = search_response.results
for r in research_response:
all_contents += r.text
# Initialize GROQ client
client = Groq(api_key=GROQ_API_KEY)
# Define system message and call the Groq API for summarization
SYSTEM_MESSAGE = (
"You are a helpful assistant writing a research summary about a company. "
"Summarize the user's input into multiple paragraphs. Be extremely concise, "
"professional, and factual as possible. The first paragraph should be an introduction "
"and summary of the company. The second paragraph should be a detailed summary of the company."
)
# Get the summary from Groq
completion = client.chat.completions.create(
model="llama-3.2-90b-text-preview",
messages=[
{"role": "system", "content": SYSTEM_MESSAGE},
{"role": "user", "content": all_contents},
],
temperature=temperature,
max_tokens=max_tokens,
top_p=1,
stream=False,
stop=None,
)
# Extract summary content
summary = completion.choices[0].message.content
# Display the summary in Streamlit with markdown formatting for readability
st.markdown(f"### {c.title}")
st.markdown(summary)
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please provide all inputs: EXA API Key, GROQ API Key, and Company URL.")
# Disclaimer Section
st.markdown("---")
st.caption(
"Disclaimer: This tool is built for demonstration purposes only and should not be used as a basis for investment decisions. "
"The analysis generated by large language models may contain inaccuracies, and the content is not intended as professional financial advice."
)
|