ghostai1 commited on
Commit
67be689
Β·
verified Β·
1 Parent(s): 2acf864

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -1,7 +1,8 @@
1
  # πŸ” Masked Word Predictor | CPU-only HF Space
2
 
3
  import gradio as gr
4
- from transformers import pipeline, PipelineException
 
5
 
6
  # Load the fill-mask pipeline once at startup
7
  fill_mask = pipeline("fill-mask", model="distilroberta-base", device=-1)
@@ -16,9 +17,9 @@ def predict_mask(sentence: str, top_k: int):
16
 
17
  # If no mask token present, show error
18
  if mask not in sentence:
19
- return [{"sequence": f"Error: please include `[MASK]` in your sentence.", "score": 0.0}]
20
 
21
- # Call the pipeline and catch any unexpected exceptions
22
  try:
23
  preds = fill_mask(sentence, top_k=top_k)
24
  except PipelineException as e:
 
1
  # πŸ” Masked Word Predictor | CPU-only HF Space
2
 
3
  import gradio as gr
4
+ from transformers import pipeline
5
+ from transformers.pipelines.base import PipelineException # correct import
6
 
7
  # Load the fill-mask pipeline once at startup
8
  fill_mask = pipeline("fill-mask", model="distilroberta-base", device=-1)
 
17
 
18
  # If no mask token present, show error
19
  if mask not in sentence:
20
+ return [{"sequence": "Error: please include `[MASK]` in your sentence.", "score": 0.0}]
21
 
22
+ # Call the pipeline and catch any pipeline-specific exceptions
23
  try:
24
  preds = fill_mask(sentence, top_k=top_k)
25
  except PipelineException as e: