SaileshSivan commited on
Commit
dd49b59
·
1 Parent(s): c2d5266

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import time
3
  from langchain.schema import HumanMessage, SystemMessage, AIMessage
4
  from langchain.chat_models import ChatOpenAI
 
 
5
 
6
 
7
  def get_chatmodel_response(question):
@@ -81,6 +83,19 @@ if submit:
81
  st.header("Sisi", divider=True)
82
  response = get_chatmodel_response(input_question)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  if response is not None:
85
 
86
  st.write(response)
 
2
  import time
3
  from langchain.schema import HumanMessage, SystemMessage, AIMessage
4
  from langchain.chat_models import ChatOpenAI
5
+ import base64
6
+ from pathlib import Path
7
 
8
 
9
  def get_chatmodel_response(question):
 
83
  st.header("Sisi", divider=True)
84
  response = get_chatmodel_response(input_question)
85
 
86
+ # Generate speech using OpenAI API
87
+ response_audio = openai.audio.speech.create(
88
+ model="tts-1",
89
+ voice="alloy",
90
+ input=response_text
91
+ )
92
+ # Display audio on the webpage
93
+ st.audio(response_audio['url'], format='audio/mp3')
94
+
95
+ # Add a download button for the audio
96
+ audio_data = base64.b64decode(response_audio['url'].split(',')[1])
97
+ st.markdown(f"### [Download Audio](data:audio/mp3;base64,{base64.b64encode(audio_data).decode()})", unsafe_allow_html=True)
98
+
99
  if response is not None:
100
 
101
  st.write(response)