WAQASCHANNA commited on
Commit
541879f
·
verified ·
1 Parent(s): b3a0493

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -32,18 +32,9 @@ def chunk_text(text, chunk_size=1000):
32
 
33
  # Function to classify text as law-related or not using zero-shot classification
34
  def classify_text(text):
35
- # Load the zero-shot classification pipeline
36
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
37
-
38
- # Define the candidate labels
39
  candidate_labels = ["law-related", "not law-related"]
40
-
41
- # Run the classifier with the candidate labels
42
  result = classifier(text[:512], candidate_labels=candidate_labels)
43
-
44
- st.write(f"Classification result: {result}")
45
-
46
- # Check if the highest-scoring label is "law-related"
47
  return result['labels'][0] == "law-related"
48
 
49
  # Main area - Display content and perform tasks
@@ -56,11 +47,12 @@ if uploaded_file is not None:
56
 
57
  uploaded_file.seek(0) # Reset file pointer to the beginning
58
  text = uploaded_file.read().decode(encoding)
59
- st.write("File content loaded successfully!") # Debugging: Confirm file loading
60
 
61
- # Classify the text
62
  if classify_text(text):
63
- st.write("This document is classified as law-related.") # Debugging: Confirm classification
 
 
64
  chunks = chunk_text(text, chunk_size=1000)
65
 
66
  if task == "Summarization":
 
32
 
33
  # Function to classify text as law-related or not using zero-shot classification
34
  def classify_text(text):
 
35
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
 
 
36
  candidate_labels = ["law-related", "not law-related"]
 
 
37
  result = classifier(text[:512], candidate_labels=candidate_labels)
 
 
 
 
38
  return result['labels'][0] == "law-related"
39
 
40
  # Main area - Display content and perform tasks
 
47
 
48
  uploaded_file.seek(0) # Reset file pointer to the beginning
49
  text = uploaded_file.read().decode(encoding)
 
50
 
51
+ # Classify the text before proceeding with summarization or NER
52
  if classify_text(text):
53
+ st.write("This document is classified as law-related.")
54
+
55
+ # Chunk the text if it is too long
56
  chunks = chunk_text(text, chunk_size=1000)
57
 
58
  if task == "Summarization":