|
|
| from fastai.text.all import* |
| import gradio as gr |
|
|
| learn = load_learner('nlp_model.pkl') |
|
|
| labels = learn.dls.vocab |
|
|
| examples = ["I can't believe you lied to me again! This is unacceptable!", |
| "Got a surprise gift today, feeling overjoyed!"] |
|
|
|
|
|
|
| def classify_text(text): |
| pred,pred_idx,probs = learn.predict(text) |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} |
|
|
| interface = gr.Interface( |
| fn=classify_text, |
| inputs=gr.inputs.Textbox( |
| placeholder="Enter Text here", |
| label='Input text', |
| lines=5 |
| ), |
| outputs=gr.outputs.Label( |
| num_top_classes=4, |
| label='Emotion in the Text' |
| ), |
| verbose=True, |
| title="Emotion Classifier", |
| theme='soft' |
| ) |
|
|
| interface.launch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|