n0v33n commited on
Commit
11a2bf7
Β·
1 Parent(s): ea6c750

Uldated app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -24,18 +24,24 @@ if not GOOGLE_API_KEY:
24
  genai.configure(api_key=GOOGLE_API_KEY)
25
 
26
  # β€”β€”β€” Load or fallback LeetCode data β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
 
27
  GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/1KK9Mnm15hV3ALJo-quJndftWfaujJ7K2_zHMCTo5mGE/"
28
  FILE_ID = GOOGLE_SHEET_URL.split("/d/")[1].split("/")[0]
29
  DOWNLOAD_URL = f"https://drive.google.com/uc?export=download&id={FILE_ID}"
30
- OUTPUT_FILE = "leetcode_downloaded.xlsx"
31
 
32
  try:
33
- print("Downloading LeetCode data...")
34
- gdown.download(DOWNLOAD_URL, OUTPUT_FILE, quiet=False)
35
- LEETCODE_DATA = pd.read_excel(OUTPUT_FILE)
 
 
 
 
 
36
  print(f"Loaded {len(LEETCODE_DATA)} problems")
37
- except Exception:
38
- print("Failed to download/read. Using fallback.")
 
39
  LEETCODE_DATA = pd.DataFrame([
40
  {"problem_no": 3151, "problem_level": "Easy", "problem_statement": "special array",
41
  "problem_link": "https://leetcode.com/problems/special-array-i/?envType=daily-question&envId=2025-06-01"},
@@ -284,6 +290,7 @@ User Query: {query}
284
  user_sessions.setdefault(session_key, {"history": []})
285
 
286
  tool_name, args = self._classify_intent(query)
 
287
 
288
  if tool_name not in self.tools:
289
  return f"I couldn't understand your request. Please try asking for:\n- Daily coding question\n- Mock interview\n- Interview questions for a specific topic"
@@ -314,6 +321,7 @@ class ChatResponse(BaseModel):
314
  @app.post("/chat", response_model=ChatResponse)
315
  async def chat(req: ChatRequest):
316
  q = preprocess_query(req.question)
 
317
  ans = agent.process_query(q, req.user_id, req.session_id)
318
  return ChatResponse(session_id=req.session_id, answer=ans)
319
 
@@ -330,4 +338,4 @@ def root():
330
 
331
  if __name__ == "__main__":
332
  import uvicorn
333
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
24
  genai.configure(api_key=GOOGLE_API_KEY)
25
 
26
  # β€”β€”β€” Load or fallback LeetCode data β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
27
+ OUTPUT_FILE = "leetcode_downloaded.xlsx"
28
  GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/1KK9Mnm15hV3ALJo-quJndftWfaujJ7K2_zHMCTo5mGE/"
29
  FILE_ID = GOOGLE_SHEET_URL.split("/d/")[1].split("/")[0]
30
  DOWNLOAD_URL = f"https://drive.google.com/uc?export=download&id={FILE_ID}"
 
31
 
32
  try:
33
+ if os.path.exists(OUTPUT_FILE):
34
+ print(f"Loading LeetCode data from local file: {OUTPUT_FILE}")
35
+ LEETCODE_DATA = pd.read_excel(OUTPUT_FILE)
36
+ else:
37
+ print("Local LeetCode file not found. Attempting to download...")
38
+ print("Downloading LeetCode data...")
39
+ gdown.download(DOWNLOAD_URL, OUTPUT_FILE, quiet=False)
40
+ LEETCODE_DATA = pd.read_excel(OUTPUT_FILE)
41
  print(f"Loaded {len(LEETCODE_DATA)} problems")
42
+ except Exception as e:
43
+ print(f"Failed to load or download LeetCode data: {str(e)}")
44
+ print("Using fallback dataset.")
45
  LEETCODE_DATA = pd.DataFrame([
46
  {"problem_no": 3151, "problem_level": "Easy", "problem_statement": "special array",
47
  "problem_link": "https://leetcode.com/problems/special-array-i/?envType=daily-question&envId=2025-06-01"},
 
290
  user_sessions.setdefault(session_key, {"history": []})
291
 
292
  tool_name, args = self._classify_intent(query)
293
+ print(f"Selected tool: {tool_name}, args: {args}") # Debug log
294
 
295
  if tool_name not in self.tools:
296
  return f"I couldn't understand your request. Please try asking for:\n- Daily coding question\n- Mock interview\n- Interview questions for a specific topic"
 
321
  @app.post("/chat", response_model=ChatResponse)
322
  async def chat(req: ChatRequest):
323
  q = preprocess_query(req.question)
324
+ print(f"Preprocessed query: {q}") # Debug log
325
  ans = agent.process_query(q, req.user_id, req.session_id)
326
  return ChatResponse(session_id=req.session_id, answer=ans)
327
 
 
338
 
339
  if __name__ == "__main__":
340
  import uvicorn
341
+ uvicorn.run(app, host="0.0.0.0", port=8000)