Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
predictions = unmasker(masked_text, top_k=3) # Top 3 most likely words
|
| 15 |
-
return predictions
|
| 16 |
-
|
| 17 |
-
# Example usage (replace with your app logic for handling user input)
|
| 18 |
-
user_text = input("Enter a word to fill the mask: ")
|
| 19 |
-
results = predict(user_text)
|
| 20 |
-
for result in results:
|
| 21 |
-
print(f"Predicted word: {result['token_str']}, Score: {result['score']}")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
def fill_mask(text, mask_token="[MASK]"):
|
| 5 |
+
fill_mask_pipeline = pipeline("fill-mask")
|
| 6 |
+
return fill_mask_pipeline(text, mask_token=mask_token)["generated_texts"][0]
|
| 7 |
+
|
| 8 |
+
interface = gr.Interface(
|
| 9 |
+
fn=fill_mask,
|
| 10 |
+
inputs=gr.Textbox(label="Enter text with a mask ([MASK])"),
|
| 11 |
+
outputs=gr.Textbox(label="Masked text filled"),
|
| 12 |
+
title="Fill Mask with Transformers",
|
| 13 |
+
description="Fill the masked word in the sentence using a pre-trained model."
|
| 14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|