Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
st.set_page_config(page_title="Text to Sentiment Analysis Audio", page_icon="🦜")
|
@@ -17,12 +18,20 @@ def analyze_sentiment(text):
|
|
17 |
return sentiment, probability
|
18 |
|
19 |
def format_sentiment_text(sentiment, probability):
|
20 |
-
return f"The
|
21 |
-
|
22 |
-
def
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def text_to_audio(text):
|
28 |
audio = text_audio_pipeline(text)
|
@@ -39,8 +48,8 @@ if input_text:
|
|
39 |
|
40 |
# Stage 2: Convert text to audio
|
41 |
st.text('Generating audio...')
|
42 |
-
|
43 |
-
sentiment_text_for_audio =
|
44 |
audio_data = text_to_audio(sentiment_text_for_audio)
|
45 |
|
46 |
# Play button
|
|
|
1 |
import streamlit as st
|
2 |
+
import inflect
|
3 |
from transformers import pipeline
|
4 |
|
5 |
st.set_page_config(page_title="Text to Sentiment Analysis Audio", page_icon="🦜")
|
|
|
18 |
return sentiment, probability
|
19 |
|
20 |
def format_sentiment_text(sentiment, probability):
|
21 |
+
return f"The sentence is {sentiment} with a probability of {probability:.2f}."
|
22 |
+
|
23 |
+
def number_to_words(number):
|
24 |
+
p = inflect.engine()
|
25 |
+
# Split the number into integer and decimal parts
|
26 |
+
integer_part, decimal_part = divmod(number, 1)
|
27 |
+
# Convert integer part to words
|
28 |
+
words = p.number_to_words(int(integer_part))
|
29 |
+
# Handle the decimal part
|
30 |
+
if decimal_part > 0:
|
31 |
+
decimal_part = round(decimal_part * 100) # Convert to two decimal places
|
32 |
+
decimal_words = p.number_to_words(int(decimal_part))
|
33 |
+
words += f" point {decimal_words.replace('-', ' ')}"
|
34 |
+
return words
|
35 |
|
36 |
def text_to_audio(text):
|
37 |
audio = text_audio_pipeline(text)
|
|
|
48 |
|
49 |
# Stage 2: Convert text to audio
|
50 |
st.text('Generating audio...')
|
51 |
+
prob=number_to_words(probability)
|
52 |
+
sentiment_text_for_audio = f"The sentence is {sentiment}, with a probability of {prob:.2f}."
|
53 |
audio_data = text_to_audio(sentiment_text_for_audio)
|
54 |
|
55 |
# Play button
|