simonn8 commited on
Commit
b463033
1 Parent(s): 1eaa717

Added email rater python file

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import streamlit.components.v1 as components
3
+ import random
4
+ from pathlib import Path
5
+
6
+
7
+ paths_to_html = [Path(filename) for filename in Path("./html_files/").glob("*.html")]
8
+ # path_to_html = random.choice(paths_to_html)
9
+
10
+
11
+ # Show in webpage
12
+
13
+ # written_by = {}
14
+
15
+ # st.header(f"Judge this email")
16
+ # with open(path_to_html, "r") as f:
17
+ # html_data = f.read()
18
+ # st.components.v1.html(html_data, height=2100)
19
+
20
+ # written_by[path_to_html.as_posix()] = st.sidebar.radio(
21
+ # "Written by a human or generated by AI ?",
22
+ # ["Human", "AI"],
23
+ # horizontal=True,
24
+ # index=None, #random.randint(0, 1),
25
+ # key=path_to_html,
26
+ # )
27
+ # # col1, col2 = st.columns([1,1])
28
+ # with col1:
29
+ # if st.button(label="Human", key=path_to_html.as_posix()+"human"):
30
+ # written_by[path_to_html.as_posix()] = "human"
31
+ # with col2:
32
+ # if st.button(label="GenAI", key=path_to_html.as_posix()+"ai"):
33
+ # written_by[path_to_html.as_posix()] = "ai"
34
+
35
+ # st.components.v1.html(
36
+ # """<hr style="height:10px;border:none;color:#333;background-color:#333;" /> """
37
+ # )
38
+ # st.stop()
39
+
40
+ label_to_number = {"Human":0, "AI":1}
41
+
42
+ if "html_idx" not in st.session_state:
43
+ st.session_state.html_idx = 0
44
+
45
+ if "html_ratings" not in st.session_state:
46
+ st.session_state.html_ratings = {}
47
+
48
+ # Display the image
49
+ path_to_html = paths_to_html[st.session_state.html_idx]
50
+ with open(path_to_html, "r") as f:
51
+ html_data = f.read()
52
+ st.components.v1.html(html_data, height=2100)
53
+
54
+ if st.session_state["html_idx"] in st.session_state.html_ratings:
55
+ rating = st.session_state.html_ratings[st.session_state.html_idx]
56
+ else:
57
+ rating = ""
58
+
59
+ if rating := st.radio(
60
+ "Written by a human or generated by AI ?",
61
+ ["Human", "AI"],
62
+ horizontal=True,
63
+ index=None if rating == "" else label_to_number[rating],
64
+ key=path_to_html,
65
+ ):
66
+ st.session_state.html_ratings[st.session_state.html_idx] = rating
67
+ st.info("Submitted!")
68
+
69
+ if st.button("Next email", key="next"):
70
+ idx = st.session_state.html_idx
71
+ idx = (idx + 1) % len(paths_to_html)
72
+ st.session_state.html_idx = idx
73
+ st.experimental_rerun()
74
+
75
+ elif st.button("Previous email", key="previous"):
76
+ idx = st.session_state.html_idx
77
+ idx = (idx - 1) % len(paths_to_html)
78
+ st.session_state.html_idx = idx
79
+ st.experimental_rerun()
80
+ else:
81
+ if st.button("Quit", key="quit"):
82
+ # send email with data or append to jsonl file
83
+ st.success(f"Thank you for rating {len(st.session_state.html_ratings)} emails, you can close the webpage.")
84
+
85
+ # st.session_state