How to take Text Input from a user

Hi @thiago and Developers’ Team of Streamlit,

I just came across your amazing tool and was looking forward to build a small ASR app with huggingface transformers model. What I need is to enter the path to the mp3 or wav file on the local drive and use it afterwards. However, st.text_input doesn’t seem to work, the model reads only the first character and says the file doesn’t exist.

Here’s my code I need to implement:

from asrecognition import ASREngine
import streamlit as st

st.header("Trascribe your Audio")

filePath = st.text_input(label = "Please enter the path to the file" )

asr = ASREngine("ru", model_path="jonatasgrosman/wav2vec2-large-xlsr-53-russian")

transcriptions = asr.transcribe(filePath)

st.write(result.get("transcription"))

Here’s the error I get:

Can you try passing a constant filepath to asr.transcribe()?

Try this:

transcriptions = asr.transcribe('\3.wav')

And then this:

transcriptions = asr.transcribe('\\3.wav')

If the first one fails and the second one works, then the problem is that Python is interpreting the \ as an escape character. So one solution would be to duplicate all \ in your string:

filePath = st.text_input(label = "Please enter the path to the file" )

filePath = filePath.replace('\\', '\\\\')

If both fail, this feels like a bug in asr.transcribe

@thiago, thank you so much for getting back to me, I tried so many ways around this problem, tried to input different paths, but the error came back with the first character only, e.g. ‘[’ or ‘C’ or ‘"’, saying this file does not exist, so I suppose you are right here saying there might be a bug with asrecognition (available at pypi) although it works fine in my pycharm with the following code:

from asrecognition import ASREngine

asr = ASREngine("ru", model_path="jonatasgrosman/wav2vec2-large-xlsr-53-russian")

audio_paths = ["C:/Users/CNata/PycharmProjects/TestASR/3.wav"]
transcriptions = asr.transcribe(audio_paths)
print(transcriptions)

I would appreciate it immensely you looking into it closer. Can it be the case that streamlit separates characters one by one or is it the model after all?

@thiago I apologize for disturbing you, I couldn’t believe the model would refuse to read the path. I used a different approach without a shortcut with asrecognition library and it worked. Thank you for doing such a great job. I really fell in love with your tool. Streamlit is amazing. Keep it up! :hugs:

2 Likes

Glad you figured it out!

2 Likes

How can I have the text box disappear once the user has entered their input?

Hi @Jacob_Schaumann ,

Welcome to the Streamlit Community Forum :balloon:
Try using st.empty() syntax.

import streamlit as st
_emp = st.empty()
text = _emp.text_input("Enter Something here! ")
if text:
    _emp.empty()

Best,
Avra

Hi @thiago,

Is there any way that I could save the text into a text file?
I am getting several text lines from a user using st.text_area(), and I need to save theem into a text file.

Thanks

1 Like