Update app.py
Browse files
app.py
CHANGED
@@ -23,15 +23,9 @@ install_packages()
|
|
23 |
|
24 |
import gradio as gr
|
25 |
from huggingface_hub import login
|
26 |
-
from optimum.onnxruntime import ORTModelForSeq2SeqLM
|
27 |
-
from transformers import AutoTokenizer, pipeline
|
28 |
-
|
29 |
-
from transformers import AutoTokenizer, pipeline
|
30 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
31 |
-
import
|
32 |
-
# with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
|
33 |
|
34 |
-
# with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
|
35 |
model_id = "HassamAliCADI/SentimentOnx"
|
36 |
hf_token = os.environ.get("NLP")
|
37 |
|
@@ -42,38 +36,24 @@ else:
|
|
42 |
|
43 |
model = ORTModelForSequenceClassification.from_pretrained(model_id)
|
44 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
45 |
-
# with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
|
46 |
|
47 |
-
# with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
|
48 |
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
|
49 |
|
50 |
def classify_text(text):
|
51 |
-
# start_time = time.time()
|
52 |
results = pipe(text)
|
53 |
-
# end_time = time.time()
|
54 |
-
|
55 |
-
# with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
|
56 |
-
|
57 |
-
# with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
|
58 |
-
|
59 |
-
|
60 |
-
# #warning {background-color: #FFCCCB}# .feedback textarea {font-size: 24px !important}# """
|
61 |
-
|
62 |
output = ""
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
return output
|
67 |
|
68 |
gr.Interface(
|
69 |
-
|
70 |
-
# with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
|
71 |
-
|
72 |
-
# with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
|
73 |
-
|
74 |
-
|
75 |
-
# #warning {background-color: #FFCCCB}# .feedback textarea {font-size: 24px !important}# """
|
76 |
-
|
77 |
fn=classify_text,
|
78 |
title="Sentiment Classifier",
|
79 |
description="Enter text to classify sentiment",
|
|
|
23 |
|
24 |
import gradio as gr
|
25 |
from huggingface_hub import login
|
|
|
|
|
|
|
|
|
26 |
from optimum.onnxruntime import ORTModelForSequenceClassification
|
27 |
+
from transformers import AutoTokenizer, pipeline
|
|
|
28 |
|
|
|
29 |
model_id = "HassamAliCADI/SentimentOnx"
|
30 |
hf_token = os.environ.get("NLP")
|
31 |
|
|
|
36 |
|
37 |
model = ORTModelForSequenceClassification.from_pretrained(model_id)
|
38 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
|
39 |
|
|
|
40 |
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
|
41 |
|
42 |
def classify_text(text):
|
|
|
43 |
results = pipe(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
output = ""
|
45 |
+
|
46 |
+
if len(results) > 0:
|
47 |
+
# Print the first result
|
48 |
+
output += f"Label 1: {result['label']}, Score: {result['score']:.4f}\n"
|
49 |
+
|
50 |
+
# Print the second result if it exists
|
51 |
+
if len(results) > 1:
|
52 |
+
output += f"Label 2: {results[1]['label']}, Score: {results[1]['score']:.4f}\n"
|
53 |
+
|
54 |
return output
|
55 |
|
56 |
gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
fn=classify_text,
|
58 |
title="Sentiment Classifier",
|
59 |
description="Enter text to classify sentiment",
|