ImPolymath commited on
Commit
4bdc2be
·
1 Parent(s): 8287cd7

add files upload feature

Browse files
Files changed (2) hide show
  1. pages/main.py +19 -10
  2. var_app.py +3 -2
pages/main.py CHANGED
@@ -365,16 +365,25 @@ def main_page():
365
  )
366
 
367
  # Interface utilisateur pour l'upload de fichiers
368
- #st.session_state.uploaded_files = st.file_uploader(
369
- # "Choose files to upload",
370
- # accept_multiple_files=True,
371
- # type=CHAT_FILES_UPLOAD_ALLOWED_TYPES,
372
- # key="chat_files_upload"
373
- #)
374
- #for uploaded_file in st.session_state.uploaded_files:
375
- # bytes_data = uploaded_file.read()
376
- # st.write("filename:", uploaded_file.name)
377
- # st.write(bytes_data)
 
 
 
 
 
 
 
 
 
378
 
379
  # Interface utilisateur pour l'enregistrement audio
380
  st.experimental_audio_input("Record a voice message",on_change=recorder_released, key="rec_widget")
 
365
  )
366
 
367
  # Interface utilisateur pour l'upload de fichiers
368
+ st.session_state.uploaded_files = st.file_uploader(
369
+ "Choose files to upload",
370
+ accept_multiple_files=True,
371
+ type=CHAT_FILES_UPLOAD_ALLOWED_TYPES,
372
+ key="chat_files_upload"
373
+ )
374
+ for uploaded_file in st.session_state.uploaded_files:
375
+ with st.container(border=True):
376
+ bytes_data = uploaded_file.read()
377
+ filetype = os.path.splitext(uploaded_file.name)[1].lstrip('.')
378
+ st.write("**filename:**", uploaded_file.name)
379
+ st.write("**filetype:**", filetype)
380
+ if filetype in ["txt"]:
381
+ with st.expander("View file content"):
382
+ st.write(bytes_data.decode())
383
+ elif filetype in ["wav", "mp3"]:
384
+ audio = AudioSegment.from_file(io.BytesIO(bytes_data))
385
+ st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
386
+ st.audio(bytes_data, format=f"audio/{filetype}", autoplay=False)
387
 
388
  # Interface utilisateur pour l'enregistrement audio
389
  st.experimental_audio_input("Record a voice message",on_change=recorder_released, key="rec_widget")
var_app.py CHANGED
@@ -1,9 +1,10 @@
1
- __version__ = "1.3.2"
2
 
3
  from core.files import read_file
4
 
5
  CHAT_FILES_UPLOAD_ALLOWED_TYPES = [
6
- "txt"
 
7
  ]
8
 
9
  # List of languages supported by the application
 
1
+ __version__ = "1.3.3"
2
 
3
  from core.files import read_file
4
 
5
  CHAT_FILES_UPLOAD_ALLOWED_TYPES = [
6
+ "txt",
7
+ "wav", "mp3"
8
  ]
9
 
10
  # List of languages supported by the application