3v324v23 commited on
Commit
da49eac
·
1 Parent(s): 5994916

Deploy app with recommendation + slogan generator

Browse files
Files changed (1) hide show
  1. app.py +73 -3
app.py CHANGED
@@ -33,9 +33,79 @@ def recommend(query, top_k=3):
33
  results["score"] = scores[0]
34
  return results[["name", "tagline", "description", "score"]]
35
 
36
- def generate_slogan(description):
37
- # Very simple slogan generator – can be replaced with FLAN-T5 later
38
- return "Fresh Ideas for " + description.split()[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  def pipeline(user_input):
41
  recs = recommend(user_input, top_k=3)
 
33
  results["score"] = scores[0]
34
  return results[["name", "tagline", "description", "score"]]
35
 
36
+ def generate_slogan(query_text, neighbors_df=None, n_samples=16):
37
+ ctx = _neighbor_context(neighbors_df)
38
+ prompt = (
39
+ "You are a creative brand copywriter. Write short, original, memorable startup slogans (max 8 words).
40
+ "
41
+ "Forbidden words: app, assistant, platform, solution, system, marketplace, AI, machine learning, augmented reality, virtual reality, decentralized, empower.
42
+ "
43
+ "Focus on clear benefits and vivid verbs. Do not copy the description. Return ONLY a list, one slogan per line.
44
+
45
+ "
46
+ "Good Examples:
47
+ "
48
+ "Description: AI assistant for doctors to prioritize patient cases
49
+ "
50
+ "Slogan: Less Guessing. More Healing.
51
+
52
+ "
53
+ "Description: Payments for small online stores
54
+ "
55
+ "Slogan: Built to Grow with Your Cart.
56
+
57
+ "
58
+ "Description: Neurotech headset to boost focus
59
+ "
60
+ "Slogan: Train Your Brain to Win.
61
+
62
+ "
63
+ )
64
+ if ctx:
65
+ prompt += f"Similar taglines (style only):
66
+ {ctx}
67
+
68
+ "
69
+ prompt += f"Description: {query_text}
70
+ Slogans:"
71
+
72
+ input_ids = GEN_TOK(prompt, return_tensors="pt").input_ids.to(DEVICE)
73
+ outputs = GEN_MODEL.generate(
74
+ input_ids,
75
+ max_new_tokens=24,
76
+ do_sample=True,
77
+ top_k=60,
78
+ top_p=0.92,
79
+ temperature=1.2,
80
+ num_return_sequences=n_samples,
81
+ repetition_penalty=1.08
82
+ )
83
+
84
+ raw_cands = [GEN_TOK.decode(o, skip_special_tokens=True) for o in outputs]
85
+
86
+ cand_set = set()
87
+ for txt in raw_cands:
88
+ for line in txt.split("
89
+ "):
90
+ s = _clean_slogan(line)
91
+ if not s:
92
+ continue
93
+ if len(s.split()) < 2 or len(s.split()) > 8:
94
+ continue
95
+ if _is_blocked_slogan(s):
96
+ continue
97
+ cand_set.add(_titlecase_soft(s))
98
+
99
+ if not cand_set:
100
+ return _clean_slogan(GEN_TOK.decode(outputs[0], skip_special_tokens=True))
101
+
102
+ scored = _score_candidates(query_text, sorted(cand_set), neighbors_df)
103
+ if not scored:
104
+ return _clean_slogan(GEN_TOK.decode(outputs[0], skip_special_tokens=True))
105
+
106
+ scored.sort(key=lambda x: x[1], reverse=True)
107
+ return scored[0][0]
108
+
109
 
110
  def pipeline(user_input):
111
  recs = recommend(user_input, top_k=3)