Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,53 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
feedback_data = pd.read_csv(filename) if os.path.exists(filename) else pd.DataFrame(columns=['Contract', 'Feedback'])
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Main Streamlit app
|
13 |
def main():
|
14 |
-
st.title("Contract Summarizer with Feedback")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
st.subheader("Input Contract:")
|
21 |
-
st.write(contract_text)
|
22 |
|
23 |
-
#
|
24 |
-
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
store_feedback(contract_text, feedback)
|
29 |
-
st.success("Feedback submitted successfully!")
|
30 |
|
31 |
# Run the app
|
32 |
if __name__ == "__main__":
|
|
|
|
|
33 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
+
# Load the EasyTerms/legalSummerizerET model from Hugging Face
|
6 |
+
summarizer = pipeline("summarization", model="EasyTerms/legalSummerizerET")
|
|
|
7 |
|
8 |
+
# Function to generate summary using the EasyTerms/legalSummerizerET model
|
9 |
+
def generate_summary(contract_text):
|
10 |
+
summary = summarizer(contract_text, max_length=150, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
|
11 |
+
return summary[0]['summary_text']
|
12 |
+
|
13 |
+
# Function to handle feedback and store it in a CSV file
|
14 |
+
def handle_feedback(feedback_data):
|
15 |
+
feedback_df = pd.DataFrame(feedback_data, columns=['Contract', 'Summary', 'Chosen', 'Rejected'])
|
16 |
+
feedback_df.to_csv('feedback.csv', mode='a', index=False, header=not st.session_state.feedback_csv_exists)
|
17 |
+
st.session_state.feedback_csv_exists = True
|
18 |
|
19 |
# Main Streamlit app
|
20 |
def main():
|
21 |
+
st.title("Legal Contract Summarizer with Feedback")
|
22 |
+
|
23 |
+
# Input area for legal contract
|
24 |
+
contract_text = st.text_area("Enter the legal contract:")
|
25 |
+
|
26 |
+
# Button to generate summary
|
27 |
+
if st.button("Generate Summary"):
|
28 |
+
summary = generate_summary(contract_text)
|
29 |
+
st.subheader("Generated Summary:")
|
30 |
+
st.write(summary)
|
31 |
+
|
32 |
+
# Feedback section
|
33 |
+
st.subheader("Feedback:")
|
34 |
+
thumbs_up = st.button("π Thumbs Up")
|
35 |
+
thumbs_down = st.button("π Thumbs Down")
|
36 |
|
37 |
+
chosen = 1 if thumbs_up else 0
|
38 |
+
rejected = 1 if thumbs_down else 0
|
39 |
|
40 |
+
feedback_data.append((contract_text, summary, chosen, rejected))
|
|
|
|
|
41 |
|
42 |
+
# Handle feedback data
|
43 |
+
if feedback_data:
|
44 |
+
handle_feedback(feedback_data)
|
45 |
|
46 |
+
# Initialize feedback data
|
47 |
+
feedback_data = []
|
|
|
|
|
48 |
|
49 |
# Run the app
|
50 |
if __name__ == "__main__":
|
51 |
+
# Create a Streamlit session state to persist variables across reruns
|
52 |
+
st.session_state.feedback_csv_exists = False
|
53 |
main()
|