lifewjola commited on
Commit
b282894
1 Parent(s): 1e0fede

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -16
app.py CHANGED
@@ -1,29 +1,44 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Load the text classification model
5
- text_classifier = pipeline("text-classification", model="distilbert-base-uncased")
6
 
7
  def main():
8
- st.title("How Good is my Writing?")
9
 
10
- # Text input area for the user
11
- text = st.text_area("Enter your text:")
12
 
13
- if st.button("Rate it"):
14
- if text:
15
- analyze_writing_quality(text)
16
  else:
17
- st.warning("Please enter some text.")
18
 
19
- def analyze_writing_quality(text):
20
- classification_result = text_classifier(text)
21
- predicted_label = classification_result[0]['label']
22
- predicted_score = classification_result[0]['score']
23
 
24
- st.subheader("Writing Quality Analysis Result:")
25
- st.write(f"Predicted Quality: {predicted_label}")
26
- st.write(f"Confidence Score: {predicted_score:.2f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()