File size: 3,853 Bytes
e815416
0d6d77d
e815416
 
03f7cd5
 
 
8ad376a
607d996
 
764e3a3
 
 
 
 
03f7cd5
9f4cdec
03f7cd5
e815416
 
 
03f7cd5
e815416
 
 
 
0d6d77d
03f7cd5
e815416
 
03f7cd5
 
 
e815416
 
03f7cd5
 
 
e815416
03f7cd5
 
 
e815416
 
03f7cd5
e815416
03f7cd5
bb0926c
 
 
 
 
 
 
03f7cd5
 
 
e815416
03f7cd5
bb0926c
1c445b4
42e461b
03f7cd5
bb0926c
 
 
 
 
 
91fa8ea
bb0926c
 
 
 
 
91fa8ea
bb0926c
 
42e461b
e815416
00961a0
 
 
 
587dfbd
bb0926c
35dd891
e815416
 
 
bb0926c
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
import pandas as pd
import gradio as gr
from sentence_transformers import SentenceTransformer, util

# Load merged influencer dataset
# Columns: Rank, Name, Followers, ER, Country, Niche, Reach, Source File, Source Path

df = pd.read_csv("top_100_influencers_combined.csv")
df.fillna("", inplace=True)

# Extract platform name from Source File (e.g., 'youtube_data_greece.csv' -> 'Youtube')
df['Platform'] = df['Source File'].str.split('_').str[0].str.capitalize()

# Prepare text for embedding (include platform)
profile_fields = ["Name", "Platform", "Niche", "Country"]
df["profile_text"] = df[profile_fields].agg(" - ".join, axis=1)

# Load embedding model
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
influencer_embeddings = model.encode(df["profile_text"].tolist(), convert_to_tensor=True)

# Recommendation logic: find top 3 by cosine similarity
def recommend_influencers(brand_description):
    query_embedding = model.encode(brand_description, convert_to_tensor=True)
    cosine_scores = util.pytorch_cos_sim(query_embedding, influencer_embeddings)[0]
    top_indices = cosine_scores.topk(3).indices.tolist()

    recs = []
    for idx in top_indices:
        row = df.iloc[idx]
        recs.append({
            "Name": row["Name"],
            "Platform": row.get("Platform", ""),
            "Niche": row["Niche"],
            "Country": row["Country"],
            "ER": row.get("ER", "N/A"),
            "Followers": row["Followers"],
            "Reach": row.get("Reach", "")
        })
    return recs

# Format recommendations into styled HTML cards
def format_output(brand_input):
    recs = recommend_influencers(brand_input)
    html = ""
    for i, rec in enumerate(recs, 1):
        html += f"""
        <div style='background:#ffffff; padding:1em; margin-bottom:1em; border-radius:8px; box-shadow:0 2px 6px rgba(0,0,0,0.1);'>
          <h3 style='margin:0; color:#0a1f44;'>🎯 {i}. {rec['Name']} <span style='font-size:0.9em; color:#555;'>({rec['Platform']})</span></h3>
          <p style='margin:0.5em 0;'><strong>Niche:</strong> {rec['Niche']}</p>
          <p style='margin:0.5em 0;'><strong>Country:</strong> {rec['Country']}</p>
          <p style='margin:0.5em 0;'><strong>Engagement:</strong> {rec['ER']}</p>
          <p style='margin:0.5em 0;'><strong>Followers:</strong> {rec['Followers']}</p>
          {f"<p style='margin:0.5em 0;'><strong>Reach:</strong> {rec['Reach']}</p>" if rec['Reach'] else ""}
        </div>
        """
    return html

# Build the Gradio interface
iface = gr.Interface(
    fn=format_output,
    inputs=gr.Textbox(
        lines=3,
        label="πŸ—£οΈ Describe Your Campaign or Brand",
        placeholder="e.g., Targeted fitness brand outreach for Gen Z"
    ),
    outputs=gr.HTML(
        label="πŸ“ˆ Recommended Influencers"
    ),
    title="πŸ’‘ Targeted Influencer Discovery for Social Media Marketing",
    description=(
        "Enhance your social media marketing by pinpointing the perfect influencers for your niche.\n\n"
        "πŸ› οΈ AI-driven matching based on niche, audience, and engagement metrics β€” get top 3 influencer recommendations instantly."
    ),
    article=(
        "**Project:** AI-Powered Influencer Recommender for Social Media Marketing\n"
        "**Model:** sentence-transformers/all-MiniLM-L6-v2 for semantic embeddings\n"
        "**Dataset:** Top 100 Social Media Influencers 2024 (Countrywise) from Kaggle"
    ),
    examples=[
        ["Sustainable fashion campaign targeting eco-conscious millennials"],
        ["Tech gadget launch aimed at early adopters in the US"],
        ["Healthy snack brand outreach for fitness enthusiasts"],
        ["Luxury travel experiences for affluent couples in Europe"]
    ],
    theme="soft",
    flagging_mode="never"
)

if __name__ == "__main__":
    iface.launch(share=True)