InstaImpact / influencer_ui.py
gkdivya's picture
Update influencer_ui.py
aa50c31
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'))