Madiharehan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
-
def load_model():
|
7 |
-
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
|
8 |
-
|
9 |
-
model = load_model()
|
10 |
|
11 |
# Streamlit UI
|
12 |
st.title("Sentiment Analysis App using GenAI Models")
|
13 |
|
14 |
# Text input from the user
|
15 |
-
user_input = st.text_area("Enter text to analyze sentiment:")
|
16 |
|
17 |
# Prediction button
|
18 |
if st.button("Analyze"):
|
19 |
if user_input:
|
20 |
# Perform prediction
|
21 |
-
|
22 |
-
sentiment =
|
23 |
-
confidence = result[0]['score'] # Confidence score
|
24 |
-
|
25 |
-
# Display the sentiment and confidence score
|
26 |
st.write(f"**Predicted Sentiment:** {sentiment}")
|
27 |
-
st.write(f"**Confidence Score:** {confidence:.2f}")
|
28 |
else:
|
29 |
st.warning("Please enter some text to analyze.")
|
30 |
|
31 |
# Optional: Footer
|
32 |
st.write("---")
|
33 |
-
st.caption("Built with Streamlit and
|
|
|
1 |
import streamlit as st
|
2 |
+
import joblib # Replace with torch if using a PyTorch model
|
3 |
|
4 |
+
# Load the trained model (ensure the model file is in the same directory)
|
5 |
+
model = joblib.load('path_to_your_model.pkl')
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Streamlit UI
|
8 |
st.title("Sentiment Analysis App using GenAI Models")
|
9 |
|
10 |
# Text input from the user
|
11 |
+
user_input = st.text_area("Enter text to analyze sentiment:", "")
|
12 |
|
13 |
# Prediction button
|
14 |
if st.button("Analyze"):
|
15 |
if user_input:
|
16 |
# Perform prediction
|
17 |
+
prediction = model.predict([user_input])
|
18 |
+
sentiment = "Positive" if prediction[0] == 1 else "Negative"
|
|
|
|
|
|
|
19 |
st.write(f"**Predicted Sentiment:** {sentiment}")
|
|
|
20 |
else:
|
21 |
st.warning("Please enter some text to analyze.")
|
22 |
|
23 |
# Optional: Footer
|
24 |
st.write("---")
|
25 |
+
st.caption("Built with Streamlit and GenAI models.")
|