Spaces:
Runtime error
Runtime error
bol20162021
commited on
requirements for api key
Browse files
app.py
CHANGED
@@ -113,6 +113,17 @@ def stream_conversation(character1, character2, initial_message, num_turns, api_
|
|
113 |
|
114 |
asyncio.run(run_simulation())
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
def chat_interface(character1_dropdown, character1_custom, character2_dropdown, character2_custom,
|
117 |
initial_message, num_turns, api_key):
|
118 |
|
@@ -242,6 +253,7 @@ with gr.Blocks() as app:
|
|
242 |
|
243 |
gr.Markdown("Powerd by [LLama3.1-405B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct) on [SambaNova Cloud](https://cloud.sambanova.ai/apis)")
|
244 |
api_key = gr.Textbox(label="Enter your Sambanova Cloud API Key\n(To get one, go to https://cloud.sambanova.ai/apis)", type="password")
|
|
|
245 |
|
246 |
with gr.Column():
|
247 |
character1_dropdown = gr.Dropdown(choices=predefined_characters + ["Custom"], label="Select Character 1")
|
@@ -262,6 +274,7 @@ with gr.Blocks() as app:
|
|
262 |
|
263 |
character1_dropdown.change(show_custom_input, inputs=character1_dropdown, outputs=character1_custom)
|
264 |
character2_dropdown.change(show_custom_input, inputs=character2_dropdown, outputs=character2_custom)
|
|
|
265 |
|
266 |
generate_btn.click(
|
267 |
chat_interface,
|
@@ -286,5 +299,10 @@ with gr.Blocks() as app:
|
|
286 |
outputs=download_output
|
287 |
)
|
288 |
|
|
|
|
|
|
|
|
|
|
|
289 |
if __name__ == "__main__":
|
290 |
app.launch()
|
|
|
113 |
|
114 |
asyncio.run(run_simulation())
|
115 |
|
116 |
+
def validate_api_key(api_key):
|
117 |
+
if not api_key.strip():
|
118 |
+
return False, "API key is required. Please enter a valid API key."
|
119 |
+
return True, ""
|
120 |
+
|
121 |
+
def update_api_key_status(api_key):
|
122 |
+
is_valid, message = validate_api_key(api_key)
|
123 |
+
if not is_valid:
|
124 |
+
return f"<p style='color: red;'>{message}</p>"
|
125 |
+
return ""
|
126 |
+
|
127 |
def chat_interface(character1_dropdown, character1_custom, character2_dropdown, character2_custom,
|
128 |
initial_message, num_turns, api_key):
|
129 |
|
|
|
253 |
|
254 |
gr.Markdown("Powerd by [LLama3.1-405B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct) on [SambaNova Cloud](https://cloud.sambanova.ai/apis)")
|
255 |
api_key = gr.Textbox(label="Enter your Sambanova Cloud API Key\n(To get one, go to https://cloud.sambanova.ai/apis)", type="password")
|
256 |
+
api_key_status = gr.Markdown()
|
257 |
|
258 |
with gr.Column():
|
259 |
character1_dropdown = gr.Dropdown(choices=predefined_characters + ["Custom"], label="Select Character 1")
|
|
|
274 |
|
275 |
character1_dropdown.change(show_custom_input, inputs=character1_dropdown, outputs=character1_custom)
|
276 |
character2_dropdown.change(show_custom_input, inputs=character2_dropdown, outputs=character2_custom)
|
277 |
+
api_key.change(update_api_key_status, inputs=[api_key], outputs=[api_key_status])
|
278 |
|
279 |
generate_btn.click(
|
280 |
chat_interface,
|
|
|
299 |
outputs=download_output
|
300 |
)
|
301 |
|
302 |
+
app.load(lambda: update_api_key_status(""), outputs=[api_key_status])
|
303 |
+
|
304 |
+
|
305 |
+
|
306 |
+
|
307 |
if __name__ == "__main__":
|
308 |
app.launch()
|