Spaces:
Runtime error
Runtime error
Danijel Petkovic
commited on
Commit
•
4dcc177
1
Parent(s):
9ee93b6
Old files
Browse files
app.py
CHANGED
@@ -3,124 +3,35 @@ import streamlit as st
|
|
3 |
import requests
|
4 |
|
5 |
headers = {"Authorization": f"Bearer api_LbZppGQTIlpuKxWWbyNLvgPXLxXCbKYiMr"}
|
6 |
-
API_URL = "https://api-inference.huggingface.co/models/vblagoje/bart_eli5"
|
7 |
API_URL_TTS = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
8 |
|
9 |
-
|
10 |
-
def query_eli_model(payload):
|
11 |
-
data = json.dumps(payload)
|
12 |
-
response = requests.request("POST", API_URL, headers=headers, data=data)
|
13 |
-
return json.loads(response.content.decode("utf-8"))
|
14 |
-
|
15 |
def query_audio_tts(payload):
|
16 |
data = json.dumps(payload)
|
17 |
response = requests.request("POST", API_URL_TTS, headers=headers, data=data)
|
18 |
return response.content
|
19 |
|
20 |
-
st.
|
21 |
-
page_title="AI assistant",
|
22 |
-
initial_sidebar_state="expanded"
|
23 |
-
)
|
24 |
-
|
25 |
-
st.markdown("""
|
26 |
-
<style>
|
27 |
-
.row-widget.stTextInput > div:first-of-type {
|
28 |
-
background: #fff;
|
29 |
-
display: flex;
|
30 |
-
border: 1px solid #dfe1e5;
|
31 |
-
box-shadow: none;
|
32 |
-
border-radius: 24px;
|
33 |
-
height: 50px;
|
34 |
-
width: auto;
|
35 |
-
padding: 10px;
|
36 |
-
margin: 10px auto 30px;
|
37 |
-
}
|
38 |
-
.row-widget.stTextInput > div:first-of-type:hover,
|
39 |
-
.row-widget.stTextInput > div:first-of-type:focus {
|
40 |
-
box-shadow: 1px 1px 2px 1px rgba(0, 0, 0, 0.2);
|
41 |
-
}
|
42 |
-
.row-widget.stTextInput .st-bq {
|
43 |
-
background-color: #fff;
|
44 |
-
}
|
45 |
-
.row-widget.stButton > button {
|
46 |
-
border-radius: 24px;
|
47 |
-
background-color: #B6C9B1;
|
48 |
-
color: #fff;
|
49 |
-
border: none;
|
50 |
-
padding: 6px 20px;
|
51 |
-
float: right;
|
52 |
-
background-image: none;
|
53 |
-
}
|
54 |
-
.row-widget.stButton > button:hover {
|
55 |
-
box-shadow: 1px 1px 2px 1px rgba(0, 0, 0, 0.2);
|
56 |
-
}
|
57 |
-
.row-widget.stButton > button:focus {
|
58 |
-
border: none;
|
59 |
-
color: #fff;
|
60 |
-
}
|
61 |
-
</style> """, unsafe_allow_html=True)
|
62 |
-
|
63 |
-
st.title('AI Assistant')
|
64 |
|
65 |
question = st.text_input('Enter a question')
|
66 |
|
67 |
if question:
|
68 |
-
with st.spinner("Generating an
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
"
|
75 |
-
"
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
if data:
|
91 |
-
generated_answer = data[0]['generated_text']
|
92 |
-
|
93 |
-
st.markdown(
|
94 |
-
" ".join([
|
95 |
-
"<div style='margin-bottom: 50px;'>",
|
96 |
-
"<h2 class='font-title text-bold'>The answer:</h2>",
|
97 |
-
'<div style="padding: 30px;background-color: #B6C9B1; border-radius: 10px;">',
|
98 |
-
f'<p>{generated_answer}</p>',
|
99 |
-
"</div>",
|
100 |
-
"</div>"
|
101 |
-
]),
|
102 |
-
unsafe_allow_html=True
|
103 |
-
)
|
104 |
-
|
105 |
-
if generated_answer:
|
106 |
-
with st.spinner("Generating an audio..."):
|
107 |
-
audio_file = query_audio_tts({
|
108 |
-
"inputs": generated_answer,
|
109 |
-
"parameters": {
|
110 |
-
"vocoder_tag": "str_or_none(none)",
|
111 |
-
"threshold": 0.5,
|
112 |
-
"minlenratio": 0.0,
|
113 |
-
"maxlenratio": 10.0,
|
114 |
-
"use_att_constraint": False,
|
115 |
-
"backward_window": 1,
|
116 |
-
"forward_window": 3,
|
117 |
-
"speed_control_alpha": 1.0,
|
118 |
-
"noise_scale": 0.333,
|
119 |
-
"noise_scale_dur": 0.333
|
120 |
-
}
|
121 |
-
})
|
122 |
-
|
123 |
-
with open("out.flac", "wb") as f:
|
124 |
-
f.write(audio_file)
|
125 |
-
|
126 |
-
st.audio("out.flac")
|
|
|
3 |
import requests
|
4 |
|
5 |
headers = {"Authorization": f"Bearer api_LbZppGQTIlpuKxWWbyNLvgPXLxXCbKYiMr"}
|
|
|
6 |
API_URL_TTS = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def query_audio_tts(payload):
|
9 |
data = json.dumps(payload)
|
10 |
response = requests.request("POST", API_URL_TTS, headers=headers, data=data)
|
11 |
return response.content
|
12 |
|
13 |
+
st.title('TEST TTS INFERENCE API')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
question = st.text_input('Enter a question')
|
16 |
|
17 |
if question:
|
18 |
+
with st.spinner("Generating an audio..."):
|
19 |
+
audio_file = query_audio_tts({
|
20 |
+
"inputs": question,
|
21 |
+
"parameters": {
|
22 |
+
"vocoder_tag": "str_or_none(none)",
|
23 |
+
"threshold": 0.5,
|
24 |
+
"minlenratio": 0.0,
|
25 |
+
"maxlenratio": 10.0,
|
26 |
+
"use_att_constraint": False,
|
27 |
+
"backward_window": 1,
|
28 |
+
"forward_window": 3,
|
29 |
+
"speed_control_alpha": 1.0,
|
30 |
+
"noise_scale": 0.333,
|
31 |
+
"noise_scale_dur": 0.333
|
32 |
+
}
|
33 |
+
})
|
34 |
+
with open("out.flac", "wb") as f:
|
35 |
+
f.write(audio_file)
|
36 |
+
|
37 |
+
st.audio("out.flac")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out.flac
ADDED
Binary file (556 kB). View file
|
|