mishrasahil934 commited on
Commit
9f71231
·
verified ·
1 Parent(s): f4d2744
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from dotenv import load_dotenv
2
  load_dotenv()
3
-
 
4
  import streamlit as st
5
  from langchain.text_splitter import RecursiveCharacterTextSplitter
6
  from langchain.document_loaders import PyPDFLoader,DirectoryLoader
@@ -70,7 +71,12 @@ def displayPDF(file):
70
  #streamlit code
71
  st.set_page_config(layout='wide')
72
 
73
- import os
 
 
 
 
 
74
 
75
  def main():
76
  st.title('Content Summarizer')
@@ -81,22 +87,18 @@ def main():
81
  if st.button("Summarize"):
82
  col1, col2 = st.columns(2)
83
 
84
- # Ensure the directory exists
85
- data_dir = "data"
86
- if not os.path.exists(data_dir):
87
- os.makedirs(data_dir)
88
-
89
- filepath = os.path.join(data_dir, uploaded_file.name)
90
- with open(filepath, 'wb') as temp_file:
91
  temp_file.write(uploaded_file.read())
 
92
 
93
  with col1:
94
  st.info("Uploaded PDF File")
95
- pdf_viewer = displayPDF(filepath)
96
 
97
  with col2:
98
  st.info("Summarization is below")
99
- summary = llm_pipleline(filepath)
100
  st.success(summary)
101
  else:
102
  st.warning("Please upload a valid PDF file.")
 
1
  from dotenv import load_dotenv
2
  load_dotenv()
3
+ import os
4
+ from tempfile import NamedTemporaryFile
5
  import streamlit as st
6
  from langchain.text_splitter import RecursiveCharacterTextSplitter
7
  from langchain.document_loaders import PyPDFLoader,DirectoryLoader
 
71
  #streamlit code
72
  st.set_page_config(layout='wide')
73
 
74
+
75
+
76
+ def main():
77
+ st.title('Content Summarizer')
78
+
79
+ uploaded_file = st.file_uploader("Upload your PDF file", type=['pdf'])
80
 
81
  def main():
82
  st.title('Content Summarizer')
 
87
  if st.button("Summarize"):
88
  col1, col2 = st.columns(2)
89
 
90
+ # Save the uploaded file to a temporary location
91
+ with NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
 
 
 
 
 
92
  temp_file.write(uploaded_file.read())
93
+ temp_filepath = temp_file.name
94
 
95
  with col1:
96
  st.info("Uploaded PDF File")
97
+ pdf_viewer = displayPDF(temp_filepath)
98
 
99
  with col2:
100
  st.info("Summarization is below")
101
+ summary = llm_pipleline(temp_filepath)
102
  st.success(summary)
103
  else:
104
  st.warning("Please upload a valid PDF file.")