Spaces:
Running
Running
fixed: state
Browse files
app.py
CHANGED
@@ -122,9 +122,10 @@ def generate_rhythm(query, state):
|
|
122 |
return [(SR, audio_data), text_output]
|
123 |
# %%
|
124 |
|
125 |
-
def on_token_change(user_token):
|
126 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
127 |
state["user_token"] = user_token
|
|
|
128 |
|
129 |
with gr.Blocks() as demo:
|
130 |
state = gr.State({"gen_count": 0, "user_token":""})
|
@@ -141,5 +142,5 @@ with gr.Blocks() as demo:
|
|
141 |
gr.Markdown("Enter your own OpenAI API Key to try out more than 5 times. You can get it [here](https://platform.openai.com/account/api-keys).", elem_id="label")
|
142 |
user_token = gr.Textbox(placeholder="OpenAI API Key", type="password", show_label=False)
|
143 |
btn.click(fn=generate_rhythm, inputs=[inp, state], outputs=[out_audio, out_text])
|
144 |
-
user_token.change(on_token_change, inputs=[user_token], outputs=[])
|
145 |
demo.launch()
|
|
|
122 |
return [(SR, audio_data), text_output]
|
123 |
# %%
|
124 |
|
125 |
+
def on_token_change(user_token, state):
|
126 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
127 |
state["user_token"] = user_token
|
128 |
+
return state
|
129 |
|
130 |
with gr.Blocks() as demo:
|
131 |
state = gr.State({"gen_count": 0, "user_token":""})
|
|
|
142 |
gr.Markdown("Enter your own OpenAI API Key to try out more than 5 times. You can get it [here](https://platform.openai.com/account/api-keys).", elem_id="label")
|
143 |
user_token = gr.Textbox(placeholder="OpenAI API Key", type="password", show_label=False)
|
144 |
btn.click(fn=generate_rhythm, inputs=[inp, state], outputs=[out_audio, out_text])
|
145 |
+
user_token.change(on_token_change, inputs=[user_token, state], outputs=[state])
|
146 |
demo.launch()
|