Spaces:
Runtime error
Runtime error
feat: implement recommendation engine components for novel project idea generation
Browse files
src/recommendation_engine/chatbot_engine.py
CHANGED
|
@@ -437,6 +437,7 @@ def chatbot(user_id: str, user_input: str):
|
|
| 437 |
state.setdefault("waiting_for_feature_title", False)
|
| 438 |
state.setdefault("waiting_for_full_project_domain", False)
|
| 439 |
state.setdefault("waiting_for_full_project_selection", False)
|
|
|
|
| 440 |
|
| 441 |
|
| 442 |
|
|
@@ -1232,12 +1233,31 @@ Choose what you want:
|
|
| 1232 |
|
| 1233 |
|
| 1234 |
if state.get("waiting_for_niche_domain"):
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1241 |
|
| 1242 |
elif state.get("waiting_for_domain"):
|
| 1243 |
|
|
@@ -1247,7 +1267,8 @@ Choose what you want:
|
|
| 1247 |
state["waiting_for_domain"] = False
|
| 1248 |
state["waiting_for_niche_domain"] = True
|
| 1249 |
|
| 1250 |
-
niche_domains = generate_list(build_niche_domains_prompt(), task="idea")
|
|
|
|
| 1251 |
|
| 1252 |
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1253 |
response = (
|
|
|
|
| 437 |
state.setdefault("waiting_for_feature_title", False)
|
| 438 |
state.setdefault("waiting_for_full_project_domain", False)
|
| 439 |
state.setdefault("waiting_for_full_project_selection", False)
|
| 440 |
+
state.setdefault("suggested_domains", [])
|
| 441 |
|
| 442 |
|
| 443 |
|
|
|
|
| 1233 |
|
| 1234 |
|
| 1235 |
if state.get("waiting_for_niche_domain"):
|
| 1236 |
+
text_lower = user_input.strip().lower()
|
| 1237 |
+
more_words = ["more", "other", "another", "different", "none", "generate more"]
|
| 1238 |
+
|
| 1239 |
+
if any(w in text_lower for w in more_words) and len(text_lower.split()) < 5:
|
| 1240 |
+
previous_domains = state.get("suggested_domains", [])
|
| 1241 |
+
niche_domains = generate_list(build_niche_domains_prompt(previous_domains), task="idea")
|
| 1242 |
+
|
| 1243 |
+
state["suggested_domains"] = previous_domains + niche_domains
|
| 1244 |
+
|
| 1245 |
+
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1246 |
+
response = (
|
| 1247 |
+
f"Here are some MORE niche and cutting-edge domain ideas:\n\n"
|
| 1248 |
+
f"{domain_list_str}\n\n"
|
| 1249 |
+
f"Which one would you like to explore? (Or type your own!)"
|
| 1250 |
+
)
|
| 1251 |
+
save_user_memory(user_id, {"history": history, "state": state})
|
| 1252 |
+
return finalize_response(user_input, response, history, state, user_id)
|
| 1253 |
+
else:
|
| 1254 |
+
domain = user_input.strip()
|
| 1255 |
+
state["waiting_for_niche_domain"] = False
|
| 1256 |
+
state["suggested_domains"] = []
|
| 1257 |
+
analysis["domain"] = domain
|
| 1258 |
+
analysis["intent"] = "idea"
|
| 1259 |
+
if "project_title" in analysis:
|
| 1260 |
+
del analysis["project_title"]
|
| 1261 |
|
| 1262 |
elif state.get("waiting_for_domain"):
|
| 1263 |
|
|
|
|
| 1267 |
state["waiting_for_domain"] = False
|
| 1268 |
state["waiting_for_niche_domain"] = True
|
| 1269 |
|
| 1270 |
+
niche_domains = generate_list(build_niche_domains_prompt([]), task="idea")
|
| 1271 |
+
state["suggested_domains"] = niche_domains
|
| 1272 |
|
| 1273 |
domain_list_str = "\n".join(f"- {d}" for d in niche_domains)
|
| 1274 |
response = (
|
src/recommendation_engine/config.py
CHANGED
|
@@ -48,7 +48,7 @@ DEFAULT_IDEA_COUNT = int(os.getenv("DEFAULT_IDEA_COUNT", 5))
|
|
| 48 |
GENERATION_BATCH_SIZE = int(os.getenv("GENERATION_BATCH_SIZE", 10))
|
| 49 |
|
| 50 |
IDEA_DUPLICATE_THRESHOLD = float(
|
| 51 |
-
os.getenv("IDEA_DUPLICATE_THRESHOLD", 0.
|
| 52 |
)
|
| 53 |
|
| 54 |
FEATURE_DUPLICATE_THRESHOLD = float(
|
|
|
|
| 48 |
GENERATION_BATCH_SIZE = int(os.getenv("GENERATION_BATCH_SIZE", 10))
|
| 49 |
|
| 50 |
IDEA_DUPLICATE_THRESHOLD = float(
|
| 51 |
+
os.getenv("IDEA_DUPLICATE_THRESHOLD", 0.15)
|
| 52 |
)
|
| 53 |
|
| 54 |
FEATURE_DUPLICATE_THRESHOLD = float(
|
src/recommendation_engine/context_builder.py
CHANGED
|
@@ -422,11 +422,11 @@ def build_domain_context(
|
|
| 422 |
|
| 423 |
extracted = extract_domain(domain)
|
| 424 |
|
| 425 |
-
if extracted:
|
| 426 |
domain_clean = extracted
|
| 427 |
else:
|
| 428 |
-
logger.
|
| 429 |
-
f"[DOMAIN
|
| 430 |
)
|
| 431 |
|
| 432 |
domain_clean = normalize(domain)
|
|
|
|
| 422 |
|
| 423 |
extracted = extract_domain(domain)
|
| 424 |
|
| 425 |
+
if extracted and extracted != "Others":
|
| 426 |
domain_clean = extracted
|
| 427 |
else:
|
| 428 |
+
logger.info(
|
| 429 |
+
f"[DOMAIN INFO] Using custom dynamic domain: {domain}"
|
| 430 |
)
|
| 431 |
|
| 432 |
domain_clean = normalize(domain)
|
src/recommendation_engine/idea_generator.py
CHANGED
|
@@ -7,6 +7,7 @@ from src.recommendation_engine.llm_client import generate_text
|
|
| 7 |
from src.recommendation_engine.validator import validate_generated_list
|
| 8 |
|
| 9 |
from src.similarity_model import compare_two_ideas, load_metadata
|
|
|
|
| 10 |
from src.recommendation_engine.config import DEFAULT_IDEA_COUNT
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
|
@@ -14,24 +15,9 @@ logger = logging.getLogger(__name__)
|
|
| 14 |
MAX_RETRIES = 5
|
| 15 |
SIMILARITY_THRESHOLD_LOCAL = 0.60
|
| 16 |
|
| 17 |
-
DATA_TITLES = set()
|
| 18 |
-
|
| 19 |
def normalize_idea(text: str) -> str:
|
| 20 |
return " ".join(text.lower().strip().split())
|
| 21 |
|
| 22 |
-
def init_dataset_titles():
|
| 23 |
-
global DATA_TITLES
|
| 24 |
-
|
| 25 |
-
df = load_metadata()
|
| 26 |
-
|
| 27 |
-
if df is not None and "project_title" in df.columns:
|
| 28 |
-
DATA_TITLES = set(
|
| 29 |
-
normalize_idea(t)
|
| 30 |
-
for t in df["project_title"].dropna()
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
init_dataset_titles()
|
| 34 |
-
|
| 35 |
def clean_ideas(ideas: List[str]) -> List[str]:
|
| 36 |
return [i.strip() for i in ideas if 2 <= len(i.split()) <= 8]
|
| 37 |
|
|
@@ -142,21 +128,9 @@ def generate_ideas(
|
|
| 142 |
if not normalized:
|
| 143 |
continue
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
logger.info(f"[SKIP DATASET EXACT] {idea}")
|
| 149 |
-
continue
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
skip_dataset_similar = False
|
| 153 |
-
for data_title in list(DATA_TITLES)[:500]:
|
| 154 |
-
if compare_two_ideas(idea, data_title) >= 0.40:
|
| 155 |
-
logger.info(f"[SKIP DATASET SIMILAR] {idea}")
|
| 156 |
-
skip_dataset_similar = True
|
| 157 |
-
break
|
| 158 |
-
|
| 159 |
-
if skip_dataset_similar:
|
| 160 |
continue
|
| 161 |
|
| 162 |
|
|
|
|
| 7 |
from src.recommendation_engine.validator import validate_generated_list
|
| 8 |
|
| 9 |
from src.similarity_model import compare_two_ideas, load_metadata
|
| 10 |
+
from src.recommendation_engine.novelty_checker import is_idea_novel
|
| 11 |
from src.recommendation_engine.config import DEFAULT_IDEA_COUNT
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
|
|
|
| 15 |
MAX_RETRIES = 5
|
| 16 |
SIMILARITY_THRESHOLD_LOCAL = 0.60
|
| 17 |
|
|
|
|
|
|
|
| 18 |
def normalize_idea(text: str) -> str:
|
| 19 |
return " ".join(text.lower().strip().split())
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def clean_ideas(ideas: List[str]) -> List[str]:
|
| 22 |
return [i.strip() for i in ideas if 2 <= len(i.split()) <= 8]
|
| 23 |
|
|
|
|
| 128 |
if not normalized:
|
| 129 |
continue
|
| 130 |
|
| 131 |
+
# Use full database check for >= 85% originality
|
| 132 |
+
if not is_idea_novel(idea):
|
| 133 |
+
logger.info(f"[SKIP DATASET SIMILAR] {idea}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
continue
|
| 135 |
|
| 136 |
|
src/recommendation_engine/prompt_builder.py
CHANGED
|
@@ -98,11 +98,17 @@ BAD FEATURE EXAMPLES:
|
|
| 98 |
OUTPUT:
|
| 99 |
""".strip()
|
| 100 |
|
| 101 |
-
def build_niche_domains_prompt() -> str:
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
You are an AI innovation consultant.
|
| 104 |
Generate 5 highly niche, unusual, and cutting-edge domains for graduation projects.
|
| 105 |
Avoid standard domains like: AI, Machine Learning, Healthcare, Finance, Education, CyberSecurity, Cloud, E-Commerce, IoT.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
Give me just the names of the domains, one per line.
|
| 107 |
Keep them concise (2-4 words).
|
| 108 |
Example:
|
|
|
|
| 98 |
OUTPUT:
|
| 99 |
""".strip()
|
| 100 |
|
| 101 |
+
def build_niche_domains_prompt(previous_domains: List[str] = None) -> str:
|
| 102 |
+
previous_domains = previous_domains or []
|
| 103 |
+
prev_text = list_to_text(previous_domains, 20)
|
| 104 |
+
return f"""
|
| 105 |
You are an AI innovation consultant.
|
| 106 |
Generate 5 highly niche, unusual, and cutting-edge domains for graduation projects.
|
| 107 |
Avoid standard domains like: AI, Machine Learning, Healthcare, Finance, Education, CyberSecurity, Cloud, E-Commerce, IoT.
|
| 108 |
+
|
| 109 |
+
PREVIOUSLY SUGGESTED (DO NOT REPEAT THESE):
|
| 110 |
+
{prev_text}
|
| 111 |
+
|
| 112 |
Give me just the names of the domains, one per line.
|
| 113 |
Keep them concise (2-4 words).
|
| 114 |
Example:
|