Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,9 @@ st.title("Legal Document Analysis")
|
|
| 8 |
st.sidebar.header("Upload Document")
|
| 9 |
uploaded_file = st.sidebar.file_uploader("Choose a document", type=["txt"])
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Sidebar for selecting task
|
| 12 |
st.sidebar.header("Select Task")
|
| 13 |
task = st.sidebar.selectbox("Choose the task you want to perform:", ("Summarization", "Named Entity Recognition (NER)"))
|
|
@@ -38,15 +41,19 @@ def classify_text(text):
|
|
| 38 |
return result['labels'][0] == "law-related"
|
| 39 |
|
| 40 |
# Main area - Display content and perform tasks
|
| 41 |
-
if uploaded_file is not None:
|
| 42 |
try:
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
encoding
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Classify the text before proceeding with summarization or NER
|
| 52 |
if classify_text(text):
|
|
@@ -77,7 +84,7 @@ if uploaded_file is not None:
|
|
| 77 |
for entity in entities:
|
| 78 |
st.write(f"{entity['entity_group']} - {entity['word']} (Score: {entity['score']:.2f})")
|
| 79 |
else:
|
| 80 |
-
st.warning("The uploaded document does not contain law-related content. Please
|
| 81 |
|
| 82 |
except IndexError as e:
|
| 83 |
st.error(f"IndexError: {e}. Ensure the text is long enough and parameters are set correctly.")
|
|
@@ -88,4 +95,4 @@ if uploaded_file is not None:
|
|
| 88 |
except Exception as e:
|
| 89 |
st.error(f"An unexpected error occurred: {e}")
|
| 90 |
else:
|
| 91 |
-
st.info("Please upload a document to analyze.")
|
|
|
|
| 8 |
st.sidebar.header("Upload Document")
|
| 9 |
uploaded_file = st.sidebar.file_uploader("Choose a document", type=["txt"])
|
| 10 |
|
| 11 |
+
# Add text input box for user-provided text
|
| 12 |
+
user_input = st.text_area("Or enter text directly for analysis:")
|
| 13 |
+
|
| 14 |
# Sidebar for selecting task
|
| 15 |
st.sidebar.header("Select Task")
|
| 16 |
task = st.sidebar.selectbox("Choose the task you want to perform:", ("Summarization", "Named Entity Recognition (NER)"))
|
|
|
|
| 41 |
return result['labels'][0] == "law-related"
|
| 42 |
|
| 43 |
# Main area - Display content and perform tasks
|
| 44 |
+
if uploaded_file is not None or user_input:
|
| 45 |
try:
|
| 46 |
+
# If a file is uploaded, read the file content
|
| 47 |
+
if uploaded_file:
|
| 48 |
+
encoding = detect_encoding(uploaded_file)
|
| 49 |
+
if encoding is None:
|
| 50 |
+
encoding = 'utf-8' # Fallback to default encoding
|
| 51 |
+
|
| 52 |
+
uploaded_file.seek(0) # Reset file pointer to the beginning
|
| 53 |
+
text = uploaded_file.read().decode(encoding)
|
| 54 |
+
else:
|
| 55 |
+
# If no file is uploaded, use user input
|
| 56 |
+
text = user_input
|
| 57 |
|
| 58 |
# Classify the text before proceeding with summarization or NER
|
| 59 |
if classify_text(text):
|
|
|
|
| 84 |
for entity in entities:
|
| 85 |
st.write(f"{entity['entity_group']} - {entity['word']} (Score: {entity['score']:.2f})")
|
| 86 |
else:
|
| 87 |
+
st.warning("The uploaded document or entered text does not contain law-related content. Please provide relevant content.")
|
| 88 |
|
| 89 |
except IndexError as e:
|
| 90 |
st.error(f"IndexError: {e}. Ensure the text is long enough and parameters are set correctly.")
|
|
|
|
| 95 |
except Exception as e:
|
| 96 |
st.error(f"An unexpected error occurred: {e}")
|
| 97 |
else:
|
| 98 |
+
st.info("Please upload a document or enter text to analyze.")
|