Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|