ayureasehealthcare's picture
Rename utils/nlp.py to nlp.py
aa02ad6 verified
raw
history blame contribute delete
794 Bytes
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load IndicBERT Model
tokenizer = AutoTokenizer.from_pretrained("ai4bharat/indic-bert")
model = AutoModelForSequenceClassification.from_pretrained("ai4bharat/indic-bert")
def process_query(query):
inputs = tokenizer(query, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
predicted_label = torch.argmax(outputs.logits).item()
# Basic intent handling (customize as needed)
if "appointment" in query.lower():
return "I can help you book an appointment with a doctor."
elif "health" in query.lower():
return "Can you describe your health concern?"
else:
return "Sorry, I didn’t understand. Can you please rephrase?"