Lamp Socrates commited on
Commit
197e844
·
1 Parent(s): 7edd56d

latest changes

Browse files
Files changed (1) hide show
  1. app.py +75 -3
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import wandb
3
  from transformers import pipeline
4
  from transformers import AutoTokenizer, AutoModelForTokenClassification
 
5
 
6
  x = st.slider('Select a value')
7
  st.write(x, 'squared is', x * x)
@@ -21,10 +22,26 @@ def load_trained_model():
21
  ner_pipeline = pipeline("ner", model=model, tokenizer = tokenizer)
22
  return ner_pipeline
23
 
24
- def load_data():
 
 
 
 
 
 
 
 
 
25
  from datasets import load_dataset
26
- dat_CW = load_dataset("surrey-nlp/PLOD-CW")
27
-
 
 
 
 
 
 
 
28
 
29
  def render_entities(tokens, entities):
30
  """
@@ -66,6 +83,57 @@ def render_entities(tokens, entities):
66
  table_data = {"Token": tokens, "Entity": entities}
67
  st.table(table_data)
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  def prep_page():
70
  model = load_trained_model()
71
 
@@ -120,6 +188,10 @@ def prep_page():
120
 
121
  render_entities(text, entities)
122
 
 
 
 
 
123
  if __name__ == '__main__':
124
 
125
  prep_page()
 
2
  import wandb
3
  from transformers import pipeline
4
  from transformers import AutoTokenizer, AutoModelForTokenClassification
5
+ import pandas as pd
6
 
7
  x = st.slider('Select a value')
8
  st.write(x, 'squared is', x * x)
 
22
  ner_pipeline = pipeline("ner", model=model, tokenizer = tokenizer)
23
  return ner_pipeline
24
 
25
+ def load_random_examples(dataset_name, num_examples=5):
26
+ """
27
+ Load random examples from the specified Hugging Face dataset.
28
+ Args:
29
+ dataset_name (str): The name of the dataset to load.
30
+ num_examples (int): The number of random examples to load.
31
+ Returns:
32
+ pd.DataFrame: A DataFrame containing the random examples.
33
+ """
34
+ # Load the dataset
35
  from datasets import load_dataset
36
+ dataset = load_dataset("surrey-nlp/PLOD-CW")
37
+
38
+ # Convert the dataset to a pandas DataFrame
39
+ df = pd.DataFrame(dataset['train'])
40
+
41
+ # Select random examples
42
+ random_examples = df.sample(n=num_examples)
43
+
44
+ return random_examples
45
 
46
  def render_entities(tokens, entities):
47
  """
 
83
  table_data = {"Token": tokens, "Entity": entities}
84
  st.table(table_data)
85
 
86
+ def render_random_examples():
87
+ """
88
+ Render random examples from the PLOD-CW dataset in a Streamlit table.
89
+ """
90
+ # Load random examples
91
+ random_examples = load_random_examples("surrey-nlp/PLOD-CW")
92
+
93
+
94
+ # Custom CSS for chilled and cool theme
95
+ st.markdown("""
96
+ <style>
97
+ body {
98
+ font-family: 'Arial', sans-serif;
99
+ background-color: #f0f0f5;
100
+ color: #333333;
101
+ }
102
+ table {
103
+ width: 100%;
104
+ border-collapse: collapse;
105
+ }
106
+ th, td {
107
+ padding: 12px;
108
+ text-align: left;
109
+ border-bottom: 1px solid #dddddd;
110
+ }
111
+ th {
112
+ background-color: #4CAF50;
113
+ color: white;
114
+ }
115
+ tr:hover {
116
+ background-color: #f5f5f5;
117
+ }
118
+ </style>
119
+ """, unsafe_allow_html=True)
120
+
121
+ # Title and description
122
+ st.title("Random Examples from PLOD-CW")
123
+ st.write("This table shows 5 random examples from the PLOD-CW dataset in a cool and chilled theme.")
124
+
125
+ # Add a button to select a different set of random samples
126
+ if st.button('Show another set of random examples'):
127
+ st.session_state['random_examples'] = load_random_examples("surrey-nlp/PLOD-CW")
128
+
129
+ # Load random examples if not already loaded
130
+ if 'random_examples' not in st.session_state:
131
+ st.session_state['random_examples'] = load_random_examples("surrey-nlp/PLOD-CW")
132
+
133
+ # Display the table
134
+ st.table(st.session_state['random_examples'])
135
+
136
+
137
  def prep_page():
138
  model = load_trained_model()
139
 
 
188
 
189
  render_entities(text, entities)
190
 
191
+ render_random_examples()
192
+
193
+
194
+
195
  if __name__ == '__main__':
196
 
197
  prep_page()