Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,44 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load the
|
5 |
-
|
6 |
|
7 |
def main():
|
8 |
-
st.title("
|
9 |
|
10 |
-
# Text input area for the user
|
11 |
-
|
12 |
|
13 |
-
if st.button("
|
14 |
-
if
|
15 |
-
|
16 |
else:
|
17 |
-
st.warning("Please enter
|
18 |
|
19 |
-
def
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the sentiment analysis model
|
5 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased")
|
6 |
|
7 |
def main():
|
8 |
+
st.title("Feedback Analyzer for Creative Writing")
|
9 |
|
10 |
+
# Text input area for the user's creative writing
|
11 |
+
writing = st.text_area("Enter your creative writing:")
|
12 |
|
13 |
+
if st.button("Analyze Writing"):
|
14 |
+
if writing:
|
15 |
+
analyze_writing_feedback(writing)
|
16 |
else:
|
17 |
+
st.warning("Please enter your creative writing.")
|
18 |
|
19 |
+
def analyze_writing_feedback(writing):
|
20 |
+
sentiment_result = sentiment_analyzer(writing)
|
21 |
+
sentiment_label = sentiment_result[0]['label']
|
22 |
+
sentiment_score = sentiment_result[0]['score']
|
23 |
|
24 |
+
feedback = generate_feedback(sentiment_label)
|
25 |
+
|
26 |
+
st.subheader("Feedback for Creative Writing:")
|
27 |
+
st.write("Sentiment Analysis Result:")
|
28 |
+
st.write(f"Sentiment: {sentiment_label}")
|
29 |
+
st.write(f"Confidence Score: {sentiment_score:.2f}")
|
30 |
+
st.write("Feedback:")
|
31 |
+
st.write(feedback)
|
32 |
+
|
33 |
+
def generate_feedback(sentiment_label):
|
34 |
+
if sentiment_label == "LABEL_1":
|
35 |
+
feedback = "Your writing has a positive sentiment! It evokes a sense of optimism and positivity."
|
36 |
+
elif sentiment_label == "LABEL_0":
|
37 |
+
feedback = "Your writing has a negative sentiment. It might be helpful to focus on brighter and more uplifting themes."
|
38 |
+
else:
|
39 |
+
feedback = "Your writing is neutral. Consider adding more emotional depth to enhance the impact."
|
40 |
+
|
41 |
+
return feedback
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
main()
|