davanstrien HF staff commited on
Commit
c11ccae
1 Parent(s): 8b691a8
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -19,11 +19,9 @@ sample_text = [
19
  "Summer Travelling in Iceland; being the narrative of two journeys across the island ... With a chapter on Askja by E. Delmar Morgan ... Containing also a literal translation of three sagas. Maps, etc'"
20
  ],
21
  [
22
- 'History of the Monument. With a brief account of the Great Fire of London, which it commemorates. By Charles Welch. (With illustrations and a map of Old London.)',
23
- ],
24
- [
25
- "The history and antiquities of Newbury and its environs [By E. W. Gray.]"
26
  ],
 
27
  ["""A Christmas Carol"""],
28
  ]
29
 
@@ -67,19 +65,25 @@ The model is trained on a particular collection of books digitised by the Britis
67
 
68
  tokenizer = AutoTokenizer.from_pretrained("TheBritishLibrary/bl-books-genre")
69
 
70
- model = AutoModelForSequenceClassification.from_pretrained("TheBritishLibrary/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']: float(pred['score']) for pred in predictions}
77
-
78
 
79
 
80
- gr.Interface(predict,
 
81
  inputs=gr.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)
 
 
 
 
19
  "Summer Travelling in Iceland; being the narrative of two journeys across the island ... With a chapter on Askja by E. Delmar Morgan ... Containing also a literal translation of three sagas. Maps, etc'"
20
  ],
21
  [
22
+ "History of the Monument. With a brief account of the Great Fire of London, which it commemorates. By Charles Welch. (With illustrations and a map of Old London.)",
 
 
 
23
  ],
24
+ ["The history and antiquities of Newbury and its environs [By E. W. Gray.]"],
25
  ["""A Christmas Carol"""],
26
  ]
27
 
65
 
66
  tokenizer = AutoTokenizer.from_pretrained("TheBritishLibrary/bl-books-genre")
67
 
68
+ model = AutoModelForSequenceClassification.from_pretrained(
69
+ "TheBritishLibrary/bl-books-genre"
70
+ )
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"]: float(pred["score"]) for pred in predictions}
 
77
 
78
 
79
+ gr.Interface(
80
+ predict,
81
  inputs=gr.Textbox(label="Book title"),
82
+ outputs="label",
83
+ interpretation="shap",
84
+ num_shap=10.0,
85
+ theme="huggingface",
86
+ examples=sample_text,
87
+ description=description,
88
+ article=article,
89
+ ).launch(enable_queue=True)