Spaces:
Running
Running
Shabbir-Anjum
commited on
Commit
•
6094769
1
Parent(s):
2a3eb19
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
-
import requests
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained("PawanKrd/CosmosRP-8k")
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
data = {
|
21 |
-
"model": "cosmosrp",
|
22 |
-
"messages": [
|
23 |
-
{"role": "system", "content": "You are a roleplay assistant."},
|
24 |
-
{"role": "user", "content": user_input}
|
25 |
-
]
|
26 |
-
}
|
27 |
-
|
28 |
-
# Make the request to the API
|
29 |
-
response = requests.post(endpoint_url, headers=headers, json=data)
|
30 |
-
result = response.json()
|
31 |
-
|
32 |
-
# Extract and display the response
|
33 |
-
generated_response = result['choices'][0]['message']['content']
|
34 |
-
st.text_area("CosmosRP-8k:", generated_response)
|
35 |
else:
|
36 |
st.warning("Please enter some text.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Set up the text-to-speech pipeline
|
5 |
+
pipe = pipeline('text-to-speech', model='Xenova/speecht5_tts')
|
|
|
6 |
|
7 |
+
def text_to_speech(text):
|
8 |
+
result = pipe(text)
|
9 |
+
audio_path = 'output.wav'
|
10 |
+
with open(audio_path, 'wb') as f:
|
11 |
+
f.write(result['audio'])
|
12 |
+
return audio_path
|
13 |
|
14 |
+
st.title("Text to Speech with Hugging Face Model")
|
15 |
|
16 |
+
text = st.text_area("Enter text to convert to speech:")
|
17 |
+
|
18 |
+
if st.button("Convert"):
|
19 |
+
if text:
|
20 |
+
audio_file = text_to_speech(text)
|
21 |
+
audio_bytes = open(audio_file, 'rb').read()
|
22 |
+
st.audio(audio_bytes, format='audio/wav')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
else:
|
24 |
st.warning("Please enter some text.")
|