Spaces:
Sleeping
Sleeping
acecalisto3
commited on
Commit
•
dc615f4
1
Parent(s):
a5957ee
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,9 @@ def get_ai_name():
|
|
32 |
def get_ai_role():
|
33 |
return gr.Textbox(label="AI Role", placeholder="e.g. an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.")
|
34 |
|
|
|
|
|
|
|
35 |
def get_top_5_goals():
|
36 |
return gr.Dataframe(row_count=(5, "fixed"), col_count=(1, "fixed"), headers=["AI Goals - Enter up to 5"], type="array")
|
37 |
|
@@ -44,7 +47,7 @@ def get_example_values():
|
|
44 |
return []
|
45 |
|
46 |
def get_chatbot():
|
47 |
-
return gr.Chatbot(elem_id="chatbot", type='messages')
|
48 |
|
49 |
def get_yes_btn():
|
50 |
return gr.Button("Yes", variant="primary", interactive=False)
|
@@ -56,124 +59,60 @@ def get_custom_response():
|
|
56 |
return gr.Textbox(label="Custom Response", placeholder="Press 'Enter' to Submit.", interactive=False)
|
57 |
|
58 |
def get_progress():
|
59 |
-
return gr.Progress()
|
60 |
|
61 |
def get_generated_files():
|
62 |
return gr.HTML(lambda: f"Generated Files<pre><code style='overflow-x: auto'>{utils.format_directory(OUTPUT_DIR)}</pre></code>", every=3, elem_id="files")
|
63 |
-
|
64 |
def get_download_btn():
|
65 |
-
return gr.Button("Download All Files")
|
66 |
|
67 |
-
def
|
|
|
|
|
|
|
68 |
try:
|
69 |
from api import AutoAPI
|
70 |
auto_api = AutoAPI(huggingface_key, ai_name, ai_role, top_5_goals)
|
71 |
logger.info("AutoAPI started with AI Name: %s, AI Role: %s", ai_name, ai_role)
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
73 |
except Exception as e:
|
74 |
logger.error("Failed to start AutoAPI: %s", str(e))
|
75 |
-
return gr.Column.update(visible=True), gr.Column.update(visible=False), None
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
chat[-1][1] = "\n".join(messages)
|
84 |
-
yield chat
|
85 |
-
|
86 |
-
def send_message(count, chat, api, message="Y"):
|
87 |
-
if message != "Y":
|
88 |
-
count = 1
|
89 |
-
for i in range(count):
|
90 |
-
chat.append([message, None])
|
91 |
-
yield chat, count - i
|
92 |
-
api.send_message(message)
|
93 |
-
for updated_chat in bot_response(chat, api):
|
94 |
-
yield updated_chat, count - i
|
95 |
-
|
96 |
-
def activate_inputs():
|
97 |
-
return {
|
98 |
-
get_yes_btn(): gr.Button.update(interactive=True),
|
99 |
-
get_consecutive_yes(): gr.Slider.update(interactive=True),
|
100 |
-
get_custom_response(): gr.Textbox.update(interactive=True),
|
101 |
-
}
|
102 |
-
|
103 |
-
def deactivate_inputs():
|
104 |
-
return {
|
105 |
-
get_yes_btn(): gr.Button.update(interactive=False),
|
106 |
-
get_consecutive_yes(): gr.Slider.update(interactive=False),
|
107 |
-
get_custom_response(): gr.Textbox.update(interactive=False),
|
108 |
-
}
|
109 |
-
|
110 |
-
def download_all_files():
|
111 |
-
try:
|
112 |
-
shutil.make_archive("outputs", "zip", OUTPUT_DIR)
|
113 |
-
logger.info("All files downloaded successfully.")
|
114 |
-
except Exception as e:
|
115 |
-
logger.error("Failed to download files: %s", str(e))
|
116 |
-
|
117 |
-
with gr.Blocks(css=CSS) as app:
|
118 |
-
with gr.Column() as setup_pane:
|
119 |
-
gr.Markdown(f"""# Auto-GPT
|
120 |
-
1. Duplicate this Space: <a href="https://huggingface.co/spaces/{os.getenv('SPACE_ID')}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a> This will **NOT** work without duplication!
|
121 |
-
2. Enter your <a href="https://huggingface.co/settings/tokens">Hugging Face API Key</a> below.
|
122 |
-
""")
|
123 |
-
huggingface_key = get_api_key()
|
124 |
-
gr.Markdown(
|
125 |
-
"3. Fill the values below, then click 'Start'. There are example values you can load at the bottom of this page."
|
126 |
-
)
|
127 |
ai_name = get_ai_name()
|
128 |
ai_role = get_ai_role()
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
chatbot = get_chatbot()
|
140 |
-
with gr.Row():
|
141 |
-
yes_btn = get_yes_btn()
|
142 |
-
consecutive_yes = get_consecutive_yes()
|
143 |
-
custom_response = get_custom_response()
|
144 |
-
progress = get_progress() # Use the corrected progress function
|
145 |
-
with gr.Column(scale=1):
|
146 |
-
generated_files = get_generated_files()
|
147 |
-
download_btn = get_download_btn()
|
148 |
-
chat_history = gr.State([[None, None]])
|
149 |
-
api = gr.State(None)
|
150 |
-
|
151 |
start_btn.click(
|
152 |
start,
|
153 |
-
[
|
154 |
-
[setup_pane, main_pane,
|
155 |
-
).then(bot_response, [chat_history, api], chatbot).then(
|
156 |
-
activate_inputs, None, [yes_btn, consecutive_yes, custom_response]
|
157 |
-
)
|
158 |
-
|
159 |
-
yes_btn.click(
|
160 |
-
deactivate_inputs, None, [yes_btn, consecutive_yes, custom_response]
|
161 |
-
).then(
|
162 |
-
send_message, [consecutive_yes, chat_history, api], [chatbot, consecutive_yes]
|
163 |
-
).then(
|
164 |
-
activate_inputs, None, [yes_btn, consecutive_yes, custom_response]
|
165 |
-
)
|
166 |
-
|
167 |
-
custom_response.submit(
|
168 |
-
deactivate_inputs, None, [yes_btn, consecutive_yes, custom_response]
|
169 |
-
).then(
|
170 |
-
send_message,
|
171 |
-
[consecutive_yes, chat_history, api, custom_response],
|
172 |
-
[chatbot, consecutive_yes],
|
173 |
-
).then(
|
174 |
-
activate_inputs, None, [yes_btn, consecutive_yes, custom_response]
|
175 |
)
|
176 |
|
177 |
-
|
|
|
|
|
178 |
|
179 |
-
app
|
|
|
|
|
|
32 |
def get_ai_role():
|
33 |
return gr.Textbox(label="AI Role", placeholder="e.g. an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.")
|
34 |
|
35 |
+
def get_description():
|
36 |
+
return gr.Textbox(label="Description", placeholder="Enter a brief description of the project.")
|
37 |
+
|
38 |
def get_top_5_goals():
|
39 |
return gr.Dataframe(row_count=(5, "fixed"), col_count=(1, "fixed"), headers=["AI Goals - Enter up to 5"], type="array")
|
40 |
|
|
|
47 |
return []
|
48 |
|
49 |
def get_chatbot():
|
50 |
+
return gr.Chatbot(elem_id="chatbot", type='messages')
|
51 |
|
52 |
def get_yes_btn():
|
53 |
return gr.Button("Yes", variant="primary", interactive=False)
|
|
|
59 |
return gr.Textbox(label="Custom Response", placeholder="Press 'Enter' to Submit.", interactive=False)
|
60 |
|
61 |
def get_progress():
|
62 |
+
return gr.Progress()
|
63 |
|
64 |
def get_generated_files():
|
65 |
return gr.HTML(lambda: f"Generated Files<pre><code style='overflow-x: auto'>{utils.format_directory(OUTPUT_DIR)}</pre></code>", every=3, elem_id="files")
|
66 |
+
|
67 |
def get_download_btn():
|
68 |
+
return gr.Button("Download All Files")
|
69 |
|
70 |
+
def get_inferred_tasks():
|
71 |
+
return gr.Textbox(label="Inferred Tasks", interactive=False)
|
72 |
+
|
73 |
+
def start(huggingface_key, ai_name, ai_role, top_5_goals, description):
|
74 |
try:
|
75 |
from api import AutoAPI
|
76 |
auto_api = AutoAPI(huggingface_key, ai_name, ai_role, top_5_goals)
|
77 |
logger.info("AutoAPI started with AI Name: %s, AI Role: %s", ai_name, ai_role)
|
78 |
+
|
79 |
+
# Infer tasks based on the role and description
|
80 |
+
tasks = auto_api.infer_tasks(description)
|
81 |
+
logger.info("Inferred tasks: % s", tasks)
|
82 |
+
|
83 |
+
return gr.Column.update(visible=False), gr.Column.update(visible=True), auto_api, tasks
|
84 |
except Exception as e:
|
85 |
logger.error("Failed to start AutoAPI: %s", str(e))
|
86 |
+
return gr.Column.update(visible=True), gr.Column.update(visible=False), None, []
|
87 |
+
|
88 |
+
# Main Gradio Interface
|
89 |
+
with gr.Blocks(css=CSS) as demo:
|
90 |
+
gr.Markdown("# AutoGPT Task Inference")
|
91 |
+
|
92 |
+
with gr.Row():
|
93 |
+
api_key = get_api_key()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
ai_name = get_ai_name()
|
95 |
ai_role = get_ai_role()
|
96 |
+
|
97 |
+
description = get_description()
|
98 |
+
top_5_goals = get_top_5_goals()
|
99 |
+
|
100 |
+
start_btn = gr.Button("Start")
|
101 |
+
main_pane = gr.Column(visible=False)
|
102 |
+
setup_pane = gr.Column(visible=True)
|
103 |
+
|
104 |
+
inferred_tasks = get_inferred_tasks()
|
105 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
start_btn.click(
|
107 |
start,
|
108 |
+
[api_key, ai_name, ai_role, top_5_goals, description],
|
109 |
+
[setup_pane, main_pane, None, inferred_tasks],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
)
|
111 |
|
112 |
+
with main_pane:
|
113 |
+
get_generated_files()
|
114 |
+
get_download_btn()
|
115 |
|
116 |
+
# Launch the Gradio app
|
117 |
+
if __name__ == "__main__":
|
118 |
+
demo.launch()
|