Kathirsci commited on
Commit
81cff83
Β·
verified Β·
1 Parent(s): 0b47d32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -2,9 +2,10 @@ import streamlit as st
2
  import tempfile
3
  import logging
4
  from typing import List
5
- from langchain.document_loaders import PyPDFLoader # Updated import
6
- from langchain.embeddings import HuggingFaceEmbeddings # Updated import
7
- from langchain.vectorstores import FAISS # Updated import
 
8
  from langchain.chains.summarize import load_summarize_chain
9
  from langchain.schema import Document
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
@@ -34,7 +35,7 @@ def load_llm(model_name):
34
  """Load and cache the language model."""
35
  try:
36
  pipe = pipeline("text2text-generation", model=model_name, max_length=512)
37
- return pipe
38
  except Exception as e:
39
  logger.error(f"Failed to load LLM: {e}")
40
  st.error(f"Failed to load the model {model_name}. Please try again.")
@@ -70,7 +71,36 @@ def summarize_report(documents: List[Document], llm) -> str:
70
  """Summarize the report using the loaded model."""
71
  try:
72
  prompt_template = """
73
- You are an AI specialized in summarizing comprehensive reports with a focus on funding, finances, and global comparisons. Given the detailed report content below, generate a concise and structured summary using bullet points and emojis...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  """
75
 
76
  prompt = PromptTemplate.from_template(prompt_template)
 
2
  import tempfile
3
  import logging
4
  from typing import List
5
+ from langchain.document_loaders import PyPDFLoader
6
+ from langchain.embeddings import HuggingFaceEmbeddings
7
+ from langchain.vectorstores import FAISS
8
+ from langchain.llms import HuggingFacePipeline
9
  from langchain.chains.summarize import load_summarize_chain
10
  from langchain.schema import Document
11
  from langchain.text_splitter import RecursiveCharacterTextSplitter
 
35
  """Load and cache the language model."""
36
  try:
37
  pipe = pipeline("text2text-generation", model=model_name, max_length=512)
38
+ return HuggingFacePipeline(pipeline=pipe)
39
  except Exception as e:
40
  logger.error(f"Failed to load LLM: {e}")
41
  st.error(f"Failed to load the model {model_name}. Please try again.")
 
71
  """Summarize the report using the loaded model."""
72
  try:
73
  prompt_template = """
74
+ You are an AI specialized in summarizing comprehensive reports with a focus on funding, finances, and global comparisons. Given the detailed report content below, generate a concise and structured summary using bullet points and emojis. The summary should highlight key funding figures, financial data, budget allocations, comparisons between regions, and notable insights about [FOCUS_REGION]'s role in the global context of [TOPIC].
75
+ Report Content:
76
+ {text}
77
+ Your summary should follow this structure:
78
+ Summary:
79
+ πŸ’° [TOPIC] Overview for [FOCUS_REGION]:
80
+ πŸ”΄ [FOCUS_REGION]'s Position in Global [TOPIC]:
81
+ πŸ“ Total investment/funding: [amount]
82
+ πŸ“ Breakdown of funding sources (e.g., government, private sector)
83
+ πŸ“ [FOCUS_REGION]'s ranking in global investment
84
+ πŸ“ Key statistics and figures
85
+ πŸ”΄ Financial Impact and Projections:
86
+ πŸ“ Expected ROI or economic benefits
87
+ πŸ“ Financial milestones or targets
88
+ πŸ“ Impact on relevant areas
89
+ πŸ”΄ Global Comparison:
90
+ πŸ“ [List of relevant countries/regions with their financial figures]
91
+ πŸ“ Comparative analysis of [FOCUS_REGION] vs other major players
92
+ πŸ”΄ Budget Analysis:
93
+ πŸ“ Major budget items
94
+ πŸ“ Key budget allocations
95
+ πŸ“ Year-over-year budget changes
96
+ πŸ“ Comparison to industry benchmarks
97
+ πŸ”΄ Funding Strategies:
98
+ πŸ“ Key funding mechanisms (e.g., grants, loans, public-private partnerships)
99
+ πŸ“ Innovative financing approaches
100
+ πŸ”΄ Progress and Significance:
101
+ πŸ“ Key achievements or milestones
102
+ πŸ“ [1-2 concluding points about [FOCUS_REGION]'s role or significance in [TOPIC]]
103
+ Please ensure the summary is concise, informative, and easy to read at a glance. Use precise figures where available and highlight any significant financial trends or insights. The summary should provide a comprehensive overview of both the financial aspects and the broader context of [TOPIC] in [FOCUS_REGION].
104
  """
105
 
106
  prompt = PromptTemplate.from_template(prompt_template)