Spaces:
Sleeping
Sleeping
msg
Browse files
app.py
CHANGED
|
@@ -18,24 +18,27 @@ def predict_sentiment(texts):
|
|
| 18 |
return [sentiment_map[p] for p in torch.argmax(probabilities, dim=-1).tolist()]
|
| 19 |
|
| 20 |
# Streamlit UI
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
st.sidebar.
|
| 24 |
-
|
| 25 |
-
uploaded_file = st.file_uploader("Upload Excel File", type=["xlsx", "xls"])
|
| 26 |
|
| 27 |
if uploaded_file is not None:
|
| 28 |
-
df = pd.read_excel(uploaded_file)
|
| 29 |
-
st.write("
|
|
|
|
|
|
|
| 30 |
st.dataframe(df.head())
|
| 31 |
|
| 32 |
-
text_column = st.selectbox("Select
|
| 33 |
|
| 34 |
-
if st.button("Analyze Sentiment"):
|
| 35 |
df["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
|
| 36 |
|
| 37 |
# Display results
|
| 38 |
-
st.write("Sentiment Analysis Results:")
|
| 39 |
st.dataframe(df[[text_column, "Sentiment"]])
|
| 40 |
|
| 41 |
# Pie chart
|
|
@@ -46,4 +49,5 @@ if uploaded_file is not None:
|
|
| 46 |
st.pyplot(fig)
|
| 47 |
|
| 48 |
# Download option
|
| 49 |
-
st.download_button("Download Results", df.to_csv(index=False).encode('utf-8'), "sentiment_results.csv", "text/csv")
|
|
|
|
|
|
| 18 |
return [sentiment_map[p] for p in torch.argmax(probabilities, dim=-1).tolist()]
|
| 19 |
|
| 20 |
# Streamlit UI
|
| 21 |
+
st.title("Sentiment Analysis App")
|
| 22 |
+
st.write("Analyze sentiment from uploaded text data.")
|
| 23 |
|
| 24 |
+
# Sidebar for File Upload
|
| 25 |
+
st.sidebar.header("Upload File")
|
| 26 |
+
uploaded_file = st.sidebar.file_uploader("Choose an Excel File", type=["xlsx", "xls"])
|
|
|
|
| 27 |
|
| 28 |
if uploaded_file is not None:
|
| 29 |
+
df = pd.read_excel(uploaded_file, engine="openpyxl") # Ensure openpyxl is installed
|
| 30 |
+
st.sidebar.write("✅ File Uploaded Successfully!")
|
| 31 |
+
|
| 32 |
+
st.write("### Preview of Uploaded Data:")
|
| 33 |
st.dataframe(df.head())
|
| 34 |
|
| 35 |
+
text_column = st.sidebar.selectbox("Select Text Column", df.columns)
|
| 36 |
|
| 37 |
+
if st.sidebar.button("Analyze Sentiment"):
|
| 38 |
df["Sentiment"] = predict_sentiment(df[text_column].astype(str).tolist())
|
| 39 |
|
| 40 |
# Display results
|
| 41 |
+
st.write("### Sentiment Analysis Results:")
|
| 42 |
st.dataframe(df[[text_column, "Sentiment"]])
|
| 43 |
|
| 44 |
# Pie chart
|
|
|
|
| 49 |
st.pyplot(fig)
|
| 50 |
|
| 51 |
# Download option
|
| 52 |
+
st.sidebar.download_button("Download Results", df.to_csv(index=False).encode('utf-8'), "sentiment_results.csv", "text/csv")
|
| 53 |
+
|