mdasad3617 commited on
Commit
7be0cb3
·
verified ·
1 Parent(s): d2271c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
  import logging
 
4
 
5
  # Setup logging
6
  def setup_logging():
@@ -12,6 +13,14 @@ def setup_logging():
12
  ]
13
  )
14
 
 
 
 
 
 
 
 
 
15
  def main():
16
  setup_logging()
17
  logging.info("Starting the Streamlit app.")
@@ -35,21 +44,30 @@ def main():
35
 
36
  if input_type == "Text":
37
  text = st.text_area("Enter your text here:", placeholder="Type your text here...")
38
- elif input_type in ["Text File", "PDF", "DOCX"]:
39
- file = st.file_uploader(f"Upload your {input_type}:", type=["txt", "pdf", "docx"])
 
 
 
 
40
  elif input_type == "Audio":
41
  audio = st.file_uploader("Upload your audio file:", type=["wav", "mp3", "m4a"])
42
 
43
  if st.button("Report Result"):
44
  try:
 
45
  if input_type == "Text" and text:
46
  logging.info("Processing text input.")
47
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
48
  logging.info("Text input processed successfully.")
49
- elif input_type in ["Text File", "PDF", "DOCX"] and file:
50
- logging.info(f"Processing {input_type} file: {file.name}")
51
- # Add file reading logic here
52
- summary = "File processing not implemented yet."
 
 
 
 
53
  elif input_type == "Audio" and audio:
54
  logging.info("Processing audio input.")
55
  # Add audio processing logic here
@@ -66,4 +84,4 @@ def main():
66
  logging.info("Closing the Streamlit app.")
67
 
68
  if __name__ == "__main__":
69
- main()
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  import logging
4
+ from PyPDF2 import PdfReader
5
 
6
  # Setup logging
7
  def setup_logging():
 
13
  ]
14
  )
15
 
16
+ # Function to extract text from a PDF file
17
+ def extract_text_from_pdf(pdf_file):
18
+ pdf_reader = PdfReader(pdf_file)
19
+ text = ""
20
+ for page in pdf_reader.pages:
21
+ text += page.extract_text()
22
+ return text
23
+
24
  def main():
25
  setup_logging()
26
  logging.info("Starting the Streamlit app.")
 
44
 
45
  if input_type == "Text":
46
  text = st.text_area("Enter your text here:", placeholder="Type your text here...")
47
+ elif input_type == "Text File":
48
+ file = st.file_uploader("Upload your text file:", type=["txt"])
49
+ elif input_type == "PDF":
50
+ file = st.file_uploader("Upload your PDF file:", type=["pdf"])
51
+ elif input_type == "DOCX":
52
+ file = st.file_uploader("Upload your DOCX file:", type=["docx"])
53
  elif input_type == "Audio":
54
  audio = st.file_uploader("Upload your audio file:", type=["wav", "mp3", "m4a"])
55
 
56
  if st.button("Report Result"):
57
  try:
58
+ summary = None
59
  if input_type == "Text" and text:
60
  logging.info("Processing text input.")
61
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
62
  logging.info("Text input processed successfully.")
63
+ elif input_type == "Text File" and file:
64
+ logging.info(f"Processing text file: {file.name}")
65
+ text = file.read().decode("utf-8") # Assuming UTF-8 encoding
66
+ summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
67
+ elif input_type == "PDF" and file:
68
+ logging.info(f"Processing PDF file: {file.name}")
69
+ text = extract_text_from_pdf(file)
70
+ summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
71
  elif input_type == "Audio" and audio:
72
  logging.info("Processing audio input.")
73
  # Add audio processing logic here
 
84
  logging.info("Closing the Streamlit app.")
85
 
86
  if __name__ == "__main__":
87
+ main()