InstaImpact / influencer_onboarding.py
gkdivya's picture
Update influencer_onboarding.py
f8205bb
import streamlit as st
import requests
import json
# influencers_data = {
# "influencer1": {
# "onboarded": True,
# "name": "Influencer One",
# "image": "./images/inf1.png", # Replace with actual image paths
# "details": "Details about Influencer One..."
# },
# "influencer2": {
# "onboarded": True,
# "name": "Influencer Two",
# "image": "./images/inf2.png",
# "details": "Details about Influencer Two..."
# },
# "influencer3": {
# "onboarded": False,
# "name": "Influencer Two",
# "image": "./images/inf2.png"
# }
# # Add more influencers as needed
# }
profile_default_image_url = "https://t4.ftcdn.net/jpg/03/46/93/61/360_F_346936114_RaxE6OQogebgAWTalE1myseY1Hbb5qPM.jpg"
def onboard_single_influencer(handle):
url = "https://us-central1-steam-cache-277314.cloudfunctions.net/create_insta_task"
data = {"handle": handle}
response = requests.post(url, json=data)
if response.status_code == 200:
st.write("Onboarding influencer! Please wait...")
else:
st.write(response["data"]["error"])
def show_onboarding_page():
st.title("Onboard Influencers")
# Upload field for multiple influencers
uploaded_file = st.file_uploader("Upload a file with influencer handles", type=["csv", "xlsx"])
# Input for single influencer handle
single_handle = st.text_input("...or enter a single influencer handle")
# Onboard button
if st.button("Onboard Influencers"):
if uploaded_file is not None:
# Process the uploaded file
onboard_influencers_from_file(uploaded_file)
elif single_handle:
# Process the single handle
onboard_single_influencer(single_handle)
else:
st.error("Please upload a file or enter a handle.")
# Function to display onboarded influencers (placeholder)
display_onboarded_influencers()
def onboard_influencers_from_file(file):
# Logic to read and process file to onboard influencers
pass # Replace with actual implementation
def display_onboarded_influencers():
# Display the list of onboarded influencers
get_all_url = "https://us-central1-steam-cache-277314.cloudfunctions.net/get_all_influencer"
data = {}
response = requests.post(get_all_url, json=data)
if response.status_code == 200:
st.write("List of Onboarded Influencers...")
influencers_list = json.loads(response.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'))
else:
st.write(response["data"]["error"])