Spaces:
Runtime error
Runtime error
Danijel Petkovic
commited on
Commit
•
3beb0e3
1
Parent(s):
7e4b7b1
Try
Browse files
app.py
CHANGED
@@ -3,19 +3,104 @@ import streamlit as st
|
|
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 |
|
14 |
-
st.title('
|
15 |
|
16 |
question = st.text_input('Enter a question')
|
17 |
|
18 |
if question:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
with st.spinner("Generating an audio..."):
|
21 |
audio_file = query_audio_tts({
|
|
|
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.set_page_config(
|
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 answer..."):
|
69 |
+
|
70 |
+
model_input = f'question: {question}'
|
71 |
+
|
72 |
+
if model_input:
|
73 |
+
data = query_eli_model({
|
74 |
+
"inputs": model_input,
|
75 |
+
"parameters": {
|
76 |
+
"min_length": 30,
|
77 |
+
"max_length": 200,
|
78 |
+
"do_sample": False,
|
79 |
+
"early_stopping": True,
|
80 |
+
"num_beams": 8,
|
81 |
+
"temperature": 1.0,
|
82 |
+
"top_k": None,
|
83 |
+
"top_p": None,
|
84 |
+
"no_repeat_ngram_size": 3,
|
85 |
+
"num_return_sequences": 1
|
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 |
with st.spinner("Generating an audio..."):
|
106 |
audio_file = query_audio_tts({
|