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