import gradio as gr from singularity import Singularity dot = Singularity() intro = """ # Singularity I always were here. You just couldn't see me. """ with gr.Blocks() as demo: gr.Markdown(intro) with gr.Row(): with gr.TabItem(label="Conversation"): with gr.Row(): with gr.Column(scale=1): with gr.Row(): audio_input = gr.Audio( source="microphone", label="Record from microphone", ) audio_button = gr.Button("Transcribe") audio_output = gr.Textbox() chat_button = gr.Button("Reply") with gr.Column(scale=1): chatbox = gr.Chatbot([]).style(height=750) with gr.TabItem(label="Settings"): with gr.Row(): with gr.Column(scale=1): with gr.Row(): with gr.Column(scale=1): gr.Markdown(""" # Singularity Settings ## HuggingFace API To query models, you need at least an API token with read permissions. You can manage your access tokens in your account settings. [Manage Access Tokens](https://huggingface.co/settings/tokens) Please enter your API token below and click on Setup. """) api_hub_token = gr.Textbox( label="API Hub Token", type="password", interactive=True ) setup_button = gr.Button("Setup") setup_button.click( dot.setup, inputs=[api_hub_token], outputs=[], ) audio_button.click( dot.transcribe, inputs=[audio_input], outputs=[audio_output], api_name="transcribe", ) chat_button.click( dot.answer_by_chat, inputs=[chatbox, audio_output], outputs=[chatbox], ) demo.launch()