bat-6 commited on
Commit
da78d1c
·
1 Parent(s): 9498c9f
Data/database/__pycache__/sql_connector.cpython-313.pyc CHANGED
Binary files a/Data/database/__pycache__/sql_connector.cpython-313.pyc and b/Data/database/__pycache__/sql_connector.cpython-313.pyc differ
 
Data/database/sql_connector.py CHANGED
@@ -40,35 +40,55 @@ except Exception as e:
40
 
41
 
42
  def load_preprocessed_projects():
 
 
 
 
 
43
 
44
- query = """
45
- SELECT *
46
- FROM PreProcessed_Projects
47
- """
48
 
49
- df = pd.read_sql(
50
- query,
51
- engine
52
- )
53
 
54
- if "features" in df.columns:
55
 
56
- def parse_features(x):
 
57
 
58
- if not isinstance(x, str):
59
- return x
60
-
61
- try:
62
- x = json.loads(x)
63
-
64
- if isinstance(x, str):
65
  x = json.loads(x)
66
 
67
- return x
68
-
69
- except Exception:
70
- return []
71
-
72
- df["features"] = df["features"].apply(parse_features)
73
-
74
- return df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
  def load_preprocessed_projects():
43
+ try:
44
+ query = """
45
+ SELECT *
46
+ FROM PreProcessed_Projects
47
+ """
48
 
49
+ df = pd.read_sql(
50
+ query,
51
+ engine
52
+ )
53
 
54
+ if "features" in df.columns:
 
 
 
55
 
56
+ def parse_features(x):
57
 
58
+ if not isinstance(x, str):
59
+ return x
60
 
61
+ try:
 
 
 
 
 
 
62
  x = json.loads(x)
63
 
64
+ if isinstance(x, str):
65
+ x = json.loads(x)
66
+
67
+ return x
68
+
69
+ except Exception:
70
+ return []
71
+
72
+ df["features"] = df["features"].apply(parse_features)
73
+
74
+ return df
75
+
76
+ except Exception as e:
77
+ print(f"Database connection failed, falling back to local metadata file. Error: {e}")
78
+ import os
79
+ from pathlib import Path
80
+ possible_paths = [
81
+ Path("models/metadata.parquet"),
82
+ Path(__file__).resolve().parent.parent.parent / "models" / "metadata.parquet",
83
+ Path("../models/metadata.parquet"),
84
+ ]
85
+ for path in possible_paths:
86
+ if path.exists():
87
+ print(f"Loading local metadata from {path}")
88
+ df = pd.read_parquet(path)
89
+ if "features" in df.columns:
90
+ df["features"] = df["features"].apply(
91
+ lambda x: x.tolist() if hasattr(x, "tolist") else (list(x) if isinstance(x, (list, tuple, set)) else [])
92
+ )
93
+ return df
94
+ raise FileNotFoundError(f"Could not connect to database and local metadata.parquet was not found. Looked in: {[str(p) for p in possible_paths]}")
api/__pycache__/__init__.cpython-313.pyc CHANGED
Binary files a/api/__pycache__/__init__.cpython-313.pyc and b/api/__pycache__/__init__.cpython-313.pyc differ
 
api/__pycache__/main.cpython-313.pyc CHANGED
Binary files a/api/__pycache__/main.cpython-313.pyc and b/api/__pycache__/main.cpython-313.pyc differ
 
api/__pycache__/schemas.cpython-313.pyc CHANGED
Binary files a/api/__pycache__/schemas.cpython-313.pyc and b/api/__pycache__/schemas.cpython-313.pyc differ
 
api/__pycache__/services.cpython-313.pyc CHANGED
Binary files a/api/__pycache__/services.cpython-313.pyc and b/api/__pycache__/services.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc and b/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/command_handler.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/command_handler.cpython-313.pyc and b/src/recommendation_engine/__pycache__/command_handler.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc and b/src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/feature_generator.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/feature_generator.cpython-313.pyc and b/src/recommendation_engine/__pycache__/feature_generator.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/full_project_generator.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/full_project_generator.cpython-313.pyc and b/src/recommendation_engine/__pycache__/full_project_generator.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc and b/src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc and b/src/recommendation_engine/__pycache__/llm_router.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/memory_store.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/memory_store.cpython-313.pyc and b/src/recommendation_engine/__pycache__/memory_store.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/novelty_checker.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/novelty_checker.cpython-313.pyc and b/src/recommendation_engine/__pycache__/novelty_checker.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc and b/src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc and b/src/recommendation_engine/__pycache__/response_formatter.cpython-313.pyc differ
 
src/recommendation_engine/__pycache__/state_manager.cpython-313.pyc CHANGED
Binary files a/src/recommendation_engine/__pycache__/state_manager.cpython-313.pyc and b/src/recommendation_engine/__pycache__/state_manager.cpython-313.pyc differ
 
src/similarity_model/llm_feature_extractor.py CHANGED
@@ -114,17 +114,57 @@ def extract_features_llm(text: str):
114
 
115
  prompt = build_feature_prompt(text)
116
 
117
- time.sleep(4)
 
118
 
119
- response = generate_text(
120
- prompt,
121
- task="feature",
122
- temperature = 0
123
- )
 
124
 
125
- return parse_features_response(
126
- response
127
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
 
130
  def parse_features_response(response: str):
 
114
 
115
  prompt = build_feature_prompt(text)
116
 
117
+ # Short delay to prevent hitting rate limits
118
+ time.sleep(1)
119
 
120
+ try:
121
+ response = generate_text(
122
+ prompt,
123
+ task="feature",
124
+ temperature = 0
125
+ )
126
 
127
+ return parse_features_response(
128
+ response
129
+ )
130
+ except Exception as e:
131
+ print(f"Gemini feature extraction failed, falling back to local dictionary-based keyword matching. Error: {e}")
132
+ try:
133
+ import pandas as pd
134
+ import numpy as np
135
+ from pathlib import Path
136
+
137
+ possible_paths = [
138
+ Path("models/metadata.parquet"),
139
+ Path(__file__).resolve().parent.parent.parent / "models" / "metadata.parquet",
140
+ Path("../models/metadata.parquet"),
141
+ ]
142
+
143
+ features_dict = set()
144
+ for path in possible_paths:
145
+ if path.exists():
146
+ df = pd.read_parquet(path)
147
+ for f_list in df['features']:
148
+ if isinstance(f_list, (list, np.ndarray, set, tuple)):
149
+ features_dict.update([str(f).strip().lower() for f in f_list])
150
+ break
151
+
152
+ text_lower = text.lower()
153
+ matched = []
154
+
155
+ # Sort by length descending to match longer keywords first (e.g. 'deep learning' before 'learning')
156
+ for f in sorted(list(features_dict), key=len, reverse=True):
157
+ if len(f) > 2:
158
+ pattern = r'\b' + re.escape(f) + r'\b'
159
+ if re.search(pattern, text_lower):
160
+ matched.append(f)
161
+ if len(matched) >= 10:
162
+ break
163
+ print(f"Local fallback matched features: {matched}")
164
+ return matched
165
+ except Exception as local_err:
166
+ print(f"Local feature extraction fallback failed: {local_err}")
167
+ return []
168
 
169
 
170
  def parse_features_response(response: str):