harshildarji commited on
Commit
6c9518c
1 Parent(s): 2fe4407
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +70 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: RE Demo
3
  emoji: 🐢
4
  colorFrom: red
5
  colorTo: yellow
@@ -10,4 +10,4 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: CAROLL RE Demo
3
  emoji: 🐢
4
  colorFrom: red
5
  colorTo: yellow
 
10
  license: mit
11
  ---
12
 
13
+ Model available at https://huggingface.co/harshildarji/privacy-policy-relation-extraction.
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+
5
+ @st.cache_data
6
+ def get_results(text):
7
+ pipe = pipeline(
8
+ "text-classification",
9
+ model="harshildarji/privacy-policy-relation-extraction",
10
+ return_all_scores=True,
11
+ framework="pt",
12
+ )
13
+ return pipe(text)
14
+
15
+
16
+ st.title("Privacy Policy Relation Extraction")
17
+
18
+ example = st.text_area(
19
+ "Enter text:",
20
+ value="We store your basic account information, including your name, username, and email address until you ask us to delete them.",
21
+ height=150,
22
+ )
23
+
24
+ if st.button("Analyze"):
25
+ with st.spinner("Processing..."):
26
+ results = get_results(example)
27
+ st.session_state.results = results
28
+
29
+ if "results" in st.session_state:
30
+ threshold = st.slider(
31
+ "Confidence threshold:", min_value=0.0, max_value=1.0, value=0.5
32
+ )
33
+ filtered_results = [
34
+ result for result in st.session_state.results[0] if result["score"] >= threshold
35
+ ]
36
+
37
+ sorted_results = sorted(filtered_results, key=lambda x: x["score"], reverse=True)
38
+
39
+ if sorted_results:
40
+ for result in sorted_results:
41
+ cols = st.columns([3, 5, 0.5])
42
+ with cols[0]:
43
+ st.write(f"**{result['label']}**")
44
+ with cols[1]:
45
+ st.progress(int(result["score"] * 100))
46
+ with cols[2]:
47
+ st.write(f"**{result['score']:.2f}**")
48
+ else:
49
+ st.warning("No relations found with the specified threshold.")
50
+
51
+ st.markdown(
52
+ """
53
+ <style>
54
+ .reportview-container {
55
+ background: #f0f2f6;
56
+ padding: 20px;
57
+ }
58
+ .stButton button {
59
+ border: 0.5;
60
+ transition: background-color 0.3s, transform 0.2s;
61
+ border-radius: 10px;
62
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
63
+ }
64
+ .stButton button:hover {
65
+ transform: translateY(-1px);
66
+ }
67
+ </style>
68
+ """,
69
+ unsafe_allow_html=True,
70
+ )
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch