File size: 581 Bytes
c88a41d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# services/zero_shot.py

from transformers import pipeline
import streamlit as st

@st.cache_resource
def load_zero_shot_model():
    return pipeline(
        "zero-shot-classification",
        model="facebook/bart-large-mnli"
    )

def classify_intent(text: str):
    classifier = load_zero_shot_model()

    labels = [
        "sales",
        "lead generation",
        "brand awareness",
        "engagement",
        "traffic"
    ]

    result = classifier(text, labels)

    return {
        "label": result["labels"][0],
        "score": float(result["scores"][0])
    }