File size: 2,593 Bytes
ff656b4
a4e59bc
 
 
3140df4
ff656b4
3140df4
 
82be1ff
ff656b4
 
 
 
834e183
9bd87e6
5872f21
ff656b4
82be1ff
3140df4
 
9bd87e6
14e4b23
9bd87e6
 
 
 
 
 
 
 
 
 
 
834e183
 
a2d7e5f
9bd87e6
834e183
9bd87e6
 
 
 
 
 
 
 
 
 
aa50c31
9bd87e6
 
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
import streamlit as st
from PIL import Image
import requests
from io import BytesIO
import json

profile_default_image_url = "https://t4.ftcdn.net/jpg/03/46/93/61/360_F_346936114_RaxE6OQogebgAWTalE1myseY1Hbb5qPM.jpg"
insta_rag_url = "https://us-central1-steam-cache-277314.cloudfunctions.net/gemini-hackathon-insta-influencer"

def show_influencer_search_page():
    st.header("Influencer Search and Analysis")
    st.markdown("Discover influencers by name, niche, location, follower count, and more.")
    search_query = st.text_input("Search Influencers", "")
    
    # Influencer search button
    search_button = st.button("Search Influencers")
    
    if search_button:
        data = {"search_query": search_query}
        resp = requests.post(insta_rag_url, json=data)
        influencers_list = json.loads(resp.text)

        for influencer_data in influencers_list:
            # Download image
            profile_img_url = influencer_data.get('profile_image_url', profile_default_image_url)
            img_response = requests.get(profile_img_url)
            image_url = profile_default_image_url
            if img_response.status_code == 200:
                image_url = f"downloaded_image_{influencer_data.get('handle', 'NoName')}.jpg"
                with open(image_url, "wb") as file:
                    file.write(img_response.content)

            # Display influencer data
            col1, col2 = st.columns([1, 3])
            with col1:
                st.image(image_url, width=150)
            
            with col2:
                with st.expander(f"{influencer_data.get('name', 'No Name')}'s Details"):
                    st.markdown(f"**Handle:** {influencer_data.get('handle', 'No Handle')}")
                    st.markdown(f"**Bio:** {influencer_data.get('bio', 'No Bio')}")
                    st.markdown(f"**Email:** {influencer_data.get('email', 'N/A')}")
                    st.markdown(f"**Country:** {influencer_data.get('country', 'N/A')}")
                    st.markdown(f"**Location:** {influencer_data.get('location', 'N/A')}")
                    st.markdown(f"**Followers Count:** {influencer_data.get('followers_count', 'N/A')}")
                    st.markdown(f"**Engagement Rate:** {influencer_data.get('engagement_rate', 'N/A')*100:.2f}%")
                    st.markdown("### Frequent Hashtags")
                    hashtags = influencer_data.get('frequent_hashtags', [])
                    st.write(hashtags)
                    st.markdown("### Post Summary")
                    st.write(influencer_data.get('post_summary', 'N/A'))