omm7 commited on
Commit
b434163
·
verified ·
1 Parent(s): 39296a5

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. app.py +37 -0
  3. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Create non-root user (required by Hugging Face)
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --chown=user requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY --chown=user . .
14
+
15
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.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.")
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ matplotlib
5
+ seaborn
6
+ transformers==4.40.2
7
+ torch
8
+ scikit-learn
9
+ sentencepiece