awacke1's picture
Update mycomponent/__init__.py
be921cd verified
raw
history blame
1.1 kB
import os
import streamlit.components.v1 as components
# Declare the component with a path to index.html
mycomponent = components.declare_component(
"mycomponent",
path=os.path.dirname(os.path.abspath(__file__))
)
# Python function to interact with the component
def speech_component(default_value=""):
"""
A custom Streamlit component for continuous speech recognition.
Args:
default_value (str): Initial value to display in the input field.
Returns:
dict: The latest transcript data from the component.
"""
# Pass the default value to the component and receive data back
component_value = mycomponent(my_input_value=default_value, key="speech_component")
# If no value is returned yet, return an empty dict
if component_value is None:
return {"value": ""}
# Return the component value (expecting a dict with 'value' key)
return component_value
if __name__ == "__main__":
# Test the component standalone
value = speech_component("Say something...")
st.write("Received from component:", value)