Spaces:
Sleeping
Sleeping
Taranosaurus
commited on
Commit
·
f0b38f2
1
Parent(s):
c502ceb
Created first version of app.py
Browse filesNot really the first version, but the first version going public 🤗
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
|
5 |
+
if torch.cuda.is_available():
|
6 |
+
device = torch.device("cuda")
|
7 |
+
else:
|
8 |
+
device = torch.device("cpu")
|
9 |
+
|
10 |
+
summary = pipeline(task="summarization", model="facebook/bart-large-cnn", device=device)
|
11 |
+
oracle = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli", device=device)
|
12 |
+
labels = ["merge","revert","fix","feature","update","refactor","test","security","documentation","style"]
|
13 |
+
|
14 |
+
def do_the_thing(input, labels):
|
15 |
+
#print(labels)
|
16 |
+
summarisation = summary(input)[0]['summary_text']
|
17 |
+
zsc_results = oracle(sequences=[input, summarisation], candidate_labels=labels, multi_label=False, batch_size=2)
|
18 |
+
classifications_input = {}
|
19 |
+
for i in range(len(labels)):
|
20 |
+
classifications_input.update({zsc_results[0]['labels'][i]: zsc_results[0]['scores'][i]})
|
21 |
+
i+=1
|
22 |
+
#zsc_results_summary = oracle(sequences=summarisation, candidate_labels=labels, multi_label=False)
|
23 |
+
classifications_summary = {}
|
24 |
+
for i in range(len(labels)):
|
25 |
+
classifications_summary.update({zsc_results[1]['labels'][i]: zsc_results[1]['scores'][i]})
|
26 |
+
i+=1
|
27 |
+
return [summarisation, classifications_input, classifications_summary]
|
28 |
+
|
29 |
+
with gr.Blocks() as frontend:
|
30 |
+
gr.Markdown(f"## Git Commit Classifier\n\nThis tool is to take the notes from a commit, summarise and classify the original and the summary.\n\nTo get the git commit notes, clone the repo and the run `git log --all --pretty='format:Subject: %s%nBody: %b%n-----%n'`")
|
31 |
+
input_value = gr.TextArea(label="Notes to Summarise")
|
32 |
+
btn_submit = gr.Button(value="Summarise and Classify")
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column():
|
35 |
+
input_labels = gr.Dropdown(label="Classification Labels", choices=labels, multiselect=True, value=labels, interactive=True, allow_custom_value=True, info="Labels to classify the original text and summary")
|
36 |
+
with gr.Column():
|
37 |
+
output_summary_text = gr.TextArea(label="Summary of Notes")
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column():
|
40 |
+
output_original_labels = gr.Label(label="Original Text Classification")
|
41 |
+
with gr.Column():
|
42 |
+
output_summary_labels = gr.Label(label="Summary Text Classification")
|
43 |
+
btn_submit.click(fn=do_the_thing, inputs=[input_value, input_labels], outputs=[output_summary_text, output_original_labels, output_summary_labels])
|
44 |
+
|
45 |
+
frontend.launch()
|