Download app.py from rradhakr/GetIntent: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/rradhakr/GetIntent/resolve/main/app.py
- Command line
-
hf download hf://spaces/rradhakr/GetIntent/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rradhakr/GetIntent/resolve/main/app.py
1.39 kB
| 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() | |