File size: 4,353 Bytes
f10c25c
75d4140
d2a58ad
f10c25c
58a57f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27a8aa3
ad1915b
db2a37e
 
 
 
e9a1e34
db2a37e
 
 
 
f10c25c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58a57f4
 
0398d1f
58a57f4
 
 
ad1915b
58a57f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8205bb
58a57f4
 
 
 
 
ad1915b
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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"])