File size: 1,130 Bytes
fec08c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification

# Load pipelines
pipe1 = pipeline("translation", model="DunnBC22/opus-mt-zh-en-Chinese_to_English")
pipe3 = pipeline("text-classification", model="lxyuan/distilbert-base-multilingual-cased-sentiments-student")

# Load model and tokenizer for pipe2
tokenizer = AutoTokenizer.from_pretrained("huimanho/CustomModel_Amazon")
model = AutoModelForSequenceClassification.from_pretrained("huimanho/CustomModel_Amazon")

# Streamlit app
st.title("Chinese Review Analysis")

# Input text
chinese_text = st.text_area("Enter Chinese Review:")

if st.button("Analyze"):
    # Translation
    english_text = pipe1(chinese_text)[0]['translation_text']
    st.write("Translated Text:", english_text)

    # Rating Prediction
    inputs = tokenizer(english_text, return_tensors="pt")
    outputs = model(**inputs)
    prediction = outputs.logits.argmax(-1).item()
    st.write("Estimated Amazon Rating:", prediction + 1)

    # Sentiment Classification
    sentiment = pipe3(english_text)[0]['label']
    st.write("Sentiment:", sentiment)