Aarya003 commited on
Commit
6171369
Β·
verified Β·
1 Parent(s): 5da3388

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +39 -21
src/streamlit_app.py CHANGED
@@ -45,33 +45,51 @@ class RoutePrediction(BaseModel):
45
  # --- 3. CACHED INITIALIZATION ---
46
  @st.cache_resource(show_spinner=False)
47
  def initialize_resources():
48
- print("πŸ”Œ Initializing Strict-Boundary Agent...")
49
 
50
- # Setup LlamaIndex Settings
51
  Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)
52
  Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
53
 
54
- # Load CSV
55
- try:
56
- script_dir = os.path.dirname(os.path.abspath(__file__))
57
- # Combine with filename
58
- csv_path = os.path.join(script_dir, 'src/nasdaq-listed.csv')
59
- # Debug print to logs
60
- print(f"πŸ“‚ Looking for CSV at: {csv_path}")
61
- nasdaq_df = pd.read_csv('nasdaq-listed.csv')
62
- nasdaq_df.columns = [c.strip() for c in nasdaq_df.columns]
63
- except Exception as e:
64
- st.error(f"CSV Load Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  nasdaq_df = pd.DataFrame()
66
 
67
- # Connect to Pinecone
68
- api_key = os.environ.get("PINECONE_API_KEY")
69
- if not api_key: raise ValueError("Pinecone Key Missing")
70
-
71
- pc = Pinecone(api_key=api_key)
72
- index = VectorStoreIndex.from_vector_store(
73
- vector_store=PineconeVectorStore(pinecone_index=pc.Index("financial-rag-agent"))
74
- )
 
 
 
 
75
 
76
  return nasdaq_df, index
77
 
 
45
  # --- 3. CACHED INITIALIZATION ---
46
  @st.cache_resource(show_spinner=False)
47
  def initialize_resources():
48
+ print("πŸ”Œ Initializing Agent...")
49
 
 
50
  Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)
51
  Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
52
 
53
+ # --- CSV PATH FINDER ---
54
+ # We check ALL possible locations
55
+ possible_paths = [
56
+ "nasdaq-listed.csv", # Root directory
57
+ "src/nasdaq-listed.csv", # Src folder
58
+ os.path.join(os.getcwd(), "nasdaq-listed.csv"), # Current Working Directory
59
+ os.path.join(os.path.dirname(__file__), "nasdaq-listed.csv"), # Same folder as script
60
+ "../nasdaq-listed.csv" # One level up
61
+ ]
62
+
63
+ csv_path = None
64
+ for path in possible_paths:
65
+ if os.path.exists(path):
66
+ csv_path = path
67
+ print(f"βœ… Found CSV at: {path}")
68
+ break
69
+
70
+ if csv_path:
71
+ try:
72
+ nasdaq_df = pd.read_csv(csv_path)
73
+ nasdaq_df.columns = [c.strip() for c in nasdaq_df.columns]
74
+ except Exception as e:
75
+ st.error(f"CSV Corrupt: {e}")
76
+ nasdaq_df = pd.DataFrame()
77
+ else:
78
+ st.error(f"❌ CRITICAL: 'nasdaq-listed.csv' not found. I looked in: {possible_paths}")
79
  nasdaq_df = pd.DataFrame()
80
 
81
+ # --- Connect to Pinecone ---
82
+ try:
83
+ api_key = os.environ.get("PINECONE_API_KEY")
84
+ if not api_key: raise ValueError("Pinecone Key Missing")
85
+
86
+ pc = Pinecone(api_key=api_key)
87
+ index = VectorStoreIndex.from_vector_store(
88
+ vector_store=PineconeVectorStore(pinecone_index=pc.Index("financial-rag-agent"))
89
+ )
90
+ except Exception as e:
91
+ st.error(f"Pinecone Error: {e}")
92
+ return nasdaq_df, None
93
 
94
  return nasdaq_df, index
95