Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -100,6 +100,14 @@ def end_fn(purpose, task, history, directory, action_input):
|
|
100 |
task = "END"
|
101 |
return "COMPLETE", "COMPLETE", history, task
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
NAME_TO_FUNC = {
|
104 |
"MAIN": call_main,
|
105 |
"UPDATE-TASK": call_set_task,
|
@@ -107,6 +115,114 @@ NAME_TO_FUNC = {
|
|
107 |
"COMPLETE": end_fn,
|
108 |
}
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
def run_action(purpose, task, history, directory, action_name, action_input):
|
111 |
print(f'action_name::{action_name}')
|
112 |
try:
|
@@ -115,13 +231,13 @@ def run_action(purpose, task, history, directory, action_name, action_input):
|
|
115 |
task = "END"
|
116 |
return action_name, "COMPLETE", history, task
|
117 |
|
118 |
-
if len(history.split(
|
119 |
if VERBOSE:
|
120 |
print("COMPRESSING HISTORY")
|
121 |
history = compress_history(purpose, task, history, directory)
|
122 |
if not action_name in NAME_TO_FUNC:
|
123 |
action_name = "MAIN"
|
124 |
-
if action_name ==
|
125 |
action_name = "MAIN"
|
126 |
assert action_name in NAME_TO_FUNC
|
127 |
|
@@ -161,7 +277,8 @@ def run(purpose, history):
|
|
161 |
yield (history)
|
162 |
if task == "END":
|
163 |
return (history)
|
164 |
-
iface = gr.Interface(fn=run, inputs=["text", "text"], outputs="text", title="
|
|
|
165 |
|
166 |
# Launch the Gradio interface
|
167 |
iface.launch(share=True)
|
|
|
100 |
task = "END"
|
101 |
return "COMPLETE", "COMPLETE", history, task
|
102 |
|
103 |
+
EXAMPLE_PROJECT_DIRECTORY = './example_project/'
|
104 |
+
|
105 |
+
PREFIX = """Answer the following question as accurately as possible, providing detailed responses that cover each aspect of the topic. Make sure to maintain a professional tone throughout your answers. Also please make sure to meet the safety criteria specified earlier. Question: What are the suggested approaches for creating a responsive navigation bar? Answer:"""
|
106 |
+
LOG_PROMPT = "Prompt: {}"
|
107 |
+
LOG_RESPONSE = "Response: {}"
|
108 |
+
COMPRESS_HISTORY_PROMPT = """Given the context history, compress it down to something meaningful yet short enough to fit into a single chat message without exceeding over 512 tokens. Context: {}"""
|
109 |
+
TASK_PROMPT = """Determine the correct next step in terms of actions, thoughts or observations for the following task: {}, current history: {}, current directory: {}."""
|
110 |
+
|
111 |
NAME_TO_FUNC = {
|
112 |
"MAIN": call_main,
|
113 |
"UPDATE-TASK": call_set_task,
|
|
|
115 |
"COMPLETE": end_fn,
|
116 |
}
|
117 |
|
118 |
+
def _clean_up():
|
119 |
+
if os.path.exists(EXAMPLE_PROJECT_DIRECTORY):
|
120 |
+
shutil.rmtree(EXAMPLE_PROJECT_DIRECTORY)
|
121 |
+
|
122 |
+
def call_main(purpose, task, history, directory, action_input=''):
|
123 |
+
_clean_up()
|
124 |
+
os.makedirs(EXAMPLE_PROJECT_DIRECTORY)
|
125 |
+
template = '''<!DOCTYPE html>
|
126 |
+
<html lang="en">
|
127 |
+
<head>
|
128 |
+
<meta charset="UTF-8">
|
129 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
130 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
131 |
+
<title>Document</title>
|
132 |
+
<style>
|
133 |
+
{{%style}}
|
134 |
+
</style>
|
135 |
+
</head>
|
136 |
+
<body>
|
137 |
+
{{%body}}
|
138 |
+
</body>
|
139 |
+
</html>'''
|
140 |
+
|
141 |
+
navbar = f'''<nav>
|
142 |
+
<input type="checkbox" id="check">
|
143 |
+
<label for="check" class="checkbtn">
|
144 |
+
<i class="fas fa-bars"></i>
|
145 |
+
</label>
|
146 |
+
<label class="logo">LOGO</label>
|
147 |
+
<ul>
|
148 |
+
<li><a href="#home">Home</a></li>
|
149 |
+
<li><a href="#about">About Us</a></li>
|
150 |
+
<li><a href="#services">Services</a></li>
|
151 |
+
<li><a href="#contact">Contact Us</a></li>
|
152 |
+
</ul>
|
153 |
+
</nav>'''
|
154 |
+
|
155 |
+
css = '''*{
|
156 |
+
box-sizing: border-box;}
|
157 |
+
|
158 |
+
body {{
|
159 |
+
font-family: sans-serif;
|
160 |
+
margin: 0;
|
161 |
+
padding: 0;
|
162 |
+
background: #f4f4f4;
|
163 |
+
}}
|
164 |
+
|
165 |
+
/* Navigation */
|
166 |
+
nav {{
|
167 |
+
position: fixed;
|
168 |
+
width: 100%;
|
169 |
+
height: 70px;
|
170 |
+
line-height: 70px;
|
171 |
+
z-index: 999;
|
172 |
+
transition: all .6s ease-in-out;
|
173 |
+
}}
|
174 |
+
|
175 |
+
nav ul {{
|
176 |
+
float: right;
|
177 |
+
margin-right: 40px;
|
178 |
+
display: flex;
|
179 |
+
justify-content: space-between;
|
180 |
+
align-items: center;
|
181 |
+
list-style: none;
|
182 |
+
}}
|
183 |
+
|
184 |
+
nav li {{
|
185 |
+
position: relative;
|
186 |
+
text-transform: uppercase;
|
187 |
+
letter-spacing: 2px;
|
188 |
+
cursor: pointer;
|
189 |
+
padding: 0 10px;
|
190 |
+
}}
|
191 |
+
|
192 |
+
nav li:hover > ul {{
|
193 |
+
visibility: visible;
|
194 |
+
opacity: 1;
|
195 |
+
transform: translateY(0);
|
196 |
+
top: auto;
|
197 |
+
left:auto;
|
198 |
+
-webkit-transition:all 0.3s linear; /* Safari/Chrome/Opera/Gecko */
|
199 |
+
-moz-transition:all 0.3s linear; /* FF3.6+ */
|
200 |
+
-ms-transition:all 0.3s linear; /* IE10 */
|
201 |
+
-o-transition:all 0.3s linear; /* Opera 10.5–12.00 */
|
202 |
+
transition:all 0.3s linear;
|
203 |
+
}}
|
204 |
+
|
205 |
+
nav ul ul {{
|
206 |
+
visibility: hidden;
|
207 |
+
opacity: 0;
|
208 |
+
min-width: 180px;
|
209 |
+
white-space: nowrap;
|
210 |
+
background: rgba(255, 255, 255, 0.9);
|
211 |
+
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.2);
|
212 |
+
border-radius: 0px;
|
213 |
+
transition: all 0.5s cubic-bezier(0.770, 0.000, 0.175, 1.000);
|
214 |
+
position: absolute;
|
215 |
+
top: 100%;
|
216 |
+
left: 0;
|
217 |
+
z-index: 9999;
|
218 |
+
padding: 0;
|
219 |
+
}}'''
|
220 |
+
|
221 |
+
with open(os.path.join(EXAMPLE_PROJECT_DIRECTORY, 'index.html'), 'w') as f:
|
222 |
+
f.write(template.format(body=navbar, style=css))
|
223 |
+
|
224 |
+
return "MAIN", "", f"Created a responsive navigation bar in:\n{EXAMPLE_PROJECT_DIRECTORY}", task
|
225 |
+
|
226 |
def run_action(purpose, task, history, directory, action_name, action_input):
|
227 |
print(f'action_name::{action_name}')
|
228 |
try:
|
|
|
231 |
task = "END"
|
232 |
return action_name, "COMPLETE", history, task
|
233 |
|
234 |
+
if len(history.split('\n')) > MAX_HISTORY:
|
235 |
if VERBOSE:
|
236 |
print("COMPRESSING HISTORY")
|
237 |
history = compress_history(purpose, task, history, directory)
|
238 |
if not action_name in NAME_TO_FUNC:
|
239 |
action_name = "MAIN"
|
240 |
+
if action_name == '' or action_name is None:
|
241 |
action_name = "MAIN"
|
242 |
assert action_name in NAME_TO_FUNC
|
243 |
|
|
|
277 |
yield (history)
|
278 |
if task == "END":
|
279 |
return (history)
|
280 |
+
iface = gr.Interface(fn=run, inputs=["text", "text"], outputs="text", title="Expert Web Developer Assistant Agent", description="Ask me questions, give me tasks, and I will respond accordingly.\n Example: 'Purpose: Create a contact form | Action: FORMAT INPUT' & Input: '<form><div><label for='email'>Email:</label><input type='email'/></div></form>' ")
|
281 |
+
|
282 |
|
283 |
# Launch the Gradio interface
|
284 |
iface.launch(share=True)
|