ppsingh commited on
Commit
6ca2a04
·
1 Parent(s): d6fbfbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -39
app.py CHANGED
@@ -10,68 +10,69 @@ import numpy as np
10
  # Declaring the variables for later use to talk to dataset
11
 
12
  # the token is saved as secret key-value pair in the environment which can be access as shown below
13
- auth_token = os.environ.get("space_to_dataset") or True
14
 
15
- DATASET_REPO_URL = 'ppsingh/annotation_data' # path to dataset repo
16
- DATA_FILENAME = "paralist.json"
17
- DATA_FILE = os.path.join("data", DATA_FILENAME)
18
 
19
  # cloning the dataset repo
20
- repo = Repository( local_dir="data", clone_from=DATASET_REPO_URL, repo_type="dataset", use_auth_token= auth_token)
21
 
22
  # Data file name
23
- file_name = 'paralist.json'
24
 
25
  # reading the json
26
- with open('data/{}'.format(file_name), 'r', encoding="utf8") as json_file:
27
- paraList = json.load(json_file)
28
 
29
  # getting outer level keys in json
30
- keys = paraList.keys()
31
  #data = pd.read_csv("test.csv")
32
 
33
  # sidebar with info and drop down to select from the keys
34
- st.sidebar.markdown(
35
- """
36
  # Data Annotation Demo
37
- This app is demo how to use the space to provide user interface for the data annotation/tagging. The data resides in repo_type 'dataset'.
38
- """
39
- )
40
- topic = None
41
- if keys is not None:
42
- topic = st.sidebar.selectbox(
43
- label="Choose dataset topic to load", options=keys )
 
44
  # st.write(line)
45
  #st.write(paraList)
46
- if topic is not None:
47
- subtopics = list(paraList[topic].keys())
48
  #st.write(subtopics)
49
- val = np.random.randint(0,len(subtopics)-1)
50
- choice = subtopics[val]
51
- st.write(choice)
52
  #if np.random.randint(0,1) == 0:
53
  # choice = "Gender"
54
  #else:
55
  # choice = "Women Empowernment"
56
 
57
- idx = np.random.randint(0,3)
58
- st.write(idx)
59
- c1, c2, c3 = st.columns([3, 1, 1])
60
- with c1:
61
- st.header('Text')
62
- st.write(paraList[topic][choice][idx]['textsegment'])
63
 
64
- with c2:
65
- st.header('Tag')
66
- st.text(choice)
67
 
68
- with c3:
69
- st.header('Feedback')
70
- feedback = None
71
- feedback = st.selectbox('0 If Tag is not a good keyword for text, 5 for prefect match',(0,1,2,3,4,5))
72
- if feedback:
73
- if st.button('Submit'):
74
- paraList[topic][choice][idx]['annotation'].append(feedback)
75
  # with open('data/{}'.format(file_name), 'r', encoding="utf8") as json_file:
76
  # json.dump(paraList,json_file, ensure_ascii = True)
77
  # repo.push_to_hub('added new annotation')
@@ -100,6 +101,38 @@ if topic is not None:
100
  # st.write('Succcess')
101
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
 
105
 
 
10
  # Declaring the variables for later use to talk to dataset
11
 
12
  # the token is saved as secret key-value pair in the environment which can be access as shown below
13
+ #auth_token = os.environ.get("space_to_dataset") or True
14
 
15
+ #DATASET_REPO_URL = 'ppsingh/annotation_data' # path to dataset repo
16
+ #DATA_FILENAME = "paralist.json"
17
+ #DATA_FILE = os.path.join("data", DATA_FILENAME)
18
 
19
  # cloning the dataset repo
20
+ #repo = Repository( local_dir="data", clone_from=DATASET_REPO_URL, repo_type="dataset", use_auth_token= auth_token)
21
 
22
  # Data file name
23
+ #file_name = 'paralist.json'
24
 
25
  # reading the json
26
+ #with open('data/{}'.format(file_name), 'r', encoding="utf8") as json_file:
27
+ # paraList = json.load(json_file)
28
 
29
  # getting outer level keys in json
30
+ #keys = paraList.keys()
31
  #data = pd.read_csv("test.csv")
32
 
33
  # sidebar with info and drop down to select from the keys
34
+ #st.sidebar.markdown(
35
+ # """
36
  # Data Annotation Demo
37
+ #This app is demo how to use the space to provide user interface for the data annotation/tagging. The data resides in repo_type 'dataset'.
38
+ #"""
39
+ #)
40
+ #topic = None
41
+ #if keys is not None:
42
+ # topic = st.sidebar.selectbox(
43
+
44
+ # label="Choose dataset topic to load", options=keys )
45
  # st.write(line)
46
  #st.write(paraList)
47
+ #if topic is not None:
48
+ # subtopics = list(paraList[topic].keys())
49
  #st.write(subtopics)
50
+ # val = np.random.randint(0,len(subtopics)-1)
51
+ # choice = subtopics[val]
52
+ # st.write(choice)
53
  #if np.random.randint(0,1) == 0:
54
  # choice = "Gender"
55
  #else:
56
  # choice = "Women Empowernment"
57
 
58
+ # idx = np.random.randint(0,3)
59
+ # st.write(idx)
60
+ #c1, c2, c3 = st.columns([3, 1, 1])
61
+ #with c1:
62
+ # st.header('Text')
63
+ #st.write(paraList[topic][choice][idx]['textsegment'])
64
 
65
+ #with c2:
66
+ # st.header('Tag')
67
+ #st.text(choice)
68
 
69
+ # with c3:
70
+ #st.header('Feedback')
71
+ #feedback = None
72
+ # feedback = st.selectbox('0 If Tag is not a good keyword for text, 5 for prefect match',(0,1,2,3,4,5))
73
+ # if feedback:
74
+ # if st.button('Submit'):
75
+ # paraList[topic][choice][idx]['annotation'].append(feedback)
76
  # with open('data/{}'.format(file_name), 'r', encoding="utf8") as json_file:
77
  # json.dump(paraList,json_file, ensure_ascii = True)
78
  # repo.push_to_hub('added new annotation')
 
101
  # st.write('Succcess')
102
 
103
 
104
+ import streamlit as st
105
+
106
+
107
+ session_state = st.sessionstate.get(col1=False, col2=False, col3=False)
108
+
109
+ col1, col2, col3 = st.columns(3)
110
+
111
+ col1_one = col1.button("CARTE", key="1")
112
+ col2_one = col2.button("TABLEAU", key="2")
113
+ col3_one = col3.button("SYNTHÈSE", key="3")
114
+
115
+ if col1_one or session_state.col1:
116
+ session_state.col1 = True
117
+ session_state.col2 = False
118
+ session_state.col3 = False
119
+ sel_Map = st.selectbox("Choose Map type :", options=['Hello1', 'Hello2'], index=1)
120
+ if sel_Map == 'Hello1':
121
+ st.write("Hello world! 1")
122
+ elif sel_Map == 'Hello2':
123
+ st.write("Hello world! 2")
124
+
125
+ if col2_one or session_state.col2:
126
+ session_state.col1 = False
127
+ session_state.col2 = True
128
+ session_state.col3 = False
129
+ st.write("Hello world! 3")
130
+
131
+ if col3_one or session_state.col3:
132
+ session_state.col1 = False
133
+ session_state.col2 = False
134
+ session_state.col3 = True
135
+ st.write("Hello world! 4")
136
 
137
 
138