DelaliScratchwerk commited on
Commit
3133f26
·
verified ·
1 Parent(s): f327d31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -1,14 +1,14 @@
1
  import json, numpy as np, gradio as gr
2
  from setfit import SetFitModel
3
- from huggingface_hub import hf_hub_download, HfHubHTTPError, EntryNotFoundError
4
 
5
  MODEL_ID = "DelaliScratchwerk/text-period-setfit"
6
 
7
- # ---- load labels (Hub -> local fallback)
8
  try:
9
  labels_path = hf_hub_download(MODEL_ID, "labels.json")
10
  LABELS = json.load(open(labels_path))
11
- except (HfHubHTTPError, EntryNotFoundError, FileNotFoundError):
12
  LABELS = json.load(open("labels.json"))
13
 
14
  model = SetFitModel.from_pretrained(MODEL_ID)
@@ -37,5 +37,6 @@ demo = gr.Interface(
37
  cache_examples=False,
38
  allow_flagging="never",
39
  )
 
40
  if __name__ == "__main__":
41
  demo.launch()
 
1
  import json, numpy as np, gradio as gr
2
  from setfit import SetFitModel
3
+ from huggingface_hub import hf_hub_download
4
 
5
  MODEL_ID = "DelaliScratchwerk/text-period-setfit"
6
 
7
+ # Try to load labels from the model repo; if missing, use local labels.json
8
  try:
9
  labels_path = hf_hub_download(MODEL_ID, "labels.json")
10
  LABELS = json.load(open(labels_path))
11
+ except Exception:
12
  LABELS = json.load(open("labels.json"))
13
 
14
  model = SetFitModel.from_pretrained(MODEL_ID)
 
37
  cache_examples=False,
38
  allow_flagging="never",
39
  )
40
+
41
  if __name__ == "__main__":
42
  demo.launch()