Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
3 |
+
|
4 |
+
# Load pipelines
|
5 |
+
pipe1 = pipeline("translation", model="DunnBC22/opus-mt-zh-en-Chinese_to_English")
|
6 |
+
pipe3 = pipeline("text-classification", model="lxyuan/distilbert-base-multilingual-cased-sentiments-student")
|
7 |
+
|
8 |
+
# Load model and tokenizer for pipe2
|
9 |
+
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 |
+
st.write("Translated Text:", english_text)
|
22 |
+
|
23 |
+
# Rating Prediction
|
24 |
+
inputs = tokenizer(english_text, return_tensors="pt")
|
25 |
+
outputs = model(**inputs)
|
26 |
+
prediction = outputs.logits.argmax(-1).item()
|
27 |
+
st.write("Estimated Amazon Rating:", prediction + 1)
|
28 |
+
|
29 |
+
# Sentiment Classification
|
30 |
+
sentiment = pipe3(english_text)[0]['label']
|
31 |
+
st.write("Sentiment:", sentiment)
|