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