File size: 1,235 Bytes
6f5969f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle, random
from sentence_transformers import SentenceTransformer

# Load model (must be in the same folder)
with open("intent_model.pkl", "rb") as f:
    data = pickle.load(f)

clf = data["classifier"]
id2label = data["id2label"]
embedder = SentenceTransformer(data["embed_model"])
intents_meta = data["intents_meta"]

def predict_intent(user_input):
    """Predict intent and return formatted response."""
    if not user_input.strip():
        return "Please enter a command."
    emb = embedder.encode([user_input])
    pred = clf.predict(emb)[0]
    intent = id2label[pred]
    meta = intents_meta[intent]
    response = random.choice(meta["responses"])
    action = meta["action"]
    return f"🧠 Intent: {intent}\n💬 Response: {response}\n⚙️ Action: {action}"

# Gradio interface
demo = gr.Interface(
    fn=predict_intent,
    inputs=gr.Textbox(label="Enter your command", placeholder="e.g. restart pc, open gmail"),
    outputs=gr.Textbox(label="Jarvis Response"),
    title="🧠 Jarvis Intent Classifier",
    description="Lightweight intent classification model that detects system commands and returns appropriate responses & actions."
)

if __name__ == "__main__":
    demo.launch()