Spaces:
Runtime error
Runtime error
File size: 1,539 Bytes
42f6bbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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)
|