Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,22 +10,34 @@ tokenizer = AutoTokenizer.from_pretrained("huimanho/CustomModel_Amazon")
|
|
10 |
model = AutoModelForSequenceClassification.from_pretrained("huimanho/CustomModel_Amazon")
|
11 |
|
12 |
# Streamlit app
|
13 |
-
st.title("Chinese Review Analysis")
|
14 |
|
15 |
# Input text
|
16 |
-
chinese_text = st.text_area("Enter Chinese Review:")
|
17 |
|
18 |
if st.button("Analyze"):
|
19 |
# Translation
|
20 |
english_text = pipe1(chinese_text)[0]['translation_text']
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
# Rating Prediction
|
24 |
inputs = tokenizer(english_text, return_tensors="pt")
|
25 |
outputs = model(**inputs)
|
26 |
prediction = outputs.logits.argmax(-1).item()
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
# Sentiment Classification
|
30 |
sentiment = pipe3(english_text)[0]['label']
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
model = AutoModelForSequenceClassification.from_pretrained("huimanho/CustomModel_Amazon")
|
11 |
|
12 |
# Streamlit app
|
13 |
+
st.title("Chinese Review Analysis - Translation, Rating & Sentiment")
|
14 |
|
15 |
# Input text
|
16 |
+
chinese_text = st.text_area("Enter Chinese Review:", height=150)
|
17 |
|
18 |
if st.button("Analyze"):
|
19 |
# Translation
|
20 |
english_text = pipe1(chinese_text)[0]['translation_text']
|
21 |
+
|
22 |
+
# Display translation
|
23 |
+
st.subheader("Translated Text")
|
24 |
+
st.write(english_text)
|
25 |
|
26 |
# Rating Prediction
|
27 |
inputs = tokenizer(english_text, return_tensors="pt")
|
28 |
outputs = model(**inputs)
|
29 |
prediction = outputs.logits.argmax(-1).item()
|
30 |
+
|
31 |
+
# Display estimated rating
|
32 |
+
st.subheader("Estimated Amazon Rating")
|
33 |
+
st.write(f"**Rating:** {prediction + 1} out of 5")
|
34 |
|
35 |
# Sentiment Classification
|
36 |
sentiment = pipe3(english_text)[0]['label']
|
37 |
+
|
38 |
+
# Display sentiment
|
39 |
+
st.subheader("Sentiment Analysis")
|
40 |
+
st.write(f"**Sentiment:** {sentiment}")
|
41 |
+
|
42 |
+
# Additional styling
|
43 |
+
st.markdown("---") # Add a horizontal line for separation
|