genaibeauty commited on
Commit
42f6bbe
Β·
verified Β·
1 Parent(s): 5be8181

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from utils.pdf_processing import extract_text_from_pdf, extract_text_from_scanned_pdf
3
+ from utils.vector_store import add_document, search
4
+ from utils.stock_data import get_stock_data
5
+ from utils.sentiment import analyze_sentiment
6
+
7
+ # Define PDF folder
8
+ PDF_FOLDER = "data"
9
+
10
+ # Process and index all PDFs
11
+ def process_pdfs():
12
+ for pdf_file in os.listdir(PDF_FOLDER):
13
+ pdf_path = os.path.join(PDF_FOLDER, pdf_file)
14
+
15
+ # Extract text from normal or scanned PDFs
16
+ text = extract_text_from_pdf(pdf_path) or extract_text_from_scanned_pdf(pdf_path)
17
+
18
+ # Store in FAISS vector store
19
+ add_document(text, pdf_file)
20
+
21
+ # Query the system
22
+ def query_system(query):
23
+ results = search(query)
24
+
25
+ print("πŸ“Œ Top Matching Documents:")
26
+ for res in results:
27
+ print(f"\nπŸ“„ Document: {res.metadata['id']}\n{text[:500]}...")
28
+
29
+ # Perform sentiment analysis
30
+ print("\nπŸ“Š Sentiment Analysis:")
31
+ for res in results:
32
+ sentiment = analyze_sentiment(res.page_content)
33
+ print(f"πŸ“„ Document: {res.metadata['id']}, Sentiment: {sentiment}")
34
+
35
+ # Fetch stock data
36
+ def get_stock_info(ticker):
37
+ stock_data = get_stock_data(ticker)
38
+ print(f"\nπŸ“ˆ Stock Price for {ticker}: ${stock_data['price']}")
39
+
40
+ # Run the application
41
+ if __name__ == "__main__":
42
+ print("πŸ”„ Indexing PDFs...")
43
+ process_pdfs()
44
+
45
+ query = input("\nπŸ” Enter your query: ")
46
+ query_system(query)
47
+
48
+ ticker = input("\nπŸ“Š Enter a stock ticker (e.g., AAPL, TSLA): ")
49
+ get_stock_info(ticker)