vishwask commited on
Commit
8d7fcf7
1 Parent(s): 6c6c1a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -26
app.py CHANGED
@@ -25,6 +25,7 @@ from langchain.vectorstores import FAISS
25
  import transformers
26
  from pydub import AudioSegment
27
  #from streamlit_extras.stateful_button import button
 
28
 
29
  user_session_id = uuid.uuid4()
30
 
@@ -174,40 +175,49 @@ if prompt := st.chat_input("How can I help you today?"):
174
  pdf_document.close()
175
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
176
  #image = Image.open('/home/user/app/pdf2image/output.png')
 
177
  #message_placeholder.image(image)
178
  #st.session_state.reference = True
179
-
180
-
181
-
182
  def generate_audio():
183
  with open('/home/user/app/audio/audio.mp3','wb') as sound_file:
184
  tts = gTTS(result['result'], lang='en', tld='co.in')
185
  tts.write_to_fp(sound_file)
186
  sound = AudioSegment.from_mp3("/home/user/app/audio/audio.mp3")
187
  sound.export("/home/user/app/audio/audio.wav", format="wav")
188
-
189
- if "reference" not in st.session_state:
190
- st.session_state.reference = '/home/user/app/pdf2image/default_output.png'
191
- if "audio" not in st.session_state:
192
- st.session_state.audio = "/home/user/app/audio/beep-06.mp3"
193
-
194
-
195
- with st.sidebar:
196
- choice = st.radio("References and TTS",["Reference" , 'TTS'], index=None,)
197
-
198
- if choice == 'Reference':
199
- generate_pdf()
200
- st.session_state['reference'] = '/home/user/app/pdf2image/output.png'
201
- st.image(st.session_state['reference'])
202
-
203
- if choice == 'TTS':
204
- with open('/home/user/app/audio/audio.mp3','wb') as sound_file:
205
- tts = gTTS(result['result'], lang='en', tld = 'co.in')
206
- tts.write_to_fp(sound_file)
207
- sound = AudioSegment.from_mp3("/home/user/app/audio/audio.mp3")
208
- sound.export("/home/user/app/audio/audio.wav", format="wav")
209
- st.session_state['audio'] = '/home/user/app/audio/audio.wav'
210
- st.audio(st.session_state['audio'])
 
 
 
 
 
 
 
 
 
211
 
212
  st.session_state.messages.append({"role": "assistant", "content": full_response})
213
 
 
25
  import transformers
26
  from pydub import AudioSegment
27
  #from streamlit_extras.stateful_button import button
28
+ from streamlit_card import card
29
 
30
  user_session_id = uuid.uuid4()
31
 
 
175
  pdf_document.close()
176
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
177
  #image = Image.open('/home/user/app/pdf2image/output.png')
178
+ st.image('/home/user/app/pdf2image/output.png')
179
  #message_placeholder.image(image)
180
  #st.session_state.reference = True
181
+
182
+
 
183
  def generate_audio():
184
  with open('/home/user/app/audio/audio.mp3','wb') as sound_file:
185
  tts = gTTS(result['result'], lang='en', tld='co.in')
186
  tts.write_to_fp(sound_file)
187
  sound = AudioSegment.from_mp3("/home/user/app/audio/audio.mp3")
188
  sound.export("/home/user/app/audio/audio.wav", format="wav")
189
+ st.audio("/home/user/app/audio/audio.wav")
190
+
191
+ card(title="Reference",
192
+ url=None,
193
+ on_click=generate_pdf)
194
+
195
+ card(title='Audio',
196
+ url = None,
197
+ on_click = generate_audio)
198
+
199
+ # if "reference" not in st.session_state:
200
+ # st.session_state.reference = '/home/user/app/pdf2image/default_output.png'
201
+ # if "audio" not in st.session_state:
202
+ # st.session_state.audio = "/home/user/app/audio/beep-06.mp3"
203
+
204
+
205
+ # with st.sidebar:
206
+ # choice = st.radio("References and TTS",["Reference" , 'TTS'], index=None,)
207
+
208
+ # if choice == 'Reference':
209
+ # generate_pdf()
210
+ # st.session_state['reference'] = '/home/user/app/pdf2image/output.png'
211
+ # st.image(st.session_state['reference'])
212
+
213
+ # if choice == 'TTS':
214
+ # with open('/home/user/app/audio/audio.mp3','wb') as sound_file:
215
+ # tts = gTTS(result['result'], lang='en', tld = 'co.in')
216
+ # tts.write_to_fp(sound_file)
217
+ # sound = AudioSegment.from_mp3("/home/user/app/audio/audio.mp3")
218
+ # sound.export("/home/user/app/audio/audio.wav", format="wav")
219
+ # st.session_state['audio'] = '/home/user/app/audio/audio.wav'
220
+ # st.audio(st.session_state['audio'])
221
 
222
  st.session_state.messages.append({"role": "assistant", "content": full_response})
223