omm7 commited on
Commit
7a26975
·
verified ·
1 Parent(s): a66c41a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -36
app.py CHANGED
@@ -1,37 +1,38 @@
1
- from transformers import T5Tokenizer, T5ForConditionalGeneration
2
- import streamlit as st
3
-
4
- tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
5
- model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
6
-
7
- def llm_response(prompt):
8
- input_ids = tokenizer(prompt, return_tensors="pt").input_ids
9
- outputs = model.generate(input_ids, max_length=300, do_sample=True, temperature=0.1)
10
- return tokenizer.decode(outputs[0])[6:-4]
11
-
12
- def predict_review_sentiment(review):
13
- sys_prompt = """
14
- Categorize the sentiment of the customer review as positive, negative, or neutral.
15
- Leverage your expertise in the aviation industry and deep understanding of industry trends to analyze the nuanced expressions and overall tone.
16
- It is crucial to accurately identify neutral sentiments, which may indicate a balanced view or neutral stance towards Us Airways. Neutral expressions could involve factual statements without explicit positive or negative opinions.
17
- Consider the importance of these neutral sentiments in gauging the public sentiment towards the airline company.
18
- For instance, a positive sentiment might convey satisfaction with the airline's services, a negative sentiment could express dissatisfaction, while neutral sentiment may reflect an impartial observation or a neutral standpoint
19
- """
20
- pred_sent = llm_response(
21
- """
22
- {}
23
- Review text: '{}'
24
- """.format(sys_prompt, review)
25
- )
26
- return pred_sent
27
-
28
- st.title("Airline Review Sentiment Classifier")
29
-
30
- review = st.text_area("Paste a review:")
31
-
32
- if st.button("Analyse Sentiment"):
33
- if review.strip():
34
- result = predict_review_sentiment(review)
35
- st.success(f"Predicted Sentiment: {result}")
36
- else:
 
37
  st.warning("Please enter some review text.")
 
1
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
2
+ import streamlit as st
3
+
4
+ tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
5
+ model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
6
+
7
+ def llm_response(prompt):
8
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
9
+ outputs = model.generate(input_ids, max_length=300, do_sample=True, temperature=0.1)
10
+ return tokenizer.decode(outputs[0])[6:-4]
11
+
12
+
13
+ def predict_review_sentiment(review):
14
+ sys_prompt = """
15
+ Categorize the sentiment of the customer review as positive, negative, or neutral.
16
+ Leverage your expertise in the aviation industry and deep understanding of industry trends to analyze the nuanced expressions and overall tone.
17
+ It is crucial to accurately identify neutral sentiments, which may indicate a balanced view or neutral stance towards Us Airways. Neutral expressions could involve factual statements without explicit positive or negative opinions.
18
+ Consider the importance of these neutral sentiments in gauging the public sentiment towards the airline company.
19
+ For instance, a positive sentiment might convey satisfaction with the airline's services, a negative sentiment could express dissatisfaction, while neutral sentiment may reflect an impartial observation or a neutral standpoint
20
+ """
21
+ pred_sent = llm_response(
22
+ """
23
+ {}
24
+ Review text: '{}'
25
+ """.format(sys_prompt, review)
26
+ )
27
+ return pred_sent
28
+
29
+ st.title("Airline Review Sentiment Classifier")
30
+
31
+ review = st.text_area("Paste a review:")
32
+
33
+ if st.button("Analyse Sentiment"):
34
+ if review.strip():
35
+ result = predict_review_sentiment(review)
36
+ st.success(f"Predicted Sentiment: {result}")
37
+ else:
38
  st.warning("Please enter some review text.")