yoniif commited on
Commit
587dfbd
·
verified ·
1 Parent(s): 03f7cd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
app.py CHANGED
@@ -9,7 +9,6 @@ df = pd.read_csv("top_100_influencers_combined.csv")
9
  df.fillna("", inplace=True)
10
 
11
  # Prepare text for embedding
12
- # You can include 'Reach' or other metrics as needed
13
  profile_fields = ["Name", "Niche", "Country"]
14
  df["profile_text"] = df[profile_fields].agg(" - ".join, axis=1)
15
 
@@ -18,7 +17,6 @@ model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
18
  influencer_embeddings = model.encode(df["profile_text"].tolist(), convert_to_tensor=True)
19
 
20
  # Recommendation logic: find top 3 by cosine similarity
21
-
22
  def recommend_influencers(brand_description):
23
  query_embedding = model.encode(brand_description, convert_to_tensor=True)
24
  cosine_scores = util.pytorch_cos_sim(query_embedding, influencer_embeddings)[0]
@@ -39,23 +37,33 @@ def recommend_influencers(brand_description):
39
  return recs
40
 
41
  # Format recommendations into styled HTML cards
42
-
43
  def format_output(brand_input):
44
  recs = recommend_influencers(brand_input)
45
  html = ""
46
  for i, rec in enumerate(recs, 1):
47
  html += f"""
48
- <div style='padding:1em; margin-bottom:1em; border:1px solid #e0e0e0; border-radius:8px; background:#fff;'>
49
- <h3 style='margin:0 0 .5em;'>{i}. {rec['Name']} <span style='font-size:0.8em; color:#666;'>({rec['Platform']})</span></h3>
50
- <p style='margin:0.2em 0;'><strong>Niche:</strong> {rec['Niche']}</p>
51
- <p style='margin:0.2em 0;'><strong>Country:</strong> {rec['Country']}</p>
52
- <p style='margin:0.2em 0;'><strong>Engagement Rate:</strong> {rec['ER']}</p>
53
- <p style='margin:0.2em 0;'><strong>Followers:</strong> {rec['Followers']}</p>
54
- {f"<p style='margin:0.2em 0;'><strong>Reach:</strong> {rec['Reach']}</p>" if rec['Reach'] else ""}
55
  </div>
56
  """
57
  return html
58
 
 
 
 
 
 
 
 
 
 
 
 
59
  # Build the Gradio interface
60
  demo = gr.Interface(
61
  fn=format_output,
@@ -67,19 +75,17 @@ demo = gr.Interface(
67
  ),
68
  outputs=gr.HTML(elem_id="output-cards"),
69
  title="InfluMatch – AI-Powered Influencer Recommender",
70
- description="""
71
- <div style='max-width:600px; margin-bottom:1em; color:#333;'>
72
- <p><strong>InfluMatch</strong> helps you discover the ideal influencers for your brand using AI-driven similarity matching.</p>
73
- <p>Simply enter a short description of your brand or campaign to get three top influencer recommendations.</p>
74
- </div>
75
- """,
76
- theme="default",
77
  examples=[
78
- ["Skincare brand for Gen Z women in the US"],
79
- ["High-end travel gear targeting adventure enthusiasts in Europe"],
80
- ["Eco-friendly fitness apparel for millennials"],
81
- ["Gourmet pet food brand seeking Instagram influencers in Canada"]
82
- ]
 
 
 
 
83
  )
84
 
85
  if __name__ == "__main__":
 
9
  df.fillna("", inplace=True)
10
 
11
  # Prepare text for embedding
 
12
  profile_fields = ["Name", "Niche", "Country"]
13
  df["profile_text"] = df[profile_fields].agg(" - ".join, axis=1)
14
 
 
17
  influencer_embeddings = model.encode(df["profile_text"].tolist(), convert_to_tensor=True)
18
 
19
  # Recommendation logic: find top 3 by cosine similarity
 
20
  def recommend_influencers(brand_description):
21
  query_embedding = model.encode(brand_description, convert_to_tensor=True)
22
  cosine_scores = util.pytorch_cos_sim(query_embedding, influencer_embeddings)[0]
 
37
  return recs
38
 
39
  # Format recommendations into styled HTML cards
 
40
  def format_output(brand_input):
41
  recs = recommend_influencers(brand_input)
42
  html = ""
43
  for i, rec in enumerate(recs, 1):
44
  html += f"""
45
+ <div class='card'>
46
+ <h3>{i}. {rec['Name']} <span class='platform'>({rec['Platform']})</span></h3>
47
+ <p><strong>Niche:</strong> {rec['Niche']}</p>
48
+ <p><strong>Country:</strong> {rec['Country']}</p>
49
+ <p><strong>Engagement Rate:</strong> {rec['ER']}</p>
50
+ <p><strong>Followers:</strong> {rec['Followers']}</p>
51
+ {f"<p><strong>Reach:</strong> {rec['Reach']}</p>" if rec['Reach'] else ""}
52
  </div>
53
  """
54
  return html
55
 
56
+ # Custom CSS for dark-blue, professional theme
57
+ custom_css = """
58
+ body { background-color: #0a1f44; color: #f0f0f0; font-family: 'Roboto', sans-serif; }
59
+ #input-box textarea { background-color: #1f305b !important; color: #ffffff; border: none; border-radius: 8px; }
60
+ #output-cards .card { background-color: #112857; color: #e0e0e0; border: none; border-radius: 10px; padding: 1em; margin-bottom: 1em; box-shadow: 0 4px 8px rgba(0,0,0,0.3); }
61
+ #output-cards h3 { margin-bottom: 0.3em; color: #ffd700; font-size: 1.3em; }
62
+ #output-cards .platform { font-size: 0.9em; color: #cccccc; }
63
+ .interface-title { color: #ffffff !important; font-size: 2em !important; }
64
+ .interface-description { color: #c0c0c0 !important; }
65
+ """
66
+
67
  # Build the Gradio interface
68
  demo = gr.Interface(
69
  fn=format_output,
 
75
  ),
76
  outputs=gr.HTML(elem_id="output-cards"),
77
  title="InfluMatch – AI-Powered Influencer Recommender",
78
+ description="Enter your brand or campaign description and get three top influencer matches.",
 
 
 
 
 
 
79
  examples=[
80
+ ["Skincare brand for Gen Z women in the US"],
81
+ ["High-end travel gear targeting adventure enthusiasts in Europe"],
82
+ ["Eco-friendly fitness apparel for millennials"],
83
+ ["Gourmet pet food brand seeking Instagram influencers in Canada"]
84
+ ],
85
+ css=custom_css,
86
+ theme="default",
87
+ layout="vertical",
88
+ allow_flagging=False
89
  )
90
 
91
  if __name__ == "__main__":