Spaces:
Sleeping
Sleeping
Parse SA pred str
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModel, BertForSequenceClassification, AlbertForSequenceClassification, DebertaForSequenceClassification, AutoModelForSequenceClassification, RobertaForSequenceClassification
|
| 3 |
from peft.auto import AutoPeftModelForSequenceClassification
|
|
@@ -7,7 +8,20 @@ from huggingface_hub import hf_hub_download
|
|
| 7 |
import plotly.express as px
|
| 8 |
import pandas as pd
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
loraModel = AutoPeftModelForSequenceClassification.from_pretrained("Intradiction/text_classification_WithLORA")
|
| 13 |
#tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
|
@@ -28,13 +42,13 @@ SentimentAnalysis_LORA_pipe = pipeline("sentiment-analysis", model=sa_merged_mod
|
|
| 28 |
|
| 29 |
#text class models
|
| 30 |
def distilBERTnoLORA_fn(text):
|
| 31 |
-
return distilBERTnoLORA_pipe(text)
|
| 32 |
|
| 33 |
def distilBERTwithLORA_fn(text):
|
| 34 |
-
return SentimentAnalysis_LORA_pipe(text)
|
| 35 |
|
| 36 |
def distilBERTUntrained_fn(text):
|
| 37 |
-
return distilBERTUntrained_pipe(text)
|
| 38 |
|
| 39 |
|
| 40 |
# Handle calls to ALBERT---------------------------------------------
|
|
@@ -335,7 +349,7 @@ with gr.Blocks(
|
|
| 335 |
TextClassUntrained = gr.Textbox(label = "Training Informaiton")
|
| 336 |
|
| 337 |
with gr.Row(variant="panel"):
|
| 338 |
-
TextClassOut1 = gr.Textbox(label=
|
| 339 |
TextClassNoLoraStats = gr.Textbox(label = "Training Informaiton - Active Training Time: 27.95 mins")
|
| 340 |
|
| 341 |
with gr.Row(variant="panel"):
|
|
|
|
| 1 |
+
import json
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModel, BertForSequenceClassification, AlbertForSequenceClassification, DebertaForSequenceClassification, AutoModelForSequenceClassification, RobertaForSequenceClassification
|
| 4 |
from peft.auto import AutoPeftModelForSequenceClassification
|
|
|
|
| 8 |
import plotly.express as px
|
| 9 |
import pandas as pd
|
| 10 |
|
| 11 |
+
# Parse sentiment analysis pipeline results
|
| 12 |
+
def parse_pipe_sa(pipe_out_text: str):
|
| 13 |
+
output_list = list(pipe_out_text)
|
| 14 |
+
pipe_label = output_list[0]['label']
|
| 15 |
+
pipe_score = output_list[0]['score']
|
| 16 |
|
| 17 |
+
parsed_prediction = 'NULL'
|
| 18 |
+
|
| 19 |
+
if pipe_label == 'NEGATIVE' or pipe_label == 'LABEL_0':
|
| 20 |
+
parsed_prediction = f'This model thinks the sentiment is negative with a confidence score of {pipe_score}'
|
| 21 |
+
elif pipe_label == 'POSITIVE' or pipe_label == 'LABEL_1':
|
| 22 |
+
parsed_prediction = f'This model thinks the sentiment is positive with a confidence score of {pipe_score}'
|
| 23 |
+
|
| 24 |
+
return parsed_prediction
|
| 25 |
|
| 26 |
loraModel = AutoPeftModelForSequenceClassification.from_pretrained("Intradiction/text_classification_WithLORA")
|
| 27 |
#tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
|
|
|
| 42 |
|
| 43 |
#text class models
|
| 44 |
def distilBERTnoLORA_fn(text):
|
| 45 |
+
return parse_pipe_sa(distilBERTnoLORA_pipe(text))
|
| 46 |
|
| 47 |
def distilBERTwithLORA_fn(text):
|
| 48 |
+
return parse_pipe_sa(SentimentAnalysis_LORA_pipe(text))
|
| 49 |
|
| 50 |
def distilBERTUntrained_fn(text):
|
| 51 |
+
return parse_pipe_sa(distilBERTUntrained_pipe(text))
|
| 52 |
|
| 53 |
|
| 54 |
# Handle calls to ALBERT---------------------------------------------
|
|
|
|
| 349 |
TextClassUntrained = gr.Textbox(label = "Training Informaiton")
|
| 350 |
|
| 351 |
with gr.Row(variant="panel"):
|
| 352 |
+
TextClassOut1 = gr.Textbox(label="Conventionaly Trained Model")
|
| 353 |
TextClassNoLoraStats = gr.Textbox(label = "Training Informaiton - Active Training Time: 27.95 mins")
|
| 354 |
|
| 355 |
with gr.Row(variant="panel"):
|