huimanho's picture
Create app.py
fec08c2 verified
raw
history blame
1.13 kB
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)