cnealex commited on
Commit
c4cf5c4
1 Parent(s): dd35f5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -36
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
4
  def coding(model, text, codetext):
5
  classifier = pipeline("zero-shot-classification", model=model)
@@ -7,40 +8,67 @@ def coding(model, text, codetext):
7
  output = classifier(text, codelist, multi_label=True)
8
  return output
9
 
10
- iface = gr.Interface(
11
- fn=coding,
12
- inputs=[
13
- gr.Radio(
14
- [
15
- "facebook/bart-large-mnli",
16
- "MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli",
17
- "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7",
18
- "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli",
19
- "MoritzLaurer/deberta-v3-large-zeroshot-v2.0",
20
- #"joeddav/xlm-roberta-large-xnli"
21
- ],
22
- #min_width=200,
23
- #scale=2,
24
- value="facebook/bart-large-mnli",
25
- label="Model"
26
- ),
27
- gr.TextArea(
28
- label='Comment',
29
- value='感覺性格溫和,適合香港人,特別係亞洲人的肌膚,不足之處就是感覺很少有優惠,價錢都比較貴'
30
- ),
31
- gr.Textbox(
32
- label='Code list (colon-separated)',
33
- value='非常好/很好/好滿意;價錢合理/實惠/不太貴/親民/價格適中/價格便宜/價錢大眾化;價錢貴/不合理/比日本台灣貴/可以再平d'
34
- )
35
- ],
36
- outputs=[
37
- #gr.Textbox(label='Result')
38
- gr.JSON()
39
- #gr.BarPlot()
40
- ],
41
- title="NuanceTree Coding Test",
42
- description="Test Zero-Shot Classification",
43
- allow_flagging='never'
44
- )
45
 
46
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import pandas as pd
4
 
5
  def coding(model, text, codetext):
6
  classifier = pipeline("zero-shot-classification", model=model)
 
8
  output = classifier(text, codelist, multi_label=True)
9
  return output
10
 
11
+ def upload_code_list(file):
12
+ df = pd.read_excel(file.name, sheet_name='code')
13
+ # Join the data in column B using ";" as the delimiter
14
+ joined_data = ';'.join(df['label'].astype(str))
15
+ #file_paths = [file.name for file in files]
16
+
17
+ return joined_data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ demo = gr.Blocks()
20
+
21
+ with demo:
22
+ gr.Markdown(
23
+ """
24
+ # NuanceTree
25
+ Coding test program
26
+ """
27
+ )
28
+
29
+ with gr.Row():
30
+ with gr.Column():
31
+ select_model = gr.Radio(
32
+ [
33
+ "facebook/bart-large-mnli",
34
+ "MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli",
35
+ "MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7",
36
+ "MoritzLaurer/mDeBERTa-v3-base-mnli-xnli",
37
+ "MoritzLaurer/deberta-v3-large-zeroshot-v2.0",
38
+ #"joeddav/xlm-roberta-large-xnli"
39
+ ],
40
+ #min_width=200,
41
+ #scale=2,
42
+ value="facebook/bart-large-mnli",
43
+ label="Model"
44
+ )
45
+ comment_text = gr.TextArea(
46
+ label='Comment',
47
+ value='感覺性格溫和,適合香港人,特別係亞洲人的肌膚,不足之處就是感覺很少有優惠,價錢都比較貴'
48
+ )
49
+ # upload_btn = gr.UploadButton(
50
+ # label="Upload the code list file"
51
+ # )
52
+ codelist_text = gr.Textbox(
53
+ label='Code list (colon-separated)',
54
+ value='非常好/很好/好滿意;價錢合理/實惠/不太貴/親民/價格適中/價格便宜/價錢大眾化;價錢貴/不合理/比日本台灣貴/可以再平d'
55
+ )
56
+ with gr.Row():
57
+ clear_codelist_btn = gr.ClearButton(value="Clear Code List")
58
+ clear_codelist_btn.click(lambda: None, outputs=[codelist_text])
59
+ upload_btn = gr.UploadButton(
60
+ label="Upload the code list file",
61
+ variant='primary'
62
+ )
63
+ upload_btn.upload(upload_code_list, upload_btn, codelist_text)
64
+ run_btn = gr.Button(
65
+ value="Submit",
66
+ variant='primary'
67
+ )
68
+ with gr.Column():
69
+ result_text = gr.JSON()
70
+ run_btn.click(coding, [select_model, comment_text, codelist_text], result_text, scroll_to_output=True)
71
+
72
+ if __name__ == "__main__":
73
+ demo.launch()
74
+