Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -393,4 +393,239 @@ elif app_mode == "Workspace Chat App":
|
|
| 393 |
if agent._hf_api and agent.has_valid_hf_token():
|
| 394 |
repository = agent.deploy_built_space_to_hf()
|
| 395 |
st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
|
| 396 |
-
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
if agent._hf_api and agent.has_valid_hf_token():
|
| 394 |
repository = agent.deploy_built_space_to_hf()
|
| 395 |
st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
|
| 396 |
+
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
| 397 |
+
|
| 398 |
+
if __name__ == "__main__":
|
| 399 |
+
st.sidebar.title("Navigation")
|
| 400 |
+
app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
|
| 401 |
+
|
| 402 |
+
if app_mode == "AI Agent Creator":
|
| 403 |
+
# AI Agent Creator
|
| 404 |
+
st.header("Create an AI Agent from Text")
|
| 405 |
+
|
| 406 |
+
st.subheader("From Text")
|
| 407 |
+
agent_name = st.text_input("Enter agent name:")
|
| 408 |
+
text_input = st.text_area("Enter skills (one per line):")
|
| 409 |
+
if st.button("Create Agent"):
|
| 410 |
+
skills = text_input.split('\n')
|
| 411 |
+
agent = AIAgent(agent_name, "AI agent created from text input", skills)
|
| 412 |
+
st.success(f"Agent '{agent_name}' created and saved successfully.")
|
| 413 |
+
st.session_state.available_agents.append(agent_name)
|
| 414 |
+
|
| 415 |
+
elif app_mode == "Tool Box":
|
| 416 |
+
# Tool Box
|
| 417 |
+
st.header("AI-Powered Tools")
|
| 418 |
+
|
| 419 |
+
# Chat Interface
|
| 420 |
+
st.subheader("Chat with CodeCraft")
|
| 421 |
+
chat_input = st.text_area("Enter your message:")
|
| 422 |
+
if st.button("Send"):
|
| 423 |
+
response = process_input(chat_input)
|
| 424 |
+
st.session_state.chat_history.append((chat_input, response))
|
| 425 |
+
st.write(f"CodeCraft: {response}")
|
| 426 |
+
|
| 427 |
+
# Terminal Interface
|
| 428 |
+
st.subheader("Terminal")
|
| 429 |
+
terminal_input = st.text_input("Enter a command:")
|
| 430 |
+
if st.button("Run"):
|
| 431 |
+
output = run_code(terminal_input)
|
| 432 |
+
st.session_state.terminal_history.append((terminal_input, output))
|
| 433 |
+
st.code(output, language="bash")
|
| 434 |
+
|
| 435 |
+
# Project Management
|
| 436 |
+
st.subheader("Project Management")
|
| 437 |
+
project_name_input = st.text_input("Enter Project Name:")
|
| 438 |
+
if st.button("Create Project"):
|
| 439 |
+
status = workspace_interface(project_name_input)
|
| 440 |
+
st.write(status)
|
| 441 |
+
|
| 442 |
+
code_to_add = st.text_area("Enter Code to Add to Workspace:", height=150)
|
| 443 |
+
file_name_input = st.text_input("Enter File Name (e.g., 'app.py'):")
|
| 444 |
+
if st.button("Add Code"):
|
| 445 |
+
status = add_code_to_workspace(project_name_input, code_to_add, file_name_input)
|
| 446 |
+
st.write(status)
|
| 447 |
+
|
| 448 |
+
# Display Chat History
|
| 449 |
+
st.subheader("Chat History")
|
| 450 |
+
chat_history = display_chat_history(st.session_state.chat_history)
|
| 451 |
+
st.text_area("Chat History", value=chat_history, height=200)
|
| 452 |
+
|
| 453 |
+
# Display Workspace Projects
|
| 454 |
+
st.subheader("Workspace Projects")
|
| 455 |
+
workspace_projects = display_workspace_projects(st.session_state.workspace_projects)
|
| 456 |
+
st.text_area("Workspace Projects", value=workspace_projects, height=200)
|
| 457 |
+
|
| 458 |
+
elif app_mode == "Workspace Chat App":
|
| 459 |
+
# Workspace Chat App
|
| 460 |
+
st.header("Workspace Chat App")
|
| 461 |
+
|
| 462 |
+
# Chat Interface with AI Agents
|
| 463 |
+
st.subheader("Chat with AI Agents")
|
| 464 |
+
selected_agent = st.selectbox("Select an AI agent", st.session_state.available_agents)
|
| 465 |
+
agent_chat_input = st.text_area("Enter your message for the agent:")
|
| 466 |
+
if st.button("Send to Agent"):
|
| 467 |
+
response = process_input(agent_chat_input)
|
| 468 |
+
st.session_state.chat_history.append((agent_chat_input, response))
|
| 469 |
+
st.write(f"{selected_agent}: {response}")
|
| 470 |
+
|
| 471 |
+
# Code Generation
|
| 472 |
+
st.subheader("Code Generation")
|
| 473 |
+
code_idea = st.text_input("Enter your code idea:")
|
| 474 |
+
selected_model = st.selectbox("Select a code-generative model", AVAILABLE_CODE_GENERATIVE_MODELS)
|
| 475 |
+
if st.button("Generate Code"):
|
| 476 |
+
generated_code = run_code(code_idea)
|
| 477 |
+
st.code(generated_code, language="python")
|
| 478 |
+
|
| 479 |
+
# Automate Build Process
|
| 480 |
+
st.subheader("Automate Build Process")
|
| 481 |
+
if st.button("Automate"):
|
| 482 |
+
agent = AIAgent(selected_agent, "", []) # Load the agent without skills for now
|
| 483 |
+
summary, next_step = agent.autonomous_build(st.session_state.chat_history, st.session_state.workspace_projects, project_name, selected_model, hf_token)
|
| 484 |
+
st.write("Autonomous Build Summary:")
|
| 485 |
+
st.write(summary)
|
| 486 |
+
st.write("Next Step:")
|
| 487 |
+
st.write(next_step)
|
| 488 |
+
|
| 489 |
+
if agent._hf_api and agent.has_valid_hf_token():
|
| 490 |
+
repository = agent.deploy_built_space_to_hf()
|
| 491 |
+
st.markdown("## Congratulations! Successfully deployed Space 🚀 ##")
|
| 492 |
+
st.markdown("[Check out your new Space here](hf.co/" + repository.name + ")")
|
| 493 |
+
|
| 494 |
+
# Launch the Streamlit app
|
| 495 |
+
st.markdown("""
|
| 496 |
+
<style>
|
| 497 |
+
/* Advanced and Accommodating CSS */
|
| 498 |
+
body {
|
| 499 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 500 |
+
background-color: #f4f4f9;
|
| 501 |
+
color: #333;
|
| 502 |
+
margin: 0;
|
| 503 |
+
padding: 0;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
h1, h2, h3, h4, h5, h6 {
|
| 507 |
+
color: #333;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
.container {
|
| 511 |
+
width: 90%;
|
| 512 |
+
margin: 0 auto;
|
| 513 |
+
padding: 20px;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
/* Navigation Sidebar */
|
| 517 |
+
.sidebar {
|
| 518 |
+
background-color: #2c3e50;
|
| 519 |
+
color: #ecf0f1;
|
| 520 |
+
padding: 20px;
|
| 521 |
+
height: 100vh;
|
| 522 |
+
position: fixed;
|
| 523 |
+
top: 0;
|
| 524 |
+
left: 0;
|
| 525 |
+
width: 250px;
|
| 526 |
+
overflow-y: auto;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
.sidebar a {
|
| 530 |
+
color: #ecf0f1;
|
| 531 |
+
text-decoration: none;
|
| 532 |
+
display: block;
|
| 533 |
+
padding: 10px 0;
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
.sidebar a:hover {
|
| 537 |
+
background-color: #34495e;
|
| 538 |
+
border-radius: 5px;
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
/* Main Content */
|
| 542 |
+
.main-content {
|
| 543 |
+
margin-left: 270px;
|
| 544 |
+
padding: 20px;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
/* Buttons */
|
| 548 |
+
button {
|
| 549 |
+
background-color: #3498db;
|
| 550 |
+
color: #fff;
|
| 551 |
+
border: none;
|
| 552 |
+
padding: 10px 20px;
|
| 553 |
+
border-radius: 5px;
|
| 554 |
+
cursor: pointer;
|
| 555 |
+
font-size: 16px;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
button:hover {
|
| 559 |
+
background-color: #2980b9;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
/* Text Areas and Inputs */
|
| 563 |
+
textarea, input[type="text"] {
|
| 564 |
+
width: 100%;
|
| 565 |
+
padding: 10px;
|
| 566 |
+
margin: 10px 0;
|
| 567 |
+
border: 1px solid #ddd;
|
| 568 |
+
border-radius: 5px;
|
| 569 |
+
box-sizing: border-box;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
textarea:focus, input[type="text"]:focus {
|
| 573 |
+
border-color: #3498db;
|
| 574 |
+
outline: none;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
/* Terminal Output */
|
| 578 |
+
.code-output {
|
| 579 |
+
background-color: #1e1e1e;
|
| 580 |
+
color: #dcdcdc;
|
| 581 |
+
padding: 20px;
|
| 582 |
+
border-radius: 5px;
|
| 583 |
+
font-family: 'Courier New', Courier, monospace;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
/* Chat History */
|
| 587 |
+
.chat-history {
|
| 588 |
+
background-color: #ecf0f1;
|
| 589 |
+
padding: 20px;
|
| 590 |
+
border-radius: 5px;
|
| 591 |
+
max-height: 300px;
|
| 592 |
+
overflow-y: auto;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
.chat-message {
|
| 596 |
+
margin-bottom: 10px;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
.chat-message.user {
|
| 600 |
+
text-align: right;
|
| 601 |
+
color: #3498db;
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
.chat-message.agent {
|
| 605 |
+
text-align: left;
|
| 606 |
+
color: #e74c3c;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
/* Project Management */
|
| 610 |
+
.project-list {
|
| 611 |
+
background-color: #ecf0f1;
|
| 612 |
+
padding: 20px;
|
| 613 |
+
border-radius: 5px;
|
| 614 |
+
max-height: 300px;
|
| 615 |
+
overflow-y: auto;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
.project-item {
|
| 619 |
+
margin-bottom: 10px;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
.project-item a {
|
| 623 |
+
color: #3498db;
|
| 624 |
+
text-decoration: none;
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
.project-item a:hover {
|
| 628 |
+
text-decoration: underline;
|
| 629 |
+
}
|
| 630 |
+
</style>
|
| 631 |
+
""", unsafe_allow_html=True)
|