Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -91,7 +91,14 @@ class AIAgent:
|
|
91 |
self.current_task: Optional[str] = None
|
92 |
self.search_engine_url: str = "https://www.google.com/search?q=" # Default search engine
|
93 |
self.prompts: List[str] = [] # Store prompts for future use
|
94 |
-
self.code_generator =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# --- Search Functionality ---
|
97 |
def search(self, query: str) -> List[str]:
|
@@ -110,9 +117,13 @@ class AIAgent:
|
|
110 |
def code_generation(self, snippet: str) -> str:
|
111 |
"""Generates code based on the provided snippet or description."""
|
112 |
try:
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
116 |
return generated_text
|
117 |
except Exception as e:
|
118 |
raise CodeGenerationError(f"Error during code generation: {e}")
|
@@ -384,12 +395,70 @@ class AIAgent:
|
|
384 |
# --- Streamlit Integration ---
|
385 |
if __name__ == "__main__":
|
386 |
agent = AIAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
st.title("AI Agent")
|
388 |
-
st.
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
|
394 |
# --- Gradio Integration ---
|
395 |
def gradio_interface(input_text):
|
|
|
91 |
self.current_task: Optional[str] = None
|
92 |
self.search_engine_url: str = "https://www.google.com/search?q=" # Default search engine
|
93 |
self.prompts: List[str] = [] # Store prompts for future use
|
94 |
+
self.code_generator = None # Initialize code generator later
|
95 |
+
self.available_models = [
|
96 |
+
"gpt2",
|
97 |
+
"facebook/bart-large-cnn",
|
98 |
+
"google/flan-t5-xl",
|
99 |
+
"bigscience/T0_3B",
|
100 |
+
] # Add more as needed
|
101 |
+
self.selected_model = "gpt2" # Default model
|
102 |
|
103 |
# --- Search Functionality ---
|
104 |
def search(self, query: str) -> List[str]:
|
|
|
117 |
def code_generation(self, snippet: str) -> str:
|
118 |
"""Generates code based on the provided snippet or description."""
|
119 |
try:
|
120 |
+
if not self.code_generator:
|
121 |
+
self.code_generator = pipeline(
|
122 |
+
'text-generation', model=self.selected_model
|
123 |
+
)
|
124 |
+
generated_text = self.code_generator(
|
125 |
+
snippet, max_length=500, num_return_sequences=1
|
126 |
+
)[0]['generated_text']
|
127 |
return generated_text
|
128 |
except Exception as e:
|
129 |
raise CodeGenerationError(f"Error during code generation: {e}")
|
|
|
395 |
# --- Streamlit Integration ---
|
396 |
if __name__ == "__main__":
|
397 |
agent = AIAgent()
|
398 |
+
st.set_page_config(
|
399 |
+
page_title="AI Agent",
|
400 |
+
page_icon="🤖",
|
401 |
+
layout="wide",
|
402 |
+
initial_sidebar_state="expanded",
|
403 |
+
)
|
404 |
st.title("AI Agent")
|
405 |
+
st.sidebar.title("Agent Settings")
|
406 |
+
|
407 |
+
# --- Command Dropdown ---
|
408 |
+
command_options = [
|
409 |
+
"SEARCH",
|
410 |
+
"CODEGEN",
|
411 |
+
"REFINE-CODE",
|
412 |
+
"TEST-CODE",
|
413 |
+
"INTEGRATE-CODE",
|
414 |
+
"TEST-APP",
|
415 |
+
"GENERATE-REPORT",
|
416 |
+
"WORKSPACE-EXPLORER",
|
417 |
+
"ADD_PROMPT",
|
418 |
+
"ACTION_PROMPT",
|
419 |
+
"COMPRESS_HISTORY_PROMPT",
|
420 |
+
"LOG_PROMPT",
|
421 |
+
"LOG_RESPONSE",
|
422 |
+
"MODIFY_PROMPT",
|
423 |
+
"PREFIX",
|
424 |
+
"SEARCH_QUERY",
|
425 |
+
"READ_PROMPT",
|
426 |
+
"TASK_PROMPT",
|
427 |
+
"UNDERSTAND_TEST_RESULTS_PROMPT",
|
428 |
+
]
|
429 |
+
selected_command = st.sidebar.selectbox("Command", command_options)
|
430 |
+
|
431 |
+
# --- Model Dropdown ---
|
432 |
+
selected_model = st.sidebar.selectbox(
|
433 |
+
"Model", agent.available_models, index=agent.available_models.index(agent.selected_model)
|
434 |
+
)
|
435 |
+
agent.selected_model = selected_model
|
436 |
+
|
437 |
+
# --- Input Field ---
|
438 |
+
input_str = st.text_input(f"Enter input for {selected_command}:")
|
439 |
+
|
440 |
+
# --- Execute Command ---
|
441 |
+
if st.button("Execute"):
|
442 |
+
if input_str:
|
443 |
+
agent.handle_input(f"{selected_command} {input_str}")
|
444 |
+
st.write(f"Output: {agent.task_history[-1]['output']}")
|
445 |
+
|
446 |
+
# --- Task History ---
|
447 |
+
st.subheader("Task History")
|
448 |
+
for task in agent.task_history:
|
449 |
+
st.write(f"**Action:** {task['action']}")
|
450 |
+
st.write(f"**Input:** {task['input']}")
|
451 |
+
st.write(f"**Output:** {task['output']}")
|
452 |
+
|
453 |
+
# --- Workspace Explorer ---
|
454 |
+
st.subheader("Workspace Explorer")
|
455 |
+
with st.expander("Explore Workspace"):
|
456 |
+
try:
|
457 |
+
workspace_output = agent.workspace_explorer()
|
458 |
+
st.write(workspace_output)
|
459 |
+
except WorkspaceExplorerError as e:
|
460 |
+
st.error(f"Error exploring workspace: {e}")
|
461 |
+
|
462 |
|
463 |
# --- Gradio Integration ---
|
464 |
def gradio_interface(input_text):
|