Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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
|
| 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 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
nasdaq_df = pd.DataFrame()
|
| 66 |
|
| 67 |
-
# Connect to Pinecone
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 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 |
|