rolwinpinto commited on
Commit
dd35c43
·
verified ·
1 Parent(s): 6022d39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -3,14 +3,17 @@ import streamlit as st
3
  import PyPDF2
4
  import matplotlib.pyplot as plt
5
  from io import BytesIO
6
- from llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader
7
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
8
  from llama_index.llms.huggingface import HuggingFaceLLM
9
- import requests
 
 
 
10
 
11
  # Configure Hugging Face model
12
- Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
13
- Settings.llm = HuggingFaceLLM(model_name="sarvamai/sarvam-2b-v0.5", api_token=os.getenv("HUGGINGFACE_API_KEY"))
14
 
15
  def write_to_file(content, filename="./files/test.pdf"):
16
  os.makedirs(os.path.dirname(filename), exist_ok=True)
@@ -23,11 +26,11 @@ def ingest_documents():
23
  return documents
24
 
25
  def load_data(documents):
26
- index = VectorStoreIndex.from_documents(documents)
27
  return index
28
 
29
  def generate_summary(index, document_text):
30
- query_engine = index.as_query_engine()
31
  response = query_engine.query(f"""
32
  You are a financial analyst. Your task is to provide a comprehensive summary of the given financial document.
33
  Analyze the following document and summarize it:
@@ -41,7 +44,7 @@ def generate_summary(index, document_text):
41
  5. Future outlook or forecasts
42
  6. Any notable financial risks or opportunities
43
 
44
- Provide a clear, concise, and professional summary
45
  """)
46
  return response.response
47
 
 
3
  import PyPDF2
4
  import matplotlib.pyplot as plt
5
  from io import BytesIO
6
+ from llama_index import VectorStoreIndex, SimpleDirectoryReader
7
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
8
  from llama_index.llms.huggingface import HuggingFaceLLM
9
+ import dotenv
10
+
11
+ # Load environment variables
12
+ dotenv.load_dotenv()
13
 
14
  # Configure Hugging Face model
15
+ embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
16
+ llm_model = HuggingFaceLLM(model_name="sarvamai/sarvam-2b-v0.5", api_token=os.getenv("HUGGINGFACE_API_KEY"))
17
 
18
  def write_to_file(content, filename="./files/test.pdf"):
19
  os.makedirs(os.path.dirname(filename), exist_ok=True)
 
26
  return documents
27
 
28
  def load_data(documents):
29
+ index = VectorStoreIndex.from_documents(documents, embed_model=embed_model)
30
  return index
31
 
32
  def generate_summary(index, document_text):
33
+ query_engine = index.as_query_engine(llm_model=llm_model)
34
  response = query_engine.query(f"""
35
  You are a financial analyst. Your task is to provide a comprehensive summary of the given financial document.
36
  Analyze the following document and summarize it:
 
44
  5. Future outlook or forecasts
45
  6. Any notable financial risks or opportunities
46
 
47
+ Provide a clear, concise, and professional summary.
48
  """)
49
  return response.response
50