Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,20 @@ 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
|
| 13 |
predictions = model2(text)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
|
|
|
| 16 |
return f"Error processing input: {e}"
|
| 17 |
|
| 18 |
def documentation():
|
|
|
|
| 7 |
|
| 8 |
def predict_sentiment(text, model_choice):
|
| 9 |
try:
|
| 10 |
+
if model_choice == "Model 1 (Default Transformer)":
|
| 11 |
predictions = model1(text)
|
| 12 |
+
elif model_choice == "Model 2 (BERTweet)":
|
| 13 |
predictions = model2(text)
|
| 14 |
+
else:
|
| 15 |
+
return "Model choice is not recognized."
|
| 16 |
+
|
| 17 |
+
if predictions:
|
| 18 |
+
return f"Label: {predictions[0]['label']}, Score: {predictions[0]['score']:.4f}"
|
| 19 |
+
else:
|
| 20 |
+
return "No predictions returned by the model."
|
| 21 |
+
|
| 22 |
except Exception as e:
|
| 23 |
+
# This catches any error and returns it directly
|
| 24 |
return f"Error processing input: {e}"
|
| 25 |
|
| 26 |
def documentation():
|