YosefAyele commited on
Commit
3356a7c
·
1 Parent(s): d38e058

fix gr.cache deprecation issue

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -2,20 +2,23 @@ import gradio as gr
2
  from transformers import pipeline
3
  import torch
4
 
5
- # Load the model from Hugging Face
6
- @gr.cache
 
7
  def load_model():
8
  """Load the intent classification model"""
9
- try:
10
- classifier = pipeline(
11
- "text-classification",
12
- model="YosefA/adfluence-intent-model",
13
- return_all_scores=True
14
- )
15
- return classifier
16
- except Exception as e:
17
- print(f"Error loading model: {e}")
18
- return None
 
 
19
 
20
  def classify_intent(comment):
21
  """
 
2
  from transformers import pipeline
3
  import torch
4
 
5
+ # Global variable to cache the model
6
+ _classifier = None
7
+
8
  def load_model():
9
  """Load the intent classification model"""
10
+ global _classifier
11
+ if _classifier is None:
12
+ try:
13
+ _classifier = pipeline(
14
+ "text-classification",
15
+ model="YosefA/adfluence-intent-model",
16
+ return_all_scores=True
17
+ )
18
+ except Exception as e:
19
+ print(f"Error loading model: {e}")
20
+ return None
21
+ return _classifier
22
 
23
  def classify_intent(comment):
24
  """