SurendraKumarDhaka commited on
Commit
1ee4c02
·
1 Parent(s): a9ec7a9

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -145
app.py DELETED
@@ -1,145 +0,0 @@
1
- import streamlit as st
2
- import time
3
- from datetime import datetime
4
- from transformers import SpeechT5Processor, SpeechT5ForSpeechToSpeech, SpeechT5HifiGan,SpeechT5ForTextToSpeech
5
- import numpy as np
6
- import torch
7
- from io import StringIO
8
- # from streamlit_chat import message as st_message
9
-
10
-
11
- html_temp= """
12
- <div style="background-color:tomato;padding:10px">
13
- <h2 style="color:white;text-align:centre;"> Text-to-Speech </h2>
14
- </div>
15
- """
16
- st.markdown(html_temp,unsafe_allow_html=True)
17
-
18
- st.markdown(
19
-
20
- """
21
- This is an AI tool. This tool will convert your text into audio. You can also drop you text file here and download the audio file.
22
- """
23
- )
24
- model = SpeechT5ForTextToSpeech.from_pretrained("speecht5_tts")
25
- processor = SpeechT5Processor.from_pretrained("speecht5_tts")
26
- vocoder = SpeechT5HifiGan.from_pretrained("speecht5_hifigan")
27
-
28
- speaker_embeddings = np.load("cmu_us_slt_arctic-wav-arctic_a0499.npy")
29
- speaker_embeddings = torch.tensor(speaker_embeddings).unsqueeze(0)
30
-
31
- text = st.text_area("Type your text..")
32
- st.button("Convert")
33
- inputs = processor(text=text, return_tensors="pt")
34
- spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)
35
- with torch.no_grad():
36
- speech = vocoder(spectrogram)
37
- import soundfile as sf
38
- sf.write("speech.wav", speech.numpy(), samplerate=16000)
39
-
40
- audio_file = open('speech.wav', 'rb')
41
- audio_bytes = audio_file.read()
42
- st.audio(audio_bytes, format='audio/wav')
43
-
44
-
45
- uploaded_file=st.file_uploader("Upload your text file here",type=['txt'] )
46
- if uploaded_file is not None:
47
- stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
48
- #To read file as string:
49
- text = stringio.read()
50
- st.write(text)
51
-
52
- st.button("Convert",key=1)
53
- inputs = processor(text=text, return_tensors="pt")
54
- spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)
55
- with torch.no_grad():
56
- speech = vocoder(spectrogram)
57
- import soundfile as sf
58
- sf.write("speech.wav", speech.numpy(), samplerate=16000)
59
- audio_file = open('speech.wav', 'rb')
60
- audio_bytes = audio_file.read()
61
- st.audio(audio_bytes, format='audio/wav')
62
-
63
-
64
-
65
-
66
-
67
- st.text("Thanks for using")
68
-
69
- if st.button("About"):
70
- st.text("Created by Surendra Kumar")
71
- ## footer
72
- from htbuilder import HtmlElement, div, ul, li, br, hr, a, p, img, styles, classes, fonts
73
- from htbuilder.units import percent, px
74
- from htbuilder.funcs import rgba, rgb
75
-
76
-
77
- def image(src_as_string, **style):
78
- return img(src=src_as_string, style=styles(**style))
79
-
80
-
81
- def link(link, text, **style):
82
- return a(_href=link, _target="_blank", style=styles(**style))(text)
83
-
84
-
85
- def layout(*args):
86
- style = """
87
- <style>
88
- # MainMenu {visibility: hidden;}
89
- footer {visibility: hidden;}
90
- .stApp { bottom: 105px; }
91
- </style>
92
- """
93
-
94
- style_div = styles(
95
- position="fixed",
96
- left=0,
97
- bottom=0,
98
- margin=px(0, 0, 0, 0),
99
- width=percent(100),
100
- color="black",
101
- text_align="center",
102
- height="auto",
103
- opacity=1
104
- )
105
-
106
- style_hr = styles(
107
- display="block",
108
- margin=px(8, 8, "auto", "auto"),
109
- border_style="solid",
110
- border_width=px(0.5)
111
- )
112
-
113
- body = p()
114
- foot = div(
115
- style=style_div
116
- )(
117
- hr(
118
- style=style_hr
119
- ),
120
- body
121
- )
122
- st.markdown(style,unsafe_allow_html=True)
123
-
124
- for arg in args:
125
- if isinstance(arg, str):
126
- body(arg)
127
-
128
- elif isinstance(arg, HtmlElement):
129
- body(arg)
130
-
131
- st.markdown(str(foot), unsafe_allow_html=True)
132
-
133
-
134
- def footer():
135
- myargs = [
136
- "©️ surendraKumar",
137
- br(),
138
- link("https://www.linkedin.com/in/surendra-kumar-51802022b", image('https://icons.getbootstrap.com/assets/icons/linkedin.svg') ),
139
- br(),
140
- link("https://www.instagram.com/im_surendra_dhaka/",image('https://icons.getbootstrap.com/assets/icons/instagram.svg')),
141
- ]
142
- layout(*myargs)
143
-
144
- if __name__ == "__main__":
145
- footer()