acecalisto3 commited on
Commit
e1c400c
·
verified ·
1 Parent(s): c41dcf5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -109
app.py CHANGED
@@ -3,15 +3,8 @@ import subprocess
3
  import random
4
  import json
5
  from flask import Flask, render_template
6
-
7
- app = Flask(__name__)
8
-
9
- @app.route("/")
10
- def index():
11
- return render_template("index.html")
12
-
13
  from datetime import datetime
14
- from gradio import blocks # Import blocks
15
  from safe_search import safe_search
16
  from i_search import google, i_search as i_s
17
  from agent import (
@@ -28,8 +21,16 @@ from agent import (
28
  UNDERSTAND_TEST_RESULTS_PROMPT,
29
  )
30
  from utils import parse_action, parse_file_content, read_python_module_structure
 
 
 
 
 
 
 
 
31
 
32
- class App(blocks.Blocks): # Inherit from gradio.blocks.Blocks
33
  def __init__(self):
34
  super().__init__()
35
  self.app_state = {"components": []}
@@ -128,108 +129,14 @@ class App(blocks.Blocks): # Inherit from gradio.blocks.Blocks
128
  def run_terminal_command(self, command, history):
129
  output = ""
130
  try:
131
- if command.startswith("add "):
132
- component_type = command.split("add ")[1]
133
- return self.add_component(component_type)
134
- elif command.startswith("search "):
135
- query = command.split("search ")[1]
136
- return google(query)
137
- elif command.startswith("i search "):
138
- query = command.split("i search ")[1]
139
- return i_s(query)
140
- elif command.startswith("safe search "):
141
- query = command.split("safesearch ")[1]
142
- return safe_search(query)
143
- elif command.startswith("read "):
144
- file_path = command.split("read ")[1]
145
- return parse_file_content(file_path)
146
- elif command == "task":
147
- return TASK_PROMPT
148
- elif command == "modify":
149
- return MODIFY_PROMPT
150
- elif command == "log":
151
- return LOG_PROMPT
152
- elif command.startswith("understand test results "):
153
- test_results = command.split("understand test results ")[1]
154
- return self.understand_test_results(test_results)
155
- elif command.startswith("compress history"):
156
- return self.compress_history(history)
157
- elif command == "help":
158
- return self.get_help_message()
159
- elif command == "exit":
160
- exit()
161
- else:
162
- output = subprocess.check_output(command, shell=True).decode("utf-8")
163
  except Exception as e:
164
  output = str(e)
165
- return output or "No output\n"
166
-
167
- def compress_history(self, history):
168
- compressed_history = ""
169
- lines = history.strip().split("\n")
170
- for line in lines:
171
- if not line.strip().startswith("#"):
172
- compressed_history += line + "\n"
173
- return compressed_history
174
-
175
- def understand_test_results(self, test_results):
176
- # Logic to understand test results
177
- return UNDERSTAND_TEST_RESULTS_PROMPT
178
-
179
- def get_help_message(self):
180
- return """
181
- Available commands:
182
- - add [component_type]: Add a component to the app canvas
183
- - search [query]: Perform a Google search
184
- - i search [query]: Perform an intelligent search
185
- - safe search [query]: Perform a safe search
186
- - read [file_path]: Read and parse the content of a Python module
187
- - task: Prompt for a task to perform
188
- - modify: Prompt to modify a component property
189
- - log: Prompt to log a response
190
- - understand test results [test_results]: Understand test results
191
- - compress history: Compress the terminal history by removing comments
192
- - help: Show this help message
193
- - exit: Exit the program
194
- """
195
-
196
- def process_input(self, input_text):
197
- if input_text.strip().startswith("/"):
198
- command = input_text.strip().lstrip("/")
199
- output = self.run_terminal_command(command, self.terminal_history)
200
- self.terminal_history += f"{input_text}\n{output}\n"
201
- return output
202
- else:
203
- model_index = random.randint(0, len(self.nlp_models)-1)
204
- response = self.get_nlp_response(input_text, model_index)
205
- component_id, action, property_name, property_value = parse_action(response)
206
- if component_id:
207
- component = next((comp for comp in self.app_state["components"] if comp["id"] == component_id), None)
208
- if component:
209
- if action == "update":
210
- component["properties"][property_name] = property_value
211
- return (
212
- self.update_app_canvas(),
213
- f"System: Updated property '{property_name}' of component with ID {component_id}\n",
214
- )
215
- elif action == "remove":
216
- self.app_state["components"].remove(component)
217
- return (
218
- self.update_app_canvas(),
219
- f"System: Removed component with ID {component_id}\n",
220
- )
221
- else:
222
- return None, f"Error: Invalid action: {action}\n"
223
- else:
224
- return None, f"Error: Component with ID {component_id} not found\n"
225
- else:
226
- return None, f"Error: Failed to parse action from NLP response\n"
227
-
228
- def run(self):
229
- print("Welcome to the Python App Builder!")
230
- print("Type 'help' to see the available commands.")
231
- print("-" * 50)
232
- self.launch()
233
 
234
  if __name__ == "__main__":
235
  app.run(debug=True)
 
3
  import random
4
  import json
5
  from flask import Flask, render_template
 
 
 
 
 
 
 
6
  from datetime import datetime
7
+ from gradio import Blocks
8
  from safe_search import safe_search
9
  from i_search import google, i_search as i_s
10
  from agent import (
 
21
  UNDERSTAND_TEST_RESULTS_PROMPT,
22
  )
23
  from utils import parse_action, parse_file_content, read_python_module_structure
24
+ from huggingface_hub import cached_download, hf_hub_url
25
+ from transformers import InferenceClient
26
+
27
+ app = Flask(__name__)
28
+
29
+ @app.route("/")
30
+ def index():
31
+ return render_template("index.html")
32
 
33
+ class App(Blocks):
34
  def __init__(self):
35
  super().__init__()
36
  self.app_state = {"components": []}
 
129
  def run_terminal_command(self, command, history):
130
  output = ""
131
  try:
132
+ process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
133
+ output, error = process.communicate()
134
+ if error:
135
+ output = error
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  except Exception as e:
137
  output = str(e)
138
+ self.terminal_history += f"{command}\n{output.decode('utf-8')}\n"
139
+ return self.terminal_history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  if __name__ == "__main__":
142
  app.run(debug=True)