davanstrien HF staff commited on
Commit
d92088b
1 Parent(s): f6c0139

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -68,17 +68,18 @@ The model is trained on a particular collection of books digitised by the Britis
68
  tokenizer = AutoTokenizer.from_pretrained("BritishLibraryLabs/bl-books-genre")
69
 
70
  model = AutoModelForSequenceClassification.from_pretrained("BritishLibraryLabs/bl-books-genre")
71
- classifier = pipeline('text-classification',model=model, tokenizer=tokenizer, return_all_scores=True)
72
 
73
 
74
  def predict(text):
75
  predictions = classifier(text)
76
- return {pred['label']: pred['score'] for pred in predictions[0]}
 
 
77
 
78
  gr.Interface(predict,
79
  inputs=gr.inputs.Textbox(label="Book title"),
80
- outputs=gr.outputs.Label(label="Predicted genre"),
81
- interpretation='shap', num_shap=5, theme="huggingface",
82
  examples=sample_text,description=description,article=article,
83
- ).launch(enable_queue=True, cache_examples=True)
84
-
 
68
  tokenizer = AutoTokenizer.from_pretrained("BritishLibraryLabs/bl-books-genre")
69
 
70
  model = AutoModelForSequenceClassification.from_pretrained("BritishLibraryLabs/bl-books-genre")
71
+ classifier = pipeline('text-classification',model=model, tokenizer=tokenizer, top_k=10)
72
 
73
 
74
  def predict(text):
75
  predictions = classifier(text)
76
+ return {pred['label']: pred['score'] for pred in predictions}
77
+
78
+
79
 
80
  gr.Interface(predict,
81
  inputs=gr.inputs.Textbox(label="Book title"),
82
+ outputs='label',
83
+ interpretation='shap', num_shap=10.0, theme="huggingface",
84
  examples=sample_text,description=description,article=article,
85
+ ).launch(enable_queue=True)