Shruti9756 commited on
Commit
4de9de9
Β·
verified Β·
1 Parent(s): c7bee0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -1,6 +1,7 @@
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")
@@ -11,30 +12,25 @@ def generate_summary(contract_text):
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
-
17
- # Save the dataframe to a temporary CSV file
18
- temp_csv_path = 'temp_feedback.csv'
19
- feedback_df.to_csv(temp_csv_path, index=False, header=not st.session_state.feedback_csv_exists)
20
-
21
- # Display a download link for the user
22
- st.download_button(
23
- label="Download Feedback CSV",
24
- data=temp_csv_path,
25
- key="download_feedback_csv",
26
- on_click=download_feedback_csv,
27
- args=(temp_csv_path,),
28
- help="Click to download the feedback CSV file."
29
- )
30
-
31
- # Append feedback to the main CSV file
32
- feedback_df.to_csv('feedback.csv', mode='a', index=False, header=not st.session_state.feedback_csv_exists)
33
- st.session_state.feedback_csv_exists = True
34
-
35
- # Callback function for download button
36
- def download_feedback_csv(file_path):
37
- st.markdown(f"Download [Feedback CSV File]({file_path})", unsafe_allow_html=True)
38
 
39
  # Main Streamlit app
40
  def main():
@@ -51,23 +47,23 @@ def main():
51
 
52
  # Feedback section
53
  st.subheader("Feedback:")
54
- thumbs_up = st.button("πŸ‘ Thumbs Up")
55
- thumbs_down = st.button("πŸ‘Ž Thumbs Down")
56
 
57
- chosen = 1 if thumbs_up else 0
58
- rejected = 1 if thumbs_down else 0
59
 
60
  feedback_data.append((contract_text, summary, chosen, rejected))
61
 
62
  # Handle feedback data
63
  if feedback_data:
64
- handle_feedback(feedback_data)
 
 
65
 
66
  # Initialize feedback data
67
  feedback_data = []
68
 
69
  # Run the app
70
  if __name__ == "__main__":
71
- # Create a Streamlit session state to persist variables across reruns
72
- st.session_state.feedback_csv_exists = False
73
  main()
 
1
  import streamlit as st
2
  import pandas as pd
3
  from transformers import pipeline
4
+ import base64
5
 
6
  # Load the EasyTerms/legalSummerizerET model from Hugging Face
7
  summarizer = pipeline("summarization", model="EasyTerms/legalSummerizerET")
 
12
  return summary[0]['summary_text']
13
 
14
  # Function to handle feedback and store it in a CSV file
15
+ def handle_feedback(feedback_data, feedback_file):
16
+ feedback_df = pd.DataFrame(feedback_data, columns=['Contract', 'Summary', 'πŸ‘', 'πŸ‘Ž'])
17
+
18
+ # Save the dataframe to the feedback CSV file
19
+ feedback_df.to_csv(feedback_file, mode='a', index=False, header=not st.session_state.feedback_csv_exists)
20
+
21
+ # Display a download button for the user
22
+ download_button = st.button("Download Feedback CSV")
23
+
24
+ # If the download button is clicked, initiate the download
25
+ if download_button:
26
+ st.markdown(get_binary_file_downloader_html(feedback_file, 'Feedback Data'), unsafe_allow_html=True)
27
+
28
+ # Function to create a download link for a binary file
29
+ def get_binary_file_downloader_html(file_path, file_label):
30
+ with open(file_path, 'rb') as file:
31
+ file_content = file.read()
32
+ b64 = base64.b64encode(file_content).decode()
33
+ return f'<a href="data:file/csv;base64,{b64}" download="{file_label}.csv">Click here to download {file_label}</a>'
 
 
 
 
 
34
 
35
  # Main Streamlit app
36
  def main():
 
47
 
48
  # Feedback section
49
  st.subheader("Feedback:")
50
+ thumbs_up = st.button("πŸ‘")
51
+ thumbs_down = st.button("πŸ‘Ž")
52
 
53
+ chosen = "πŸ‘" if thumbs_up else None
54
+ rejected = "πŸ‘Ž" if thumbs_down else None
55
 
56
  feedback_data.append((contract_text, summary, chosen, rejected))
57
 
58
  # Handle feedback data
59
  if feedback_data:
60
+ feedback_file = 'feedback.csv'
61
+ st.session_state.feedback_csv_exists = True
62
+ handle_feedback(feedback_data, feedback_file)
63
 
64
  # Initialize feedback data
65
  feedback_data = []
66
 
67
  # Run the app
68
  if __name__ == "__main__":
 
 
69
  main()