Spaces:
Runtime error
Runtime error
File size: 2,795 Bytes
d85379c bfa08d3 c4cf5c4 bfa08d3 8b4a6c9 2171fc9 bfa08d3 a2ea162 bfa08d3 80eac88 2171fc9 c4cf5c4 80eac88 8b4a6c9 2171fc9 c4cf5c4 42cf708 c4cf5c4 8b4a6c9 c4cf5c4 8b4a6c9 c4cf5c4 8b4a6c9 c4cf5c4 8b4a6c9 c4cf5c4 2171fc9 42cf708 2171fc9 c4cf5c4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
from transformers import pipeline
import gradio as gr
import pandas as pd
def coding_v1(model, text, codetext):
classifier = pipeline("zero-shot-classification", model=model)
codelist = codetext.split(';')
output = classifier(text, codelist, multi_label=True)
return output
def coding(model, text, codetext):
classifier = pipeline("zero-shot-classification", model=model)
codelist = codetext.split(';')
output = classifier(text, codelist, multi_label=True)
# keys = output.labels
# values = output.scores
keys = output['labels']
values = output['scores']
my_dict = {k: v for k, v in zip(keys, values)}
return my_dict
def upload_code_list(file):
df = pd.read_excel(file.name, sheet_name='code')
joined_data = ';'.join(df['label'].astype(str))
return joined_data
css = """
h2.svelte-1pq4gst{display:none}
"""
demo = gr.Blocks(css=css)
with demo:
gr.Markdown(
"""
# NuanceTree
# Coding Test Program
"""
)
with gr.Row():
with gr.Column():
select_model = gr.Radio(
[
"facebook/bart-large-mnli",
"MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli",
"MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7",
"MoritzLaurer/mDeBERTa-v3-base-mnli-xnli",
"MoritzLaurer/deberta-v3-large-zeroshot-v2.0",
],
value="MoritzLaurer/multilingual-MiniLMv2-L6-mnli-xnli",
label="Model"
)
comment_text = gr.TextArea(
label='Comment',
value='感覺性格溫和,特別係亞洲人的肌膚,不足之處就是感覺很少有優惠,價錢都比較貴'
)
codelist_text = gr.Textbox(
label='Code list (colon-separated)',
value='非常好;很好;好滿意;價錢合理;實惠'
)
with gr.Row():
clear_codelist_btn = gr.ClearButton(value="Clear Code List")
clear_codelist_btn.click(lambda: None, outputs=[codelist_text])
upload_btn = gr.UploadButton(
label="Upload",
variant='primary'
)
upload_btn.upload(upload_code_list, upload_btn, codelist_text)
run_btn = gr.Button(
value="Submit",
variant='primary'
)
with gr.Column():
#result_text = gr.JSON()
result_label = gr.Label(show_label=False)
run_btn.click(coding, [select_model, comment_text, codelist_text], result_label, scroll_to_output=True)
if __name__ == "__main__":
demo.launch()
|