JethroDD's picture
Update app.py
9d3c70e verified
raw
history blame contribute delete
No virus
2.61 kB
import streamlit as st
from transformers import pipeline
from datasets import Dataset, DatasetDict, load_dataset
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification,AutoConfig
from datasets import load_metric
from transformers import TrainingArguments, Trainer
def sentiment(comment):
model = pipeline("text-classification", model="JethroDD/twitter-roberta-base-sentiment-CustomModel_imdb")
outputs = model(comment)
result_text =outputs[0]["label"]
if result_text == "LABEL_1":
result_text = "Positive"
elif result_text == "LABEL_0":
result_text = "Negative"
print(f"The predicted class is {result_text}")
return result_text
# TextSummary
def txtsummary(text):
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
summary_text = summarizer(text)[0]["summary_text"]
return summary_text
# result2Audio
def text2audio(result_text):
speaker = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
audio_data = speaker(result_text)
return audio_data
def main():
st.set_page_config(page_title="Movie Review Analysor", page_icon="🎬")
st.header("Movie Review Analysor")
text_box = st.text_input("Please paste your review here:",on_change=None)
# text_box = "If only to avoid making this type of film in the future. This film is interesting as an experiment but tells no cogent story.<br /><br />One might feel virtuous for sitting thru it because it touches on so many IMPORTANT issues but it does so without any discernable motive. The viewer comes away with no new perspectives (unless one comes up with one while one's mind wanders, as it will invariably do during this pointless film).<br /><br />One might better spend one's time staring out a window at a tree growing.<br /><br />"
if st.button("Analyse!"):
# stage 1
st.text('Processing sentiment analysis...')
sentiment_result = sentiment(text_box)
st.write(sentiment_result)
# stage 2
st.text('Summarying review...')
summary_text = txtsummary(text_box)
st.write(summary_text)
# stage 3
final_text = "The sentiment of this review is {}. There is the summary of this comments: {}".format(sentiment_result,summary_text)
audio_result = text2audio(final_text)
st.audio(audio_result['audio'],
format="audio/wav",
start_time=0,
sample_rate = audio_result['sampling_rate'])
st.text('Press buttom to play result!')
main()