Spaces:
Runtime error
Runtime error
import os | |
from utils.pdf_processing import extract_text_from_pdf, extract_text_from_scanned_pdf | |
from utils.vector_store import add_document, search | |
from utils.stock_data import get_stock_data | |
from utils.sentiment import analyze_sentiment | |
# Define PDF folder | |
PDF_FOLDER = "data" | |
# Process and index all PDFs | |
def process_pdfs(): | |
for pdf_file in os.listdir(PDF_FOLDER): | |
pdf_path = os.path.join(PDF_FOLDER, pdf_file) | |
# Extract text from normal or scanned PDFs | |
text = extract_text_from_pdf(pdf_path) or extract_text_from_scanned_pdf(pdf_path) | |
# Store in FAISS vector store | |
add_document(text, pdf_file) | |
# Query the system | |
def query_system(query): | |
results = search(query) | |
print("π Top Matching Documents:") | |
for res in results: | |
print(f"\nπ Document: {res.metadata['id']}\n{text[:500]}...") | |
# Perform sentiment analysis | |
print("\nπ Sentiment Analysis:") | |
for res in results: | |
sentiment = analyze_sentiment(res.page_content) | |
print(f"π Document: {res.metadata['id']}, Sentiment: {sentiment}") | |
# Fetch stock data | |
def get_stock_info(ticker): | |
stock_data = get_stock_data(ticker) | |
print(f"\nπ Stock Price for {ticker}: ${stock_data['price']}") | |
# Run the application | |
if __name__ == "__main__": | |
print("π Indexing PDFs...") | |
process_pdfs() | |
query = input("\nπ Enter your query: ") | |
query_system(query) | |
ticker = input("\nπ Enter a stock ticker (e.g., AAPL, TSLA): ") | |
get_stock_info(ticker) | |