omm7 commited on
Commit
429fbfe
·
verified ·
1 Parent(s): 541ab60

Upload app (1).py

Browse files
Files changed (1) hide show
  1. app (1).py +37 -0
app (1).py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")