Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
import api
|
3 |
-
import utils
|
4 |
import os
|
5 |
import shutil
|
6 |
import json
|
@@ -14,31 +12,41 @@ logger = logging.getLogger(__name__)
|
|
14 |
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
|
15 |
EXAMPLES_PATH = os.path.join(FILE_DIR, 'examples.json')
|
16 |
OUTPUT_DIR = os.path.join(os.path.dirname(FILE_DIR), "auto_gpt_workspace")
|
|
|
|
|
17 |
if not os.path.exists(OUTPUT_DIR):
|
18 |
-
os.
|
19 |
|
|
|
20 |
CSS = """
|
21 |
#chatbot {font-family: monospace;}
|
22 |
#files .generating {display: none;}
|
23 |
#files .min {min-height: 0px;}
|
24 |
"""
|
25 |
|
|
|
26 |
def get_api_key():
|
|
|
27 |
return gr.Textbox(label="Hugging Face API Key", type="password")
|
28 |
|
29 |
def get_ai_name():
|
|
|
30 |
return gr.Textbox(label="AI Name", placeholder="e.g. Entrepreneur-GPT")
|
31 |
|
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 |
|
41 |
def get_example_values():
|
|
|
42 |
try:
|
43 |
with open(EXAMPLES_PATH, 'r', encoding='utf-8') as f:
|
44 |
return json.load(f)
|
@@ -47,30 +55,65 @@ def get_example_values():
|
|
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)
|
54 |
|
55 |
def get_consecutive_yes():
|
|
|
56 |
return gr.Slider(1, 10, 1, step=1, label="Consecutive Yes", interactive=False)
|
57 |
|
58 |
def get_custom_response():
|
|
|
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)
|
@@ -78,12 +121,12 @@ def start(huggingface_key, ai_name, ai_role, top_5_goals, description):
|
|
78 |
|
79 |
# Infer tasks based on the role and description
|
80 |
tasks = auto_api.infer_tasks(description)
|
81 |
-
logger.info("Inferred 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:
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import os
|
3 |
import shutil
|
4 |
import json
|
|
|
12 |
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
|
13 |
EXAMPLES_PATH = os.path.join(FILE_DIR, 'examples.json')
|
14 |
OUTPUT_DIR = os.path.join(os.path.dirname(FILE_DIR), "auto_gpt_workspace")
|
15 |
+
|
16 |
+
# Create output directory if it doesn't exist
|
17 |
if not os.path.exists(OUTPUT_DIR):
|
18 |
+
os.makedirs(OUTPUT_DIR)
|
19 |
|
20 |
+
# Custom CSS for styling
|
21 |
CSS = """
|
22 |
#chatbot {font-family: monospace;}
|
23 |
#files .generating {display: none;}
|
24 |
#files .min {min-height: 0px;}
|
25 |
"""
|
26 |
|
27 |
+
# UI Components
|
28 |
def get_api_key():
|
29 |
+
"""Get Hugging Face API key input."""
|
30 |
return gr.Textbox(label="Hugging Face API Key", type="password")
|
31 |
|
32 |
def get_ai_name():
|
33 |
+
"""Get AI name input."""
|
34 |
return gr.Textbox(label="AI Name", placeholder="e.g. Entrepreneur-GPT")
|
35 |
|
36 |
def get_ai_role():
|
37 |
+
"""Get AI role input."""
|
38 |
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.")
|
39 |
|
40 |
def get_description():
|
41 |
+
"""Get project description input."""
|
42 |
return gr.Textbox(label="Description", placeholder="Enter a brief description of the project.")
|
43 |
|
44 |
def get_top_5_goals():
|
45 |
+
"""Get top 5 goals input."""
|
46 |
return gr.Dataframe(row_count=(5, "fixed"), col_count=(1, "fixed"), headers=["AI Goals - Enter up to 5"], type="array")
|
47 |
|
48 |
def get_example_values():
|
49 |
+
"""Load example values from JSON file."""
|
50 |
try:
|
51 |
with open(EXAMPLES_PATH, 'r', encoding='utf-8') as f:
|
52 |
return json.load(f)
|
|
|
55 |
return []
|
56 |
|
57 |
def get_chatbot():
|
58 |
+
"""Get chatbot UI element."""
|
59 |
return gr.Chatbot(elem_id="chatbot", type='messages')
|
60 |
|
61 |
def get_yes_btn():
|
62 |
+
"""Get Yes button."""
|
63 |
return gr.Button("Yes", variant="primary", interactive=False)
|
64 |
|
65 |
def get_consecutive_yes():
|
66 |
+
"""Get slider for consecutive yes count."""
|
67 |
return gr.Slider(1, 10, 1, step=1, label="Consecutive Yes", interactive=False)
|
68 |
|
69 |
def get_custom_response():
|
70 |
+
"""Get custom response input."""
|
71 |
return gr.Textbox(label="Custom Response", placeholder="Press 'Enter' to Submit.", interactive=False)
|
72 |
|
73 |
def get_progress():
|
74 |
+
"""Get progress bar."""
|
75 |
return gr.Progress()
|
76 |
|
77 |
def get_generated_files():
|
78 |
+
"""Get HTML element to display generated files."""
|
79 |
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")
|
80 |
|
81 |
def get_download_btn():
|
82 |
+
"""Get download all files button."""
|
83 |
return gr.Button("Download All Files")
|
84 |
|
85 |
def get_inferred_tasks():
|
86 |
+
"""Get inferred tasks textbox."""
|
87 |
return gr.Textbox(label="Inferred Tasks", interactive=False)
|
88 |
|
89 |
+
class AutoAPI:
|
90 |
+
def __init__(self, huggingface_key, ai_name, ai_role, top_5_goals):
|
91 |
+
self.huggingface_key = huggingface_key
|
92 |
+
self.ai_name = ai_name
|
93 |
+
self.ai_role = ai_role
|
94 |
+
self.top_5_goals = top_5_goals
|
95 |
+
|
96 |
+
def infer_tasks(self, description):
|
97 |
+
# Placeholder for actual task inference logic
|
98 |
+
# Simulate task inference based on the description
|
99 |
+
tasks = []
|
100 |
+
|
101 |
+
# Simple logic to infer tasks based on keywords in the description
|
102 |
+
if "business" in description.lower():
|
103 |
+
tasks.extend(["Analyze market trends", "Create business plan"])
|
104 |
+
if "technology" in description.lower():
|
105 |
+
tasks.extend(["Research latest technology", "Prototype development"])
|
106 |
+
if "startup" in description.lower():
|
107 |
+
tasks.extend(["Identify target audience", "Develop marketing strategy"])
|
108 |
+
|
109 |
+
# Ensure the list always has 5 tasks
|
110 |
+
while len(tasks) < 5:
|
111 |
+
tasks.append(f"Generic Task {len(tasks) + 1}")
|
112 |
+
|
113 |
+
return tasks
|
114 |
+
|
115 |
def start(huggingface_key, ai_name, ai_role, top_5_goals, description):
|
116 |
+
"""Start AutoAPI and infer tasks."""
|
117 |
try:
|
118 |
from api import AutoAPI
|
119 |
auto_api = AutoAPI(huggingface_key, ai_name, ai_role, top_5_goals)
|
|
|
121 |
|
122 |
# Infer tasks based on the role and description
|
123 |
tasks = auto_api.infer_tasks(description)
|
124 |
+
logger.info("Inferred tasks: %s", tasks)
|
125 |
|
126 |
+
return gr.Column.update(visible=False), gr.Column.update(visible=True), auto_api, gr.update(value=tasks)
|
127 |
except Exception as e:
|
128 |
logger.error("Failed to start AutoAPI: %s", str(e))
|
129 |
+
return gr.Column.update(visible=True), gr.Column.update(visible=False), None, gr.update(value=[])
|
130 |
|
131 |
# Main Gradio Interface
|
132 |
with gr.Blocks(css=CSS) as demo:
|