File size: 614 Bytes
b9b2b14 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# app.py
import torch
from transformers import pipeline
import gradio as gr
# Initialize the model pipeline
pipe = pipeline(
"fill-mask",
model="answerdotai/ModernBERT-base",
torch_dtype=torch.bfloat16,
)
# Function to run the model
def fill_mask(input_text):
return pipe(input_text)[0]["sequence"]
# Set up the Gradio interface
iface = gr.Interface(
fn=fill_mask,
inputs="text",
outputs="text",
title="Mask Filling with ModernBERT",
description="Enter a sentence with a [MASK] token, and the model will predict the missing word.",
)
# Launch the interface
iface.launch()
|