andreska commited on
Commit
9dfb04d
·
verified ·
1 Parent(s): cbd1365

Prevent loading dataset if Help checkbox is not checked

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -7,18 +7,6 @@ from huggingface_hub import InferenceClient
7
  api_key = os.getenv("HF_API_KEY")
8
  client = InferenceClient(api_key=api_key)
9
 
10
- # Load the dataset
11
- dataset = load_dataset("andreska/adregadocs", split="test")
12
-
13
- # Function to read the content from the dataset
14
- def read_dataset(dataset):
15
- text = []
16
- for item in dataset:
17
- text.append(item['text'])
18
- return "\n".join(text)
19
-
20
- context = read_dataset(dataset)
21
-
22
  # Inject custom CSS to change the background color to yellow
23
  st.markdown(
24
  """
@@ -39,6 +27,20 @@ if 'conversation' not in st.session_state:
39
  if 'include_context' not in st.session_state:
40
  st.session_state.include_context = False
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def handle_submit():
43
  user_input = st.session_state.user_input
44
  if user_input:
@@ -66,5 +68,8 @@ def handle_submit():
66
  else:
67
  st.write("Please enter a question.")
68
 
 
 
 
69
  st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
70
  st.text_area("Conversation History", value=st.session_state.conversation, height=300, max_chars=None)
 
7
  api_key = os.getenv("HF_API_KEY")
8
  client = InferenceClient(api_key=api_key)
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Inject custom CSS to change the background color to yellow
11
  st.markdown(
12
  """
 
27
  if 'include_context' not in st.session_state:
28
  st.session_state.include_context = False
29
 
30
+ if include_context:
31
+ dataset = load_dataset("andreska/adregadocs", split="test")
32
+
33
+ # Function to read the content from the dataset
34
+ def read_dataset(dataset):
35
+ text = []
36
+ for item in dataset:
37
+ text.append(item['text'])
38
+ return "\n".join(text)
39
+
40
+ context = read_dataset(dataset)
41
+ else:
42
+ context = ""
43
+
44
  def handle_submit():
45
  user_input = st.session_state.user_input
46
  if user_input:
 
68
  else:
69
  st.write("Please enter a question.")
70
 
71
+ if st.button("Ask"):
72
+ handle_submit()
73
+
74
  st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
75
  st.text_area("Conversation History", value=st.session_state.conversation, height=300, max_chars=None)