AlphamanKing commited on
Commit
fea7782
·
verified ·
1 Parent(s): 64962af

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +23 -11
  2. requirements.txt +2 -1
app.py CHANGED
@@ -6,16 +6,27 @@ from huggingface_hub import login
6
  import os
7
 
8
  # Authenticate with Hugging Face using token from environment variable
9
- login(os.environ.get("HUGGINGFACE_TOKEN"))
 
 
 
 
 
 
 
10
 
11
  # Load MentalBERT model & tokenizer
12
- MODEL_NAME = "mental/mental-bert-base-uncased"
13
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
14
- model = AutoModelForSequenceClassification.from_pretrained(
15
- MODEL_NAME,
16
- num_labels=2,
17
- problem_type="single_label_classification"
18
- )
 
 
 
 
19
 
20
  LABELS = {
21
  "neutral": {"index": 0, "description": "Emotionally balanced or calm"},
@@ -52,8 +63,9 @@ iface = gr.Interface(
52
  ["I've been feeling quite depressed lately"],
53
  ["I'm managing my stress levels well today"],
54
  ["Just had a great therapy session!"]
55
- ]
 
56
  )
57
 
58
- # Launch the interface
59
- iface.launch()
 
6
  import os
7
 
8
  # Authenticate with Hugging Face using token from environment variable
9
+ try:
10
+ hf_token = os.environ.get("HUGGINGFACE_TOKEN")
11
+ if hf_token:
12
+ login(hf_token)
13
+ else:
14
+ print("Warning: HUGGINGFACE_TOKEN not found in environment variables")
15
+ except Exception as e:
16
+ print(f"Authentication error: {e}")
17
 
18
  # Load MentalBERT model & tokenizer
19
+ try:
20
+ MODEL_NAME = "mental/mental-bert-base-uncased"
21
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
22
+ model = AutoModelForSequenceClassification.from_pretrained(
23
+ MODEL_NAME,
24
+ num_labels=2,
25
+ problem_type="single_label_classification"
26
+ )
27
+ except Exception as e:
28
+ print(f"Error loading model: {e}")
29
+ raise
30
 
31
  LABELS = {
32
  "neutral": {"index": 0, "description": "Emotionally balanced or calm"},
 
63
  ["I've been feeling quite depressed lately"],
64
  ["I'm managing my stress levels well today"],
65
  ["Just had a great therapy session!"]
66
+ ],
67
+ allow_flagging="never"
68
  )
69
 
70
+ # Launch the interface with CORS support
71
+ iface.launch(share=True, server_name="0.0.0.0")
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  gradio==4.13.0
2
  transformers==4.35.2
3
  torch==2.1.1
4
- uvicorn==0.24.0
 
5
  pydantic==2.5.2
 
1
  gradio==4.13.0
2
  transformers==4.35.2
3
  torch==2.1.1
4
+ huggingface-hub==0.19.4
5
+ numpy==1.26.2
6
  pydantic==2.5.2