Spaces:
Runtime error
Runtime error
Ahmadkhan12
commited on
Commit
•
b2aa777
1
Parent(s):
5a5d589
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,20 @@ def prepare_dataset(dataset_name):
|
|
40 |
documents = dataset['train']['text'][:100] # Use a subset for demo purposes
|
41 |
titles = dataset['train']['title'][:100] # Get corresponding titles
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# Streamlit App Code
|
44 |
st.title("Legal Case Summarizer")
|
45 |
st.write("Select a dataset and enter keywords to retrieve and summarize relevant cases.")
|
@@ -62,7 +76,7 @@ if st.button("Retrieve and Summarize Cases"):
|
|
62 |
summary = summaries[i]
|
63 |
st.write(f"### Case {i + 1}")
|
64 |
st.write(f"**Title:** {title}")
|
65 |
-
st.write(f"**Case Text:** {case}")
|
66 |
st.write(f"**Summary:** {summary}")
|
67 |
else:
|
68 |
st.write("No cases found for the given query.")
|
|
|
40 |
documents = dataset['train']['text'][:100] # Use a subset for demo purposes
|
41 |
titles = dataset['train']['title'][:100] # Get corresponding titles
|
42 |
|
43 |
+
# Function for case retrieval and summarization
|
44 |
+
def retrieve_cases(query):
|
45 |
+
# Implement a simple keyword-based search for demo purposes
|
46 |
+
return [(doc, title) for doc, title in zip(documents, titles) if query.lower() in doc.lower()]
|
47 |
+
|
48 |
+
def summarize_cases(cases):
|
49 |
+
summaries = []
|
50 |
+
for case in cases:
|
51 |
+
input_ids = t5_tokenizer.encode(case[0], return_tensors="pt", max_length=512, truncation=True)
|
52 |
+
outputs = t5_model.generate(input_ids, max_length=60, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
53 |
+
summary = t5_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
54 |
+
summaries.append(summary)
|
55 |
+
return summaries
|
56 |
+
|
57 |
# Streamlit App Code
|
58 |
st.title("Legal Case Summarizer")
|
59 |
st.write("Select a dataset and enter keywords to retrieve and summarize relevant cases.")
|
|
|
76 |
summary = summaries[i]
|
77 |
st.write(f"### Case {i + 1}")
|
78 |
st.write(f"**Title:** {title}")
|
79 |
+
st.write(f"**Case Text:** {case[0]}")
|
80 |
st.write(f"**Summary:** {summary}")
|
81 |
else:
|
82 |
st.write("No cases found for the given query.")
|