Spaces:
Sleeping
Sleeping
Download app.py from mahebabu/NLP-Model-Comparison: direct link, hf CLI and curl.
- Browser
- Download file 698 Bytes
-
https://huggingface.co/spaces/mahebabu/NLP-Model-Comparison/resolve/main/app.py
- Command line
-
hf download hf://spaces/mahebabu/NLP-Model-Comparison/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mahebabu/NLP-Model-Comparison/resolve/main/app.py
698 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| bert_model = pipeline("sentiment-analysis") | |
| distilbert_model = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
| def compare_models(text): | |
| result1 = bert_model(text)[0] | |
| result2 = distilbert_model(text)[0] | |
| return( | |
| f"BERT -> {result1['label']} {round(result1['score'],2)}\n" | |
| f"DistilBERT -> {result2['label']} {round(result2['score'],2)}" | |
| ) | |
| iface = gr.Interface( | |
| fn=compare_models, | |
| inputs=gr.Textbox(label="Enter Text"), | |
| outputs="text", | |
| title="NLP Model Comparision", | |
| description="Compare predictions of multiple NLP models" | |
| ) | |
| iface.launch(share=True) |