Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,34 @@ import pandas as pd
|
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
-
def
|
| 8 |
classifier = pipeline("zero-shot-classification", model=model)
|
| 9 |
codelist = codetext.split(';')
|
| 10 |
output = classifier(text, codelist, multi_label=True)
|
| 11 |
return output
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def upload_code_list(file):
|
| 14 |
df = pd.read_excel(file.name, sheet_name='code')
|
| 15 |
joined_data = ';'.join(df['label'].astype(str))
|
| 16 |
return joined_data
|
| 17 |
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
with demo:
|
| 22 |
gr.Markdown(
|
|
@@ -59,8 +74,10 @@ with demo:
|
|
| 59 |
variant='primary'
|
| 60 |
)
|
| 61 |
with gr.Column():
|
| 62 |
-
result_text = gr.JSON()
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
demo.launch()
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
+
def coding_v1(model, text, codetext):
|
| 8 |
classifier = pipeline("zero-shot-classification", model=model)
|
| 9 |
codelist = codetext.split(';')
|
| 10 |
output = classifier(text, codelist, multi_label=True)
|
| 11 |
return output
|
| 12 |
|
| 13 |
+
def coding(model, text, codetext):
|
| 14 |
+
classifier = pipeline("zero-shot-classification", model=model)
|
| 15 |
+
codelist = codetext.split(';')
|
| 16 |
+
output = classifier(text, codelist, multi_label=True)
|
| 17 |
+
# keys = output.labels
|
| 18 |
+
# values = output.scores
|
| 19 |
+
keys = output['labels']
|
| 20 |
+
values = output['scores']
|
| 21 |
+
my_dict = {k: v for k, v in zip(keys, values)}
|
| 22 |
+
return my_dict
|
| 23 |
+
|
| 24 |
def upload_code_list(file):
|
| 25 |
df = pd.read_excel(file.name, sheet_name='code')
|
| 26 |
joined_data = ';'.join(df['label'].astype(str))
|
| 27 |
return joined_data
|
| 28 |
|
| 29 |
|
| 30 |
+
css = """
|
| 31 |
+
h2.svelte-1pq4gst{display:none}
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
demo = gr.Blocks(css=css)
|
| 35 |
|
| 36 |
with demo:
|
| 37 |
gr.Markdown(
|
|
|
|
| 74 |
variant='primary'
|
| 75 |
)
|
| 76 |
with gr.Column():
|
| 77 |
+
#result_text = gr.JSON()
|
| 78 |
+
result_label = gr.Label()
|
| 79 |
+
|
| 80 |
+
run_btn.click(coding, [select_model, comment_text, codelist_text], result_label, scroll_to_output=True)
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
| 83 |
demo.launch()
|