Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
import logging
|
4 |
from PyPDF2 import PdfReader
|
5 |
|
@@ -21,19 +21,12 @@ def extract_text_from_pdf(pdf_file):
|
|
21 |
text += page.extract_text()
|
22 |
return text
|
23 |
|
24 |
-
# Function to summarize text using the specified model and tokenizer
|
25 |
-
def summarize_text(model, tokenizer, text):
|
26 |
-
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
|
27 |
-
outputs = model.generate(inputs, max_length=130, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
28 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
-
|
30 |
def main():
|
31 |
setup_logging()
|
32 |
logging.info("Starting the Streamlit app.")
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("Falconsai/medical_summarization")
|
37 |
|
38 |
# Streamlit UI
|
39 |
st.title("GenAI Lab Report Analyzer")
|
@@ -65,16 +58,16 @@ def main():
|
|
65 |
summary = None
|
66 |
if input_type == "Text" and text:
|
67 |
logging.info("Processing text input.")
|
68 |
-
summary =
|
69 |
logging.info("Text input processed successfully.")
|
70 |
elif input_type == "Text File" and file:
|
71 |
logging.info(f"Processing text file: {file.name}")
|
72 |
text = file.read().decode("utf-8") # Assuming UTF-8 encoding
|
73 |
-
summary =
|
74 |
elif input_type == "PDF" and file:
|
75 |
logging.info(f"Processing PDF file: {file.name}")
|
76 |
text = extract_text_from_pdf(file)
|
77 |
-
summary =
|
78 |
elif input_type == "Audio" and audio:
|
79 |
logging.info("Processing audio input.")
|
80 |
# Add audio processing logic here
|
@@ -83,7 +76,7 @@ def main():
|
|
83 |
summary = "Invalid input. Please provide a valid file or text."
|
84 |
logging.warning("Invalid input type provided.")
|
85 |
|
86 |
-
st.text_area("Report Result:", summary, height=200)
|
87 |
except Exception as e:
|
88 |
logging.error(f"Error during summarization: {e}")
|
89 |
st.error("An error occurred during summarization. Please check the logs for more details.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
import logging
|
4 |
from PyPDF2 import PdfReader
|
5 |
|
|
|
21 |
text += page.extract_text()
|
22 |
return text
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def main():
|
25 |
setup_logging()
|
26 |
logging.info("Starting the Streamlit app.")
|
27 |
|
28 |
+
# Initialize the summarization pipeline with the specified model
|
29 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
30 |
|
31 |
# Streamlit UI
|
32 |
st.title("GenAI Lab Report Analyzer")
|
|
|
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
|
|
|
76 |
summary = "Invalid input. Please provide a valid file or text."
|
77 |
logging.warning("Invalid input type provided.")
|
78 |
|
79 |
+
st.text_area("Report Result:", summary[0]['summary_text'] if isinstance(summary, list) else summary, height=200)
|
80 |
except Exception as e:
|
81 |
logging.error(f"Error during summarization: {e}")
|
82 |
st.error("An error occurred during summarization. Please check the logs for more details.")
|