minskiter commited on
Commit
5ef85db
1 Parent(s): 2423b27

feat(app.py): update app

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +26 -0
  3. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ **/__pycache__
2
+ flagged
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.pipelines import pipeline
2
+ import gradio as gr
3
+ from huggingface_hub import login
4
+ import os
5
+ login(os.environ['HF_Token'])
6
+ predictor = pipeline(
7
+ "sentences_sim",
8
+ model="minskiter/simbert-chinese-bert-wwm-ext",
9
+ device="cpu",
10
+ trust_remote_code=True,
11
+ use_auth_token=True
12
+ )
13
+
14
+ def sim_predictor_gradio(text_a,text_b):
15
+ sim = predictor((text_a, text_b))
16
+ return {text_b[:10]+"...": sim}
17
+
18
+ demo = gr.Interface(
19
+ fn=sim_predictor_gradio,
20
+ inputs=[
21
+ gr.Textbox(lines=5, label="文本1"),
22
+ gr.Textbox(lines=5, label="文本2")
23
+ ],
24
+ outputs=gr.Label(num_top_classes=1, label="相似度")
25
+ )
26
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers==4.30.1
2
+ gradio==3.36.1
3
+ huggingface-hub==0.15.1
4
+ torch==2.0.1