File size: 1,392 Bytes
5bbf388 457f5d9 5bbf388 457f5d9 5bbf388 457f5d9 5bbf388 457f5d9 5bbf388 457f5d9 5bbf388 457f5d9 | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import gradio as gr
from transformers import pipeline
# Load the pipeline
# The model is public, so no token is needed.
model_id = "rradhakr/health-payer-level1-intent"
classifier = pipeline("text-classification", model=model_id)
def predict_intent(text):
"""
Classifies the intent of the input text.
"""
if not text:
return "Please enter some text."
# Get prediction
result = classifier(text)
# result example: [{'label': 'BENEFITS', 'score': 0.9592}]
top_result = result[0]
label = top_result['label']
score = top_result['score']
# Return as a dictionary for the Label component
return {label: score}
# Create Gradio interface
iface = gr.Interface(
fn=predict_intent,
inputs=gr.Textbox(
label="Question",
placeholder="Type your question here (e.g., 'Does my plan cover CPAP?')"
),
outputs=gr.Label(num_top_classes=3, label="Predicted Intent"),
title="Health Payer Intent Classifier",
description=f"This model identifies the intent of health payer related questions using `{model_id}`.\n\nModel is fintetuned on distilbert/distilbert-base-uncased",
examples=[
["I need to know if my plan covers a CPAP machine."],
["How do I check my claim status?"],
["Can I add a dependent to my plan?"]
]
)
if __name__ == "__main__":
iface.launch()
|