from transformers import T5Tokenizer, T5ForConditionalGeneration import streamlit as st tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large") model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large") def llm_response(prompt): input_ids = tokenizer(prompt, return_tensors="pt").input_ids outputs = model.generate(input_ids, max_length=300, do_sample=True, temperature=0.1) return tokenizer.decode(outputs[0])[6:-4] def predict_review_sentiment(review): sys_prompt = """ Categorize the sentiment of the customer review as positive, negative, or neutral. Leverage your expertise in the aviation industry and deep understanding of industry trends to analyze the nuanced expressions and overall tone. 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. Consider the importance of these neutral sentiments in gauging the public sentiment towards the airline company. 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 """ pred_sent = llm_response( """ {} Review text: '{}' """.format(sys_prompt, review) ) return pred_sent st.title("Airline Review Sentiment Classifier") review = st.text_area("Paste a review:") if st.button("Analyse Sentiment"): if review.strip(): result = predict_review_sentiment(review) st.success(f"Predicted Sentiment: {result}") else: st.warning("Please enter some review text.")