Shabbir-Anjum commited on
Commit
6094769
1 Parent(s): 2a3eb19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -1,36 +1,24 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
- import requests
4
 
5
- # Initialize the tokenizer and model
6
- tokenizer = AutoTokenizer.from_pretrained("PawanKrd/CosmosRP-8k")
7
- model = AutoModelForCausalLM.from_pretrained("PawanKrd/CosmosRP-8k")
8
 
9
- st.title("CosmosRP-8k Roleplay Chatbot")
 
 
 
 
 
10
 
11
- user_input = st.text_input("You:", "")
12
 
13
- if st.button("Generate Response"):
14
- if user_input:
15
- # Define the endpoint and payload
16
- endpoint_url = "https://api.pawan.krd/cosmosrp/v1/chat/completions"
17
- headers = {
18
- "Content-Type": "application/json"
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.")