File size: 1,273 Bytes
f473b17
840561e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from google_search import google_search
from mistral_llm import analyze_text
from utils import get_embeddings, build_index, search_similar

st.set_page_config(page_title="Brand Insight Companion", layout="wide")
st.title("πŸ” Real-Time Brand Insight Companion")

query = st.text_input("Enter a brand or keyword (e.g., 'Nvidia')")
if query:
    with st.spinner("πŸ”Ž Searching Reddit-related content..."):
        posts = google_search(f"site:reddit.com {query}", num=5)
    
    if not posts:
        st.warning("❌ No posts found.")
    else:
        st.success(f"βœ… Fetched {len(posts)} posts.")
        summaries = [analyze_text(p[:1024]) for p in posts]

        for i, summary in enumerate(summaries):
            st.subheader(f"Post {i+1}")
            st.markdown(summary)

        st.markdown("---")
        sim_query = st.text_input("Find similar posts to this topic")
        if sim_query:
            embeddings = get_embeddings(posts)
            index = build_index(embeddings)
            query_embedding = get_embeddings([sim_query])
            dists, idxs = search_similar(index, query_embedding)

            st.subheader("πŸ” Similar Posts")
            for i in idxs[0]:
                st.markdown(f"- {posts[i]}")