JethroDD commited on
Commit
73d4b43
1 Parent(s): 7c24489

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from datasets import Dataset, DatasetDict, load_dataset
4
+ import torch
5
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification,AutoConfig
6
+ from datasets import load_metric
7
+ from transformers import TrainingArguments, Trainer
8
+
9
+
10
+
11
+ def sentiment(comment):
12
+
13
+ model = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
14
+ outputs = model(comment)
15
+ result_text =outputs[0]["label"]
16
+ print(f"The predicted class is {result_text}")
17
+
18
+ return result_text
19
+
20
+ # TextSummary
21
+ def txtsummary(text):
22
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
23
+ summary_text = summarizer(text)[0]["summary_text"]
24
+
25
+ return summary_text
26
+
27
+ # result2Audio
28
+ def text2audio(result_text):
29
+ speaker = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
30
+ audio_data = speaker(result_text)
31
+ return audio_data
32
+
33
+
34
+
35
+
36
+ def main():
37
+
38
+ st.set_page_config(page_title="Movie Review Analysor", page_icon="🎬")
39
+ st.header("Movie Review Analysor")
40
+ text_box = st.text_input("Please paste your review here:",on_change=None)
41
+ # 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 />"
42
+ if st.button("Analyse!"):
43
+ # stage 1
44
+ st.text('Processing sentiment analysis...')
45
+ sentiment_result = sentiment(text_box)
46
+ st.write(sentiment_result)
47
+
48
+ # stage 2
49
+
50
+ st.text('Summarying review...')
51
+ summary_text = txtsummary(text_box)
52
+ st.write(summary_text)
53
+
54
+
55
+ # stage 3
56
+
57
+ final_text = "The sentiment of this review is {}. There is the summary of this comments: {}".format(sentiment_result,summary_text)
58
+
59
+ audio_result = text2audio(final_text)
60
+ st.audio(audio_result['audio'],
61
+ format="audio/wav",
62
+ start_time=0,
63
+ sample_rate = audio_result['sampling_rate'])
64
+ st.text('Press buttom to play result!')
65
+
66
+
67
+
68
+ main()