Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,9 @@ import gradio as gr
|
|
| 3 |
|
| 4 |
# Attempt to load the model and run a test prediction
|
| 5 |
try:
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
test_output = sentiment_analysis("Testing the model with a simple sentence.")
|
| 8 |
print("Model test output:", test_output)
|
| 9 |
except Exception as e:
|
|
@@ -17,9 +19,8 @@ def predict_sentiment(text):
|
|
| 17 |
except Exception as e:
|
| 18 |
return f"Error processing input: {e}"
|
| 19 |
|
| 20 |
-
|
| 21 |
# Define example inputs
|
| 22 |
-
|
| 23 |
"I absolutely love this product! It has changed my life.",
|
| 24 |
"This is the worst movie I have ever seen. Completely disappointing.",
|
| 25 |
"I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.",
|
|
@@ -33,6 +34,6 @@ iface = gr.Interface(fn=predict_sentiment,
|
|
| 33 |
description="Enter text to analyze sentiment. Powered by Hugging Face Transformers.",
|
| 34 |
inputs="text",
|
| 35 |
outputs="text",
|
| 36 |
-
examples=
|
| 37 |
|
| 38 |
-
iface.launch()
|
|
|
|
| 3 |
|
| 4 |
# Attempt to load the model and run a test prediction
|
| 5 |
try:
|
| 6 |
+
# Explicitly specify the model
|
| 7 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 8 |
+
sentiment_analysis = pipeline("sentiment-analysis", model=model_name)
|
| 9 |
test_output = sentiment_analysis("Testing the model with a simple sentence.")
|
| 10 |
print("Model test output:", test_output)
|
| 11 |
except Exception as e:
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error processing input: {e}"
|
| 21 |
|
|
|
|
| 22 |
# Define example inputs
|
| 23 |
+
examples = [
|
| 24 |
"I absolutely love this product! It has changed my life.",
|
| 25 |
"This is the worst movie I have ever seen. Completely disappointing.",
|
| 26 |
"I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.",
|
|
|
|
| 34 |
description="Enter text to analyze sentiment. Powered by Hugging Face Transformers.",
|
| 35 |
inputs="text",
|
| 36 |
outputs="text",
|
| 37 |
+
examples=examples)
|
| 38 |
|
| 39 |
+
iface.launch()
|