max-long commited on
Commit
378ec43
·
verified ·
1 Parent(s): f18abee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -81,13 +81,16 @@ with gr.Blocks(title="General NER with Color-Coded Output") as demo:
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
93
  refresh_btn.click(fn=get_new_snippet, outputs=input_text)
 
81
 
82
  def get_new_snippet():
83
  # Preload several samples into a list
84
+ max_length = 384 # Maximum length for snippets
85
+ samples = [
86
+ sample['text'][:max_length] for sample, _ in zip(dataset_iter, range(100)) # Truncate to max_length
87
+ ]
88
 
89
  # Return a random snippet from the preloaded samples
90
  if samples:
91
  return random.choice(samples)
92
 
93
+ return "No more snippets available." # Return this if no valid snippets are found
94
 
95
  # Connect refresh button
96
  refresh_btn.click(fn=get_new_snippet, outputs=input_text)