WAQASCHANNA commited on
Commit
a9d4fb1
·
verified ·
1 Parent(s): 58c54c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -1,34 +1,35 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Set the title of the app
5
- st.title("Legal Document Analysis with Hugging Face and Streamlit")
6
 
7
- # Sidebar for user inputs
8
- st.sidebar.header("Upload your document")
9
- uploaded_file = st.sidebar.file_uploader("Choose a text file", type=["txt"])
10
 
 
 
 
 
 
 
 
11
  if uploaded_file is not None:
12
- # Read the file
13
  text = uploaded_file.read().decode("utf-8")
14
- st.subheader("Uploaded Document")
15
- st.write(text)
16
-
17
- # Initialize Hugging Face pipelines
18
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
19
- ner = pipeline("ner", grouped_entities=True, model="dslim/bert-base-NER")
20
-
21
- # Summarize the document
22
- with st.spinner("Generating summary..."):
23
- summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
24
- st.subheader("Summary")
25
- st.write(summary[0]['summary_text'])
26
-
27
- # Named Entity Recognition
28
- with st.spinner("Performing Named Entity Recognition..."):
29
- entities = ner(text)
30
- st.subheader("Named Entities")
31
- for entity in entities:
32
- st.write(f"**{entity['entity_group']}**: {entity['word']} (Confidence: {entity['score']:.2f})")
33
  else:
34
- st.info("Please upload a legal document to analyze.")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ st.title("Legal Document Analysis")
 
5
 
6
+ # Sidebar for uploading the document
7
+ st.sidebar.header("Upload Document")
8
+ uploaded_file = st.sidebar.file_uploader("Choose a document", type=["txt", "pdf", "docx"])
9
 
10
+ # Sidebar for setting summarization parameters
11
+ st.sidebar.header("Summarization Parameters")
12
+ max_length = st.sidebar.slider("Max Length", min_value=50, max_value=500, value=150)
13
+ min_length = st.sidebar.slider("Min Length", min_value=10, max_value=100, value=40)
14
+ do_sample = st.sidebar.checkbox("Use Sampling", value=False)
15
+
16
+ # Main area - Display content and summary
17
  if uploaded_file is not None:
 
18
  text = uploaded_file.read().decode("utf-8")
19
+
20
+ # Ensure the text is long enough
21
+ if len(text.split()) > min_length:
22
+ try:
23
+ # Load the model from Hugging Face
24
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
25
+
26
+ # Summarize the document
27
+ summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=do_sample)
28
+ st.subheader("Summary:")
29
+ st.write(summary[0]['summary_text'])
30
+ except Exception as e:
31
+ st.error(f"An error occurred: {e}")
32
+ else:
33
+ st.warning("Text is too short to summarize.")
 
 
 
 
34
  else:
35
+ st.info("Please upload a document to summarize.")