Spaces:
Runtime error
Runtime error
sc_ma
commited on
Commit
·
09305ff
1
Parent(s):
c257198
bug fix.
Browse files
app.py
CHANGED
|
@@ -6,13 +6,13 @@ openai_key = os.getenv("OPENAI_API_KEY")
|
|
| 6 |
access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
|
| 7 |
secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
|
| 8 |
if access_key_id is None or secret_access_key is None:
|
| 9 |
-
print("Access keys are not provided. Outputs cannot be saved to AWS Cloud Storage
|
| 10 |
IS_CACHE_AVAILABLE = False
|
| 11 |
else:
|
| 12 |
IS_CACHE_AVAILABLE = True
|
| 13 |
|
| 14 |
if openai_key is None:
|
| 15 |
-
print("OPENAI_API_KEY is not found in environment variables. The output may not be generated
|
| 16 |
IS_OPENAI_API_KEY_AVAILABLE = False
|
| 17 |
else:
|
| 18 |
# todo: check if this key is available or not
|
|
@@ -25,7 +25,7 @@ def clear_inputs(text1, text2):
|
|
| 25 |
|
| 26 |
|
| 27 |
def wrapped_generate_backgrounds(title, description, openai_key = None, cache_mode = True):
|
| 28 |
-
# if `cache_mode` is True, then follow the following
|
| 29 |
# check if "title"+"description" have been generated before
|
| 30 |
# if so, download from the cloud storage, return it
|
| 31 |
# if not, generate the result.
|
|
@@ -67,7 +67,8 @@ with gr.Blocks() as demo:
|
|
| 67 |
''')
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
-
key = gr.Textbox(value=openai_key, lines=1, max_lines=1, label="OpenAI Key", visible=not IS_OPENAI_API_KEY_AVAILABLE)
|
|
|
|
| 71 |
title = gr.Textbox(value="Deep Reinforcement Learning", lines=1, max_lines=1, label="Title")
|
| 72 |
description = gr.Textbox(lines=5, label="Description (Optional)")
|
| 73 |
|
|
@@ -75,16 +76,14 @@ with gr.Blocks() as demo:
|
|
| 75 |
clear_button = gr.Button("Clear")
|
| 76 |
submit_button = gr.Button("Submit")
|
| 77 |
with gr.Column():
|
| 78 |
-
style_mapping = {True: "color:white;background-color:green", False: "color:white;background-color:red"}
|
| 79 |
availablity_mapping = {True: "AVAILABLE", False: "NOT AVAILABLE"}
|
| 80 |
gr.Markdown(f'''## Huggingface Space Status
|
| 81 |
当`OpenAI API`显示AVAILABLE的时候这个Space可以直接使用.
|
| 82 |
-
当`OpenAI API`显示UNAVAILABLE的时候这个Space可以通过在左侧输入OPENAI KEY
|
| 83 |
`OpenAI API`: <span style="{style_mapping[IS_OPENAI_API_KEY_AVAILABLE]}">{availablity_mapping[IS_OPENAI_API_KEY_AVAILABLE]}</span>. `Cache`: <span style="{style_mapping[IS_CACHE_AVAILABLE]}">{availablity_mapping[IS_CACHE_AVAILABLE]}</span>.''')
|
| 84 |
file_output = gr.File(label="Output")
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
clear_button.click(fn=clear_inputs, inputs=[title, description], outputs=[title, description])
|
| 89 |
submit_button.click(fn=wrapped_generate_backgrounds, inputs=[title, description, key], outputs=file_output)
|
| 90 |
|
|
|
|
| 6 |
access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
|
| 7 |
secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
|
| 8 |
if access_key_id is None or secret_access_key is None:
|
| 9 |
+
print("Access keys are not provided. Outputs cannot be saved to AWS Cloud Storage.\n")
|
| 10 |
IS_CACHE_AVAILABLE = False
|
| 11 |
else:
|
| 12 |
IS_CACHE_AVAILABLE = True
|
| 13 |
|
| 14 |
if openai_key is None:
|
| 15 |
+
print("OPENAI_API_KEY is not found in environment variables. The output may not be generated.\n")
|
| 16 |
IS_OPENAI_API_KEY_AVAILABLE = False
|
| 17 |
else:
|
| 18 |
# todo: check if this key is available or not
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
def wrapped_generate_backgrounds(title, description, openai_key = None, cache_mode = True):
|
| 28 |
+
# if `cache_mode` is True, then follow the following steps:
|
| 29 |
# check if "title"+"description" have been generated before
|
| 30 |
# if so, download from the cloud storage, return it
|
| 31 |
# if not, generate the result.
|
|
|
|
| 67 |
''')
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
+
# key = gr.Textbox(value=openai_key, lines=1, max_lines=1, label="OpenAI Key", visible=not IS_OPENAI_API_KEY_AVAILABLE)
|
| 71 |
+
key = gr.Textbox(value=openai_key, lines=1, max_lines=1, label="OpenAI Key", visible=False)
|
| 72 |
title = gr.Textbox(value="Deep Reinforcement Learning", lines=1, max_lines=1, label="Title")
|
| 73 |
description = gr.Textbox(lines=5, label="Description (Optional)")
|
| 74 |
|
|
|
|
| 76 |
clear_button = gr.Button("Clear")
|
| 77 |
submit_button = gr.Button("Submit")
|
| 78 |
with gr.Column():
|
| 79 |
+
style_mapping = {True: "color:white;background-color:green", False: "color:white;background-color:red"} #todo: to match website's style
|
| 80 |
availablity_mapping = {True: "AVAILABLE", False: "NOT AVAILABLE"}
|
| 81 |
gr.Markdown(f'''## Huggingface Space Status
|
| 82 |
当`OpenAI API`显示AVAILABLE的时候这个Space可以直接使用.
|
| 83 |
+
当`OpenAI API`显示UNAVAILABLE的时候这个Space可以通过在左侧输入OPENAI KEY来使用 (暂时不支持).
|
| 84 |
`OpenAI API`: <span style="{style_mapping[IS_OPENAI_API_KEY_AVAILABLE]}">{availablity_mapping[IS_OPENAI_API_KEY_AVAILABLE]}</span>. `Cache`: <span style="{style_mapping[IS_CACHE_AVAILABLE]}">{availablity_mapping[IS_CACHE_AVAILABLE]}</span>.''')
|
| 85 |
file_output = gr.File(label="Output")
|
| 86 |
|
|
|
|
|
|
|
| 87 |
clear_button.click(fn=clear_inputs, inputs=[title, description], outputs=[title, description])
|
| 88 |
submit_button.click(fn=wrapped_generate_backgrounds, inputs=[title, description, key], outputs=file_output)
|
| 89 |
|