max-long commited on
Commit
f18abee
·
verified ·
1 Parent(s): 70ca6fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -79,12 +79,14 @@ with gr.Blocks(title="General NER with Color-Coded Output") as demo:
79
  output_entities = gr.JSON(label="Entities")
80
 
81
 
82
-
83
  def get_new_snippet():
84
- attempts = 0
85
- max_attempts = 1000 # Prevent infinite loops
86
- for sample in dataset_iter:
87
- return sample['text']
 
 
 
88
  return "No more snippets available." # Return this if no valid snippets are found
89
 
90
  # Connect refresh button
 
79
  output_entities = gr.JSON(label="Entities")
80
 
81
 
 
82
  def get_new_snippet():
83
+ # Preload several samples into a list
84
+ samples = [sample['text'] for sample, _ in zip(dataset_iter, range(100))] # Load 100 samples
85
+
86
+ # Return a random snippet from the preloaded samples
87
+ if samples:
88
+ return random.choice(samples)
89
+
90
  return "No more snippets available." # Return this if no valid snippets are found
91
 
92
  # Connect refresh button