|
import streamlit as st |
|
from exa_py import Exa |
|
from groq import Groq |
|
|
|
|
|
st.title("Company Website Analysis Tool with Exa and Groq") |
|
|
|
|
|
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.1-8b-instant", type="password") |
|
input_url = st.text_input("Company URL", placeholder="huggingface.co") |
|
|
|
|
|
max_tokens = st.slider("Max Tokens", min_value=1024, max_value=8000, value=4096, step=256) |
|
temperature = st.slider("Temperature", min_value=0.1, max_value=2.0, value=1.0, step=0.1) |
|
|
|
|
|
if st.button("Analyze Company"): |
|
if EXA_API_KEY and GROQ_API_KEY and input_url: |
|
try: |
|
|
|
exa = Exa(api_key=EXA_API_KEY) |
|
|
|
|
|
search_response = exa.find_similar_and_contents( |
|
input_url, |
|
highlights={"num_sentences": 2}, |
|
num_results=5 |
|
) |
|
companies = search_response.results |
|
|
|
|
|
c = companies[0] |
|
all_contents = "" |
|
search_response = exa.search_and_contents( |
|
c.url, |
|
type="keyword", |
|
num_results=3 |
|
) |
|
research_response = search_response.results |
|
for r in research_response: |
|
all_contents += r.text |
|
|
|
|
|
client = Groq(api_key=GROQ_API_KEY) |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
completion = client.chat.completions.create( |
|
model="llama-3.1-8b-instant", |
|
messages=[ |
|
{"role": "system", "content": SYSTEM_MESSAGE}, |
|
{"role": "user", "content": all_contents}, |
|
], |
|
temperature=temperature, |
|
max_tokens=max_tokens, |
|
top_p=1, |
|
stream=False, |
|
stop=None, |
|
) |
|
|
|
|
|
summary = completion.choices[0].message.content |
|
|
|
|
|
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.") |
|
|
|
|
|
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." |
|
) |
|
|