abhidgp1978 commited on
Commit
bf33ca3
·
verified ·
1 Parent(s): 4a9d7f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -61
app.py CHANGED
@@ -1,70 +1,82 @@
1
  import gradio as gr
2
- zs_details.append((label, float(score)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
- # 3) Fallback if everything is zero
6
  if all(v == 0 for v in votes.values()):
7
  for ch in ["Instagram", "YouTube", "LinkedIn"]:
8
  votes[ch] += 1.0
9
 
10
 
11
- # 4) Rank
12
  ranked = sorted(votes.items(), key=lambda kv: kv[1], reverse=True)
13
- top = ranked[: max(1, top_n)]
14
-
15
-
16
- # 5) Build explanation & suggestions
17
- def suggestions_for(ch_name: str) -> Dict:
18
- ch = next(c for c in CHANNELS if c.name == ch_name)
19
- ideas = {
20
- "Instagram": [
21
- "3x Reels/week: product use-cases & UGC",
22
- "Stories with polls & link stickers",
23
- "Creators: micro-influencer try-ons/reviews",
24
- ],
25
- "TikTok": [
26
- "Daily short clips riding relevant trends",
27
- "Unpolished founder POV, behind-the-scenes",
28
- "Native sounds + captions for accessibility",
29
- ],
30
- "YouTube": [
31
- "Weekly 6–10 min tutorial or demo",
32
- "YouTube Shorts repurposed from TikTok/Reels",
33
- "SEO titles targeting problem keywords",
34
- ],
35
- "LinkedIn": [
36
- "3x/week carousel posts with insights",
37
- "Founder/exec thought-leadership threads",
38
- "Case-study post with hard metrics + clear CTA",
39
- ],
40
- "X (Twitter)": [
41
- "2–3 threads/week on hot topics",
42
- "Engage with niche communities daily",
43
- "Host a Spaces AMA once per month",
44
- ],
45
- "Pinterest": [
46
- "Pin boards by theme (seasonal, how-to)",
47
- "Infographic step-by-steps & checklists",
48
- "Link pins to evergreen blog/how-to pages",
49
- ],
50
- "Reddit": [
51
- "Participate in niche subreddits (no spam)",
52
- "AMA once traction is visible",
53
- "Share transparent build-in-public learnings",
54
- ],
55
- "Discord": [
56
- "Weekly office hours or support huddles",
57
- "Early access channel for power users",
58
- "Automations: welcome, FAQ, release notes",
59
- ],
60
- "Twitch": [
61
- "Monthly live stream with creators",
62
- "Sponsor segments in aligned channels",
63
- "Live Q&A around launches or updates",
64
- ],
65
- }
66
- return {
67
- "channel": ch.name,
68
- "why": ch.notes,
69
- "ideal_audience": ", ".join(ch.audience),
70
- "content_formats": ", ".join(ch.content),
 
1
  import gradio as gr
2
+ best_for=["B2B", "thought leadership", "lead gen"],
3
+ audience=["professionals"],
4
+ content=["posts", "carousels", "articles"],
5
+ notes="Reach professionals and buyers; great for B2B SaaS and services.",
6
+ ),
7
+ ]
8
+
9
+
10
+ RULES: Dict[str, List[str]] = {
11
+ "b2b": ["LinkedIn", "YouTube"],
12
+ "saas": ["LinkedIn", "YouTube"],
13
+ "tech": ["LinkedIn", "YouTube"],
14
+ "beauty": ["Instagram", "TikTok", "YouTube"],
15
+ "fashion": ["Instagram", "TikTok"],
16
+ "food": ["Instagram", "YouTube"],
17
+ "gaming": ["YouTube", "TikTok"],
18
+ }
19
+
20
+
21
+ KEYWORD_RX = re.compile(r"[a-zA-Z0-9+#-]{3,}")
22
+
23
+
24
+ def extract_keywords(text: str, top_k: int = 10) -> List[str]:
25
+ tokens = [t.lower() for t in KEYWORD_RX.findall(text)]
26
+ seen, out = set(), []
27
+ for t in tokens:
28
+ if t not in seen:
29
+ seen.add(t)
30
+ out.append(t)
31
+ if len(out) >= top_k:
32
+ break
33
+ return out
34
+
35
+
36
+ def recommend_channels(description: str):
37
+ if not description.strip():
38
+ return {"error": "Please enter a product description."}
39
+
40
+
41
+ text_lower = description.lower()
42
+ votes: Dict[str, float] = {c.name: 0.0 for c in CHANNELS}
43
+
44
+
45
+ for key, chans in RULES.items():
46
+ if key in text_lower:
47
+ for ch in chans:
48
+ votes[ch] += 1.0
49
 
50
 
 
51
  if all(v == 0 for v in votes.values()):
52
  for ch in ["Instagram", "YouTube", "LinkedIn"]:
53
  votes[ch] += 1.0
54
 
55
 
 
56
  ranked = sorted(votes.items(), key=lambda kv: kv[1], reverse=True)
57
+ return {"ranked": ranked, "keywords": extract_keywords(description)}
58
+
59
+
60
+ # -------- Gradio UI --------
61
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
62
+ gr.Markdown("# 📢 SocialChannel AI")
63
+
64
+
65
+ with gr.Row():
66
+ inp = gr.Textbox(label="Describe your product", placeholder="e.g., Organic skincare brand for Gen Z")
67
+ out = gr.Textbox(label="Recommendations")
68
+
69
+
70
+ def on_click(desc):
71
+ res = recommend_channels(desc)
72
+ if "error" in res:
73
+ return res["error"]
74
+ ranked = ", ".join([f"{name} ({score})" for name, score in res["ranked"]])
75
+ return f"Suggested channels: {ranked}\nKeywords: {', '.join(res['keywords'])}"
76
+
77
+
78
+ gr.Button("Suggest").click(on_click, inputs=inp, outputs=out)
79
+
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch()