albertmartinez commited on
Commit
836e6dc
·
1 Parent(s): c8a5710

Update README.md

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +19 -15
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🏢
4
  colorFrom: pink
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.11.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: pink
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -5,24 +5,28 @@ from transformers import pipeline
5
  model = pipeline("text-classification",
6
  model="OpenAlex/bert-base-multilingual-cased-finetuned-openalex-topic-classification-title-abstract")
7
 
 
 
8
 
9
- def classify_text(text, top_k):
10
- result = model(text, top_k=top_k, truncation=True, max_length=512)
11
- return {p["label"]: p["score"] for p in result}
12
 
 
 
 
 
 
13
 
14
- with gr.Blocks() as demo:
15
- gr.Interface(
16
- fn=classify_text,
17
- inputs=[gr.Textbox(lines=5, label="Text", placeholder="<TITLE> {title}\n<ABSTRACT> {abstract}",
18
- value="<TITLE> {title}\n<ABSTRACT> {abstract}"),
19
- gr.Number(label="top_k", value=10, precision=0)],
20
- outputs=gr.Label(label="openalex topic predicted"),
21
- title="OpenAlex topic classification",
22
- description="Enter a text and see the topic classification result!",
23
- flagging_mode="never",
24
- api_name="classify"
25
- )
26
 
27
  if __name__ == "__main__":
28
  print(gr.__version__)
 
5
  model = pipeline("text-classification",
6
  model="OpenAlex/bert-base-multilingual-cased-finetuned-openalex-topic-classification-title-abstract")
7
 
8
+ model2 = pipeline("text-classification",
9
+ model="albertmartinez/openalex-topic-classification-title-abstract")
10
 
 
 
 
11
 
12
+ def classify_text(text, top_k):
13
+ return [
14
+ {p["label"]: p["score"] for p in model(text, top_k=top_k, truncation=True, max_length=512)},
15
+ {p["label"]: p["score"] for p in model2(text, top_k=top_k, truncation=True, max_length=512)}
16
+ ]
17
 
18
+ demo = gr.Interface(
19
+ fn=classify_text,
20
+ inputs=[gr.Textbox(lines=5, label="Text", placeholder="<TITLE> {title}\n<ABSTRACT> {abstract}",
21
+ value="<TITLE> {title}\n<ABSTRACT> {abstract}"),
22
+ gr.Number(label="top_k", value=10, precision=0)],
23
+ outputs=[gr.Label(label="Model 1: OpenAlex"),
24
+ gr.Label(label="Model 2: AlbertMartinez")],
25
+ title="OpenAlex Topic Classification",
26
+ description="Enter a text and see the topic classification result!",
27
+ flagging_mode="never",
28
+ api_name="classify"
29
+ )
30
 
31
  if __name__ == "__main__":
32
  print(gr.__version__)