Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,12 @@ from transformers import pipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# Load models only once to improve performance
|
| 5 |
-
model1 = pipeline(model="
|
| 6 |
model2 = pipeline(model="finiteautomata/bertweet-base-sentiment-analysis")
|
| 7 |
|
| 8 |
def predict_sentiment(text, model_choice):
|
| 9 |
try:
|
| 10 |
-
if model_choice == "Model 1 (
|
| 11 |
predictions = model1(text)
|
| 12 |
elif model_choice == "Model 2 (BERTweet-base)":
|
| 13 |
predictions = model2(text)
|
|
@@ -21,7 +21,7 @@ def documentation():
|
|
| 21 |
|
| 22 |
This demo utilizes two different models from the Hugging Face Transformers library:
|
| 23 |
|
| 24 |
-
|
| 25 |
- **Model 2**: BERTweet for sentiment analysis specifically fine-tuned for English Tweets.
|
| 26 |
|
| 27 |
Choose a model from the dropdown and enter text to see the sentiment prediction.
|
|
@@ -41,7 +41,7 @@ tab1 = gr.Interface(
|
|
| 41 |
fn=predict_sentiment,
|
| 42 |
title="Sentiment Analysis",
|
| 43 |
description="Select a model and enter text to analyze sentiment.",
|
| 44 |
-
inputs=[gr.Textbox(label="Input Text"), gr.Radio(["Model 1 (
|
| 45 |
outputs="text",
|
| 46 |
examples=exams
|
| 47 |
)
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# Load models only once to improve performance
|
| 5 |
+
model1 = pipeline(model="siebert/sentiment-roberta-large-english")
|
| 6 |
model2 = pipeline(model="finiteautomata/bertweet-base-sentiment-analysis")
|
| 7 |
|
| 8 |
def predict_sentiment(text, model_choice):
|
| 9 |
try:
|
| 10 |
+
if model_choice == "Model 1 (RoBERTa-large)":
|
| 11 |
predictions = model1(text)
|
| 12 |
elif model_choice == "Model 2 (BERTweet-base)":
|
| 13 |
predictions = model2(text)
|
|
|
|
| 21 |
|
| 22 |
This demo utilizes two different models from the Hugging Face Transformers library:
|
| 23 |
|
| 24 |
+
- **Model 1**: RoBERTa-large for sentiment analysis fine-tuned for diverse English text sources to enhance generalization across different types of texts (reviews, tweets, etc.).
|
| 25 |
- **Model 2**: BERTweet for sentiment analysis specifically fine-tuned for English Tweets.
|
| 26 |
|
| 27 |
Choose a model from the dropdown and enter text to see the sentiment prediction.
|
|
|
|
| 41 |
fn=predict_sentiment,
|
| 42 |
title="Sentiment Analysis",
|
| 43 |
description="Select a model and enter text to analyze sentiment.",
|
| 44 |
+
inputs=[gr.Textbox(label="Input Text"), gr.Radio(["Model 1 (RoBERTa-large)", "Model 2 (BERTweet-base)"], label="Model Choice")],
|
| 45 |
outputs="text",
|
| 46 |
examples=exams
|
| 47 |
)
|