Spaces:
Running
Running
fixed: user token
Browse files
app.py
CHANGED
@@ -96,7 +96,7 @@ def get_answer(question):
|
|
96 |
return response["choices"][0]["message"]["content"]
|
97 |
|
98 |
def generate_rhythm(query, state):
|
99 |
-
if state["gen_count"] > MAX_QUERY:
|
100 |
return [None, "You need to set your ChatGPT API Key to try more than %d times" % MAX_QUERY]
|
101 |
state["gen_count"] = state["gen_count"] + 1
|
102 |
|
@@ -123,10 +123,10 @@ def generate_rhythm(query, state):
|
|
123 |
|
124 |
def on_token_change(user_token):
|
125 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
126 |
-
|
127 |
|
128 |
with gr.Blocks() as demo:
|
129 |
-
state = gr.State({"gen_count": 0})
|
130 |
|
131 |
gr.Markdown("Ask ChatGPT to generate rhythm patterns")
|
132 |
with gr.Row():
|
@@ -136,17 +136,9 @@ with gr.Blocks() as demo:
|
|
136 |
with gr.Column():
|
137 |
out_audio = gr.Audio()
|
138 |
out_text = gr.Textbox(placeholder="ChatGPT output")
|
139 |
-
gr.
|
140 |
-
|
|
|
141 |
btn.click(fn=generate_rhythm, inputs=[inp, state], outputs=[out_audio, out_text])
|
142 |
user_token.change(on_token_change, inputs=[user_token], outputs=[])
|
143 |
demo.launch()
|
144 |
-
# demo = gr.Interface(
|
145 |
-
# fn=generate_rhythm,
|
146 |
-
# inputs=gr.Textbox(label="command",show_label=True, placeholder="Give me a dope beat!", visible=True).style(container=False),
|
147 |
-
# outputs=["audio", "text"]
|
148 |
-
# )
|
149 |
-
# demo.launch()
|
150 |
-
# %%
|
151 |
-
|
152 |
-
# %%
|
|
|
96 |
return response["choices"][0]["message"]["content"]
|
97 |
|
98 |
def generate_rhythm(query, state):
|
99 |
+
if state["gen_count"] > MAX_QUERY or len(state["user_token"]) > 0:
|
100 |
return [None, "You need to set your ChatGPT API Key to try more than %d times" % MAX_QUERY]
|
101 |
state["gen_count"] = state["gen_count"] + 1
|
102 |
|
|
|
123 |
|
124 |
def on_token_change(user_token):
|
125 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
126 |
+
state["user_token"] = user_token
|
127 |
|
128 |
with gr.Blocks() as demo:
|
129 |
+
state = gr.State({"gen_count": 0, "user_token":""})
|
130 |
|
131 |
gr.Markdown("Ask ChatGPT to generate rhythm patterns")
|
132 |
with gr.Row():
|
|
|
136 |
with gr.Column():
|
137 |
out_audio = gr.Audio()
|
138 |
out_text = gr.Textbox(placeholder="ChatGPT output")
|
139 |
+
with gr.Column():
|
140 |
+
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")
|
141 |
+
user_token = gr.Textbox(placeholder="OpenAI API Key", type="password", show_label=False)
|
142 |
btn.click(fn=generate_rhythm, inputs=[inp, state], outputs=[out_audio, out_text])
|
143 |
user_token.change(on_token_change, inputs=[user_token], outputs=[])
|
144 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|