harir commited on
Commit
6f7e68b
1 Parent(s): a774074

add app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import models
3
+
4
+ def main():
5
+ st.set_page_config(layout="wide", page_title="Review Toxicity Checker")
6
+ st.title('Review Toxicity Checker')
7
+
8
+ left_col, right_col = st.columns(2)
9
+
10
+ content = left_col.empty()
11
+
12
+ with st.sidebar:
13
+ model_id = st.radio(
14
+ "Select a model option:",
15
+ ["stabilityai/stablelm-zephyr-3b"]
16
+ )
17
+ hf_api_key = st.text_input('HF API Key\nhttps://huggingface.co/settings/tokens')
18
+ color = st.color_picker('Highlight Color', '#F44336')
19
+
20
+ with right_col:
21
+ st.markdown("<p style='text-align: left; color: white; margin-bottom: 5px; font-size: 14px;'>Revised review:</p>", unsafe_allow_html=True)
22
+
23
+ with left_col:
24
+ input_text = st.text_area('Enter your review here:', height=500)
25
+ left_col2, right_col2 = st.columns([1,3])
26
+ with left_col2:
27
+ check = st.button('Check Review')
28
+ with right_col2:
29
+ clear = st.button('Clear Text')
30
+ if check:
31
+ with st.spinner('Processing review...'):
32
+ revision = models.revise_review(input_text, hf_api_key, model_id, color)
33
+ try:
34
+ with right_col:
35
+ print(revision['data']['revision'])
36
+ st.markdown(f""" <div style="border:1px solid white; padding:10px; height:500px; overflow:auto; border-radius:7px;"> {revision['data']['revision']} </div> """, unsafe_allow_html=True)
37
+ num_revised = int(revision['data']['revised_sentences'])/int(revision['data']['sentence_count'])
38
+ left_col2, right_col2 = st.columns([1,2])
39
+ st.write(f"Sentences Revised: {revision['data']['revised_sentences']}/{revision['data']['sentence_count']}")
40
+ st.progress(num_revised)
41
+ score = revision['data']['score']
42
+ if score == 1:
43
+ st.write(f"Score: 1 (toxic)")
44
+ if score == 0:
45
+ st.write(f"Score: 0 (non-toxic)")
46
+ st.progress(int(revision['data']['score'])/1)
47
+ except Exception as e:
48
+ with right_col:
49
+ st.error("An error occured.")
50
+ st.error(e)
51
+ elif clear:
52
+ with right_col:
53
+ st.markdown(f""" <div style="border:1px solid white; padding:10px; height:500px; overflow:auto; border-radius:7px;"> </div> """, unsafe_allow_html=True)
54
+ else:
55
+ with right_col:
56
+ st.markdown(f""" <div style="border:1px solid white; padding:10px; height:500px; overflow:auto; border-radius:7px;"> </div> """, unsafe_allow_html=True)
57
+
58
+ if __name__ == "__main__":
59
+ main()