haripriyaram commited on
Commit
3ebadee
·
verified ·
1 Parent(s): a1d8194

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,15 +1,16 @@
1
- import gradio as gr
2
- from fastai.text.all import load_learner
3
- from huggingface_hub import notebook_login
4
 
5
- # Load FastAI model once
6
- learn = load_learner("emotion_classifier.pkl")
7
- learn.push_to_hub("fastai-emotion-classifier")
8
 
9
  # Prediction function
10
  def predict_emotion(text):
11
  pred_label, _, probs = learn.predict(text)
12
- probs_dict = {label: float(prob) for label, prob in zip(learn.dls.vocab, probs)}
 
 
 
 
13
  return pred_label, probs_dict
14
 
15
  # Gradio UI
 
1
+ from huggingface_hub import from_pretrained_fastai
 
 
2
 
3
+ # Load model directly from Hugging Face
4
+ learn = from_pretrained_fastai("haripriyaram/Text-emotion-Recognizer-Model")
 
5
 
6
  # Prediction function
7
  def predict_emotion(text):
8
  pred_label, _, probs = learn.predict(text)
9
+
10
+ # Handle nested vocab if needed
11
+ vocab = learn.dls.vocab[0] if isinstance(learn.dls.vocab[0], list) else learn.dls.vocab
12
+ probs_dict = {label: float(prob) for label, prob in zip(vocab, probs)}
13
+
14
  return pred_label, probs_dict
15
 
16
  # Gradio UI