Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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', '
|
16 |
-
|
17 |
-
# Save the dataframe to
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
)
|
30 |
-
|
31 |
-
|
32 |
-
|
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("π
|
55 |
-
thumbs_down = st.button("π
|
56 |
|
57 |
-
chosen =
|
58 |
-
rejected =
|
59 |
|
60 |
feedback_data.append((contract_text, summary, chosen, rejected))
|
61 |
|
62 |
# Handle feedback data
|
63 |
if feedback_data:
|
64 |
-
|
|
|
|
|
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()
|