Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,76 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from transformers import pipeline, AutoTokenizer
|
4 |
-
import base64
|
5 |
-
|
6 |
-
# Load the EasyTerms/legalSummerizerET model from Hugging Face
|
7 |
-
summarizer = pipeline("summarization", model="EasyTerms/legalSummerizerET")
|
8 |
-
|
9 |
-
# Increase the maximum token limit
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained("EasyTerms/legalSummerizerET")
|
11 |
-
summarizer.model.config.max_position_embeddings = tokenizer.model_max_length
|
12 |
-
|
13 |
-
# Function to generate summary using the EasyTerms/legalSummerizerET model
|
14 |
-
def generate_summary(contract_text):
|
15 |
-
summary = summarizer(contract_text, max_length=512, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
|
16 |
-
return summary[0]['summary_text']
|
17 |
-
|
18 |
-
# Function to handle feedback and store it in a CSV file
|
19 |
-
def handle_feedback(feedback_data, feedback_file):
|
20 |
-
feedback_df = pd.DataFrame(feedback_data, columns=['Contract', 'Summary', 'π', 'π'])
|
21 |
-
|
22 |
-
# Save the dataframe to the feedback CSV file
|
23 |
-
feedback_df.to_csv(feedback_file, mode='a', index=False, header=not st.session_state.feedback_csv_exists)
|
24 |
-
|
25 |
-
# Display a feedback collected message
|
26 |
-
st.success("Feedback collected successfully!")
|
27 |
-
|
28 |
-
# Display a download button for the user
|
29 |
-
download_button = st.button("Download Feedback CSV")
|
30 |
-
|
31 |
-
# If the download button is clicked, initiate the download
|
32 |
-
if download_button:
|
33 |
-
st.markdown(get_binary_file_downloader_html(feedback_file, 'Feedback Data'), unsafe_allow_html=True)
|
34 |
-
|
35 |
-
# Function to create a download link for a binary file
|
36 |
-
def get_binary_file_downloader_html(file_path, file_label):
|
37 |
-
with open(file_path, 'rb') as file:
|
38 |
-
file_content = file.read()
|
39 |
-
b64 = base64.b64encode(file_content).decode()
|
40 |
-
return f'<a href="data:file/csv;base64,{b64}" download="{file_label}.csv">Click here to download {file_label}</a>'
|
41 |
-
|
42 |
-
# Main Streamlit app
|
43 |
-
def main():
|
44 |
-
st.title("Legal Contract Summarizer with Feedback")
|
45 |
-
|
46 |
-
# Input area for legal contract
|
47 |
-
contract_text = st.text_area("Enter the legal contract:", height=200) # Increase the height to handle larger contracts
|
48 |
-
|
49 |
-
# Button to generate summary
|
50 |
-
if st.button("Generate Summary"):
|
51 |
-
summary = generate_summary(contract_text)
|
52 |
-
st.subheader("Generated Summary:")
|
53 |
-
st.write(summary)
|
54 |
-
|
55 |
-
# Feedback section
|
56 |
-
st.subheader("Feedback:")
|
57 |
-
thumbs_up = st.button("π")
|
58 |
-
thumbs_down = st.button("π")
|
59 |
-
|
60 |
-
chosen = "π" if thumbs_up else None
|
61 |
-
rejected = "π" if thumbs_down else None
|
62 |
-
|
63 |
-
feedback_data.append((contract_text, summary, chosen, rejected))
|
64 |
-
|
65 |
-
# Handle feedback data
|
66 |
-
if feedback_data:
|
67 |
-
feedback_file = 'feedback.csv'
|
68 |
-
st.session_state.feedback_csv_exists = True
|
69 |
-
handle_feedback(feedback_data, feedback_file)
|
70 |
-
|
71 |
-
# Initialize feedback data
|
72 |
-
feedback_data = []
|
73 |
-
|
74 |
-
# Run the app
|
75 |
-
if __name__ == "__main__":
|
76 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|