Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import logging
|
3 |
-
from transformers import pipeline
|
4 |
-
from services.text_input_handler import handle_text_input
|
5 |
-
from services.file_input_handler import read_text_file, read_pdf_file, read_docx_file
|
6 |
-
from services.audio_input_handler import audio_to_text
|
7 |
-
from utils.logging_utils import setup_logging
|
8 |
-
|
9 |
-
class TextSummarizer:
|
10 |
-
def __init__(self, model_name="t5-small"):
|
11 |
-
self.summarizer = pipeline("summarization", model=model_name)
|
12 |
-
|
13 |
-
def summarize(self, text):
|
14 |
-
if not text:
|
15 |
-
return "No text to summarize."
|
16 |
-
summary = self.summarizer(text, max_length=150, min_length=30, do_sample=False)
|
17 |
-
return summary[0]['summary_text']
|
18 |
-
|
19 |
-
def main():
|
20 |
-
# Setup logging
|
21 |
-
setup_logging()
|
22 |
-
logging.info("Starting GenAI Lab Report Analyzer with Streamlit.")
|
23 |
-
|
24 |
-
# Initialize summarizer
|
25 |
-
summarizer = TextSummarizer()
|
26 |
-
|
27 |
-
# Streamlit UI
|
28 |
-
st.title("GenAI Lab Report Analyzer")
|
29 |
-
st.write("Upload a file, record audio, or type text to generate a summary. Select the appropriate input type and provide the input.")
|
30 |
-
|
31 |
-
input_type = st.radio(
|
32 |
-
"Select Input Type:",
|
33 |
-
options=["Text", "Text File", "PDF", "DOCX", "Audio"],
|
34 |
-
index=0
|
35 |
-
)
|
36 |
-
|
37 |
-
file = None
|
38 |
-
text = None
|
39 |
-
audio = None
|
40 |
-
|
41 |
-
if input_type == "Text":
|
42 |
-
text = st.text_area("Enter your text here:", placeholder="Type your text here...")
|
43 |
-
elif input_type in ["Text File", "PDF", "DOCX"]:
|
44 |
-
file = st.file_uploader(f"Upload your {input_type}:", type=["txt", "pdf", "docx"])
|
45 |
-
elif input_type == "Audio":
|
46 |
-
audio = st.file_uploader("Upload your audio file:", type=["wav", "mp3", "m4a"])
|
47 |
-
|
48 |
-
if st.button("Report Result"):
|
49 |
-
try:
|
50 |
-
if input_type == "Text" and text:
|
51 |
-
logging.info("Processing text input.")
|
52 |
-
processed_text = handle_text_input(text)
|
53 |
-
summary = summarizer.summarize(processed_text)
|
54 |
-
logging.info("Text input processed successfully.")
|
55 |
-
elif input_type in ["Text File", "PDF", "DOCX"] and file:
|
56 |
-
if input_type == "Text File":
|
57 |
-
logging.info(f"Processing text file: {file.name}")
|
58 |
-
processed_text = read_text_file(file)
|
59 |
-
elif input_type == "PDF":
|
60 |
-
logging.info(f"Processing PDF file: {file.name}")
|
61 |
-
processed_text = read_pdf_file(file)
|
62 |
-
elif input_type == "DOCX":
|
63 |
-
logging.info(f"Processing DOCX file: {file.name}")
|
64 |
-
processed_text = read_docx_file(file)
|
65 |
-
|
66 |
-
if processed_text:
|
67 |
-
summary = summarizer.summarize(processed_text)
|
68 |
-
logging.info(f"{input_type} processed successfully.")
|
69 |
-
else:
|
70 |
-
summary = "Failed to process the file. Check logs for more details."
|
71 |
-
logging.error(f"Failed to process {input_type}: {file.name}")
|
72 |
-
elif input_type == "Audio" and audio:
|
73 |
-
logging.info("Processing audio input.")
|
74 |
-
processed_text = audio_to_text(audio)
|
75 |
-
if processed_text:
|
76 |
-
summary = summarizer.summarize(processed_text)
|
77 |
-
logging.info("Audio input processed successfully.")
|
78 |
-
else:
|
79 |
-
summary = "Failed to convert audio to text. Check logs for more details."
|
80 |
-
logging.error("Failed to convert audio to text.")
|
81 |
-
else:
|
82 |
-
summary = "Invalid input. Please provide a valid file or text."
|
83 |
-
logging.warning("Invalid input type provided.")
|
84 |
-
|
85 |
-
st.text_area("Report Result:", summary, height=200)
|
86 |
-
except Exception as e:
|
87 |
-
logging.error(f"Error during summarization: {e}")
|
88 |
-
st.error("An error occurred during summarization. Please check the logs for more details.")
|
89 |
-
|
90 |
-
logging.info("Closing GenAI Lab Report Analyzer with Streamlit.")
|
91 |
-
|
92 |
-
if __name__ == "__main__":
|
93 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|