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." )