Spaces:
Sleeping
Sleeping
Update influencer_ui.py
Browse files- influencer_ui.py +28 -37
influencer_ui.py
CHANGED
|
@@ -4,57 +4,48 @@ import requests
|
|
| 4 |
from io import BytesIO
|
| 5 |
import json
|
| 6 |
|
| 7 |
-
|
| 8 |
profile_default_image_url = "https://t4.ftcdn.net/jpg/03/46/93/61/360_F_346936114_RaxE6OQogebgAWTalE1myseY1Hbb5qPM.jpg"
|
| 9 |
insta_rag_url = "https://us-central1-steam-cache-277314.cloudfunctions.net/gemini-hackathon-insta-influencer"
|
| 10 |
-
# influencers_data = {
|
| 11 |
-
# "influencer1": {
|
| 12 |
-
# "name": "Influencer One",
|
| 13 |
-
# "image": "./images/inf1.png", # Replace with actual image paths
|
| 14 |
-
# "details": "Details about Influencer One..."
|
| 15 |
-
# },
|
| 16 |
-
# "influencer2": {
|
| 17 |
-
# "name": "Influencer Two",
|
| 18 |
-
# "image": "./images/inf2.png",
|
| 19 |
-
# "details": "Details about Influencer Two..."
|
| 20 |
-
# }
|
| 21 |
-
# # Add more influencers as needed
|
| 22 |
-
# }
|
| 23 |
|
| 24 |
-
|
| 25 |
def show_influencer_search_page():
|
| 26 |
st.header("Influencer Search and Analysis")
|
| 27 |
st.markdown("Discover influencers by name, niche, location, follower count, and more.")
|
| 28 |
search_query = st.text_input("Search Influencers", "")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
# Influencer search button (assuming this is part of your UI)
|
| 32 |
search_button = st.button("Search Influencers")
|
| 33 |
|
| 34 |
if search_button:
|
| 35 |
data = {"search_query": search_query}
|
| 36 |
resp = requests.post(insta_rag_url, json=data)
|
| 37 |
-
|
| 38 |
-
st.write(response_dict)
|
| 39 |
-
# Download images
|
| 40 |
-
profile_img_url = response_dict.get('profile_image_url', profile_default_image_url)
|
| 41 |
-
img_response = requests.get(profile_img_url)
|
| 42 |
-
if img_response.status_code == 200:
|
| 43 |
-
image_url = f"downloaded_image_{response_dict.get('handle', 'NoName')}.jpg"
|
| 44 |
-
with open(image_url, "wb") as file:
|
| 45 |
-
file.write(img_response.content)
|
| 46 |
-
influencers_data = {response_dict.get('handle', "No Name"): {"name": response_dict.get('name', 'No Name'),
|
| 47 |
-
"image": image_url,
|
| 48 |
-
"followers": response_dict.get('followersCount', ''),
|
| 49 |
-
"details": response_dict.get('bio', '')}}
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
col1, col2 = st.columns([1, 3])
|
| 54 |
with col1:
|
| 55 |
-
st.image(
|
| 56 |
-
|
| 57 |
with col2:
|
| 58 |
-
with st.expander("
|
| 59 |
-
st.
|
| 60 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from io import BytesIO
|
| 5 |
import json
|
| 6 |
|
|
|
|
| 7 |
profile_default_image_url = "https://t4.ftcdn.net/jpg/03/46/93/61/360_F_346936114_RaxE6OQogebgAWTalE1myseY1Hbb5qPM.jpg"
|
| 8 |
insta_rag_url = "https://us-central1-steam-cache-277314.cloudfunctions.net/gemini-hackathon-insta-influencer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
def show_influencer_search_page():
|
| 11 |
st.header("Influencer Search and Analysis")
|
| 12 |
st.markdown("Discover influencers by name, niche, location, follower count, and more.")
|
| 13 |
search_query = st.text_input("Search Influencers", "")
|
| 14 |
|
| 15 |
+
# Influencer search button
|
|
|
|
| 16 |
search_button = st.button("Search Influencers")
|
| 17 |
|
| 18 |
if search_button:
|
| 19 |
data = {"search_query": search_query}
|
| 20 |
resp = requests.post(insta_rag_url, json=data)
|
| 21 |
+
influencers_list = json.loads(resp.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
for influencer_data in influencers_list:
|
| 24 |
+
# Download image
|
| 25 |
+
profile_img_url = influencer_data.get('profile_image_url', profile_default_image_url)
|
| 26 |
+
img_response = requests.get(profile_img_url)
|
| 27 |
+
image_url = profile_default_image_url
|
| 28 |
+
if img_response.status_code == 200:
|
| 29 |
+
image_url = f"downloaded_image_{influencer_data.get('handle', 'NoName')}.jpg"
|
| 30 |
+
with open(image_url, "wb") as file:
|
| 31 |
+
file.write(img_response.content)
|
| 32 |
+
|
| 33 |
+
# Display influencer data
|
| 34 |
col1, col2 = st.columns([1, 3])
|
| 35 |
with col1:
|
| 36 |
+
st.image(image_url, width=50)
|
| 37 |
+
|
| 38 |
with col2:
|
| 39 |
+
with st.expander(f"{influencer_data.get('name', 'No Name')}'s Details"):
|
| 40 |
+
st.markdown(f"**Handle:** {influencer_data.get('handle', 'No Handle')}")
|
| 41 |
+
st.markdown(f"**Bio:** {influencer_data.get('bio', 'No Bio')}")
|
| 42 |
+
st.markdown(f"**Email:** {influencer_data.get('email', 'N/A')}")
|
| 43 |
+
st.markdown(f"**Country:** {influencer_data.get('country', 'N/A')}")
|
| 44 |
+
st.markdown(f"**Location:** {influencer_data.get('location', 'N/A')}")
|
| 45 |
+
st.markdown(f"**Followers Count:** {influencer_data.get('followers_count', 'N/A')}")
|
| 46 |
+
st.markdown(f"**Engagement Rate:** {influencer_data.get('engagement_rate', 'N/A')*100:.2f}%")
|
| 47 |
+
st.markdown("### Frequent Hashtags")
|
| 48 |
+
hashtags = influencer_data.get('frequent_hashtags', [])
|
| 49 |
+
st.write(", ".join(hashtags))
|
| 50 |
+
st.markdown("### Post Summary")
|
| 51 |
+
st.write(influencer_data.get('post_summary', 'N/A'))
|