Spaces:
Running
Running
Update app.py
Browse files
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
|
|
|
|
| 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":
|
| 20 |
|
| 21 |
-
# Call the pipeline and catch any
|
| 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:
|