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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -1,29 +1,69 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def main():
5
- # Set up the Streamlit app title and description
6
- st.title("Hugging Face Model Summarization")
7
- st.write("This app uses a Hugging Face model to summarize text. Enter your text below and click 'Summarize'.")
8
 
9
- # Initialize the summarization pipeline from Hugging Face
10
  summarizer = pipeline("summarization")
11
 
12
- # Create a text area for user input
13
- text = st.text_area("Enter text here:", placeholder="Type your text here...")
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # Button to trigger summarization
16
- if st.button("Summarize"):
17
- if text:
18
- try:
19
- # Generate the summary using the Hugging Face model
 
 
 
 
 
 
20
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
21
- st.write("Summary:")
22
- st.write(summary[0]['summary_text'])
23
- except Exception as e:
24
- st.error(f"An error occurred during summarization: {e}")
25
- else:
26
- st.error("Please enter some text to summarize.")
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  if __name__ == "__main__":
29
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ import logging
4
+
5
+ # Setup logging
6
+ def setup_logging():
7
+ logging.basicConfig(
8
+ level=logging.INFO,
9
+ format='%(asctime)s - %(levelname)s - %(message)s',
10
+ handlers=[
11
+ logging.StreamHandler()
12
+ ]
13
+ )
14
 
15
  def main():
16
+ setup_logging()
17
+ logging.info("Starting the Streamlit app.")
 
18
 
19
+ # Initialize the summarization pipeline
20
  summarizer = pipeline("summarization")
21
 
22
+ # Streamlit UI
23
+ st.title("GenAI Lab Report Analyzer")
24
+ st.write("Upload a file, record audio, or type text to generate a summary. Select the appropriate input type and provide the input.")
25
+
26
+ input_type = st.radio(
27
+ "Select Input Type:",
28
+ options=["Text", "Text File", "PDF", "DOCX", "Audio"],
29
+ index=0
30
+ )
31
+
32
+ file = None
33
+ text = None
34
+ audio = None
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
56
+ summary = "Audio processing not implemented yet."
57
+ else:
58
+ summary = "Invalid input. Please provide a valid file or text."
59
+ logging.warning("Invalid input type provided.")
60
+
61
+ st.text_area("Report Result:", summary[0]['summary_text'] if isinstance(summary, list) else summary, height=200)
62
+ except Exception as e:
63
+ logging.error(f"Error during summarization: {e}")
64
+ st.error("An error occurred during summarization. Please check the logs for more details.")
65
+
66
+ logging.info("Closing the Streamlit app.")
67
 
68
  if __name__ == "__main__":
69
  main()