Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,35 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.title("Legal Document Analysis with Hugging Face and Streamlit")
|
| 6 |
|
| 7 |
-
# Sidebar for
|
| 8 |
-
st.sidebar.header("Upload
|
| 9 |
-
uploaded_file = st.sidebar.file_uploader("Choose a
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
if uploaded_file is not None:
|
| 12 |
-
# Read the file
|
| 13 |
text = uploaded_file.read().decode("utf-8")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 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
|
|
|
|
| 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.")
|