Singularity / app.py
wasertech's picture
open ai
79ca40a
raw
history blame
3.11 kB
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="Settings"):
with gr.Row():
with gr.Column(scale=1):
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("""
# Welcome
## 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
)
gr.Markdown("""
## OpenAI API
To query OpenAI models, you need an OpenAI API key.
You can manage your access tokens in your account settings.
[Manage API keys](https://platform.openai.com/account/api-keys)
Please enter your API token below and click on Setup.
""")
api_openai_token = gr.Textbox(
label="OpenAI API Key",
type="password",
interactive=True
)
setup_button = gr.Button("Setup")
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)
setup_button.click(
dot.setup,
inputs=[api_hub_token, api_openai_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()