Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,9 @@ import streamlit as st
|
|
2 |
import tempfile
|
3 |
import logging
|
4 |
from typing import List
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from langchain_community.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,7 +34,7 @@ def load_llm(model_name):
|
|
35 |
"""Load and cache the language model."""
|
36 |
try:
|
37 |
pipe = pipeline("text2text-generation", model=model_name, max_length=512)
|
38 |
-
return
|
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,46 +70,7 @@ def summarize_report(documents: List[Document], llm) -> str:
|
|
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
|
75 |
-
|
76 |
-
Report Content:
|
77 |
-
{text}
|
78 |
-
|
79 |
-
Your summary should follow this structure:
|
80 |
-
|
81 |
-
Summary:
|
82 |
-
π° [TOPIC] Overview for [FOCUS_REGION]:
|
83 |
-
|
84 |
-
π΄ [FOCUS_REGION]'s Position in Global [TOPIC]:
|
85 |
-
π Total investment/funding: [amount]
|
86 |
-
π Breakdown of funding sources (e.g., government, private sector)
|
87 |
-
π [FOCUS_REGION]'s ranking in global investment
|
88 |
-
π Key statistics and figures
|
89 |
-
|
90 |
-
π΄ Financial Impact and Projections:
|
91 |
-
π Expected ROI or economic benefits
|
92 |
-
π Financial milestones or targets
|
93 |
-
π Impact on relevant areas
|
94 |
-
|
95 |
-
π΄ Global Comparison:
|
96 |
-
π [List of relevant countries/regions with their financial figures]
|
97 |
-
π Comparative analysis of [FOCUS_REGION] vs other major players
|
98 |
-
|
99 |
-
π΄ Budget Analysis:
|
100 |
-
π Major budget items
|
101 |
-
π Key budget allocations
|
102 |
-
π Year-over-year budget changes
|
103 |
-
π Comparison to industry benchmarks
|
104 |
-
|
105 |
-
π΄ Funding Strategies:
|
106 |
-
π Key funding mechanisms (e.g., grants, loans, public-private partnerships)
|
107 |
-
π Innovative financing approaches
|
108 |
-
|
109 |
-
π΄ Progress and Significance:
|
110 |
-
π Key achievements or milestones
|
111 |
-
π [1-2 concluding points about [FOCUS_REGION]'s role or significance in [TOPIC]]
|
112 |
-
|
113 |
-
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].
|
114 |
"""
|
115 |
|
116 |
prompt = PromptTemplate.from_template(prompt_template)
|
@@ -155,4 +115,4 @@ def main():
|
|
155 |
st.warning("Failed to generate summary. Please try again.")
|
156 |
|
157 |
if __name__ == "__main__":
|
158 |
-
main()
|
|
|
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 |
"""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 |
"""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)
|
|
|
115 |
st.warning("Failed to generate summary. Please try again.")
|
116 |
|
117 |
if __name__ == "__main__":
|
118 |
+
main()
|