acecalisto3 commited on
Commit
fad993f
1 Parent(s): 248842c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +236 -29
app.py CHANGED
@@ -17,6 +17,12 @@ from agent import (
17
  generateFiles,
18
  )
19
 
 
 
 
 
 
 
20
  # Set Hugging Face repository URL and project root path
21
  HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/Mistri"
22
  PROJECT_ROOT = "projects"
@@ -406,40 +412,241 @@ elif app_mode == "Tool Box":
406
  if st.button("Analyze Sentiment"):
407
  sentiment = sentiment_analysis(sentiment_text)
408
  st.write(f"Sentiment: {sentiment}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
 
410
- # Text Translation Tool (Code Translation)
411
- st.subheader("Translate Code")
412
- code_to_translate = st.text_area("Enter code to translate:")
413
- source_language = st.text_input("Enter source language (e.g. 'Python'):")
414
- target_language = st.text_input("Enter target language (e.g. 'JavaScript'):")
415
- if st.button("Translate Code"):
416
- translated_code = translate_code(code_to_translate, source_language, target_language)
417
- st.code(translated_code, language=target_language.lower())
418
-
419
- # Code Generation
420
- st.subheader("Code Generation")
421
- code_idea = st.text_input("Enter your code idea:")
422
- if st.button("Generate Code"):
423
- generated_code = generate_code(code_idea)
424
- st.code(generated_code, language="python")
425
-
426
- # Display Preset Commands
427
- st.subheader("Preset Commands")
428
- preset_commands = {
429
- "Create a new project": "create_project('project_name')",
430
- "Add code to workspace": "add_code_to_workspace('project_name', 'code', 'file_name')",
431
- "Run terminal command": "terminal_interface('command', 'project_name')",
432
- "Generate code": "generate_code('code_idea')",
433
- "Summarize text": "summarize_text('text')",
434
- "Analyze sentiment": "sentiment_analysis('text')",
435
- "Translate code": "translate_code('code', 'source_language', 'target_language')",
436
  }
437
- for command_name, command in preset_commands.items():
438
- st.write(f"{command_name}: `{command}`")
439
 
440
- # Workspace Chat App
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  elif app_mode == "Workspace Chat App":
442
  st.header("Workspace Chat App")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
 
444
  # Project Workspace Creation
445
  st.subheader("Create a New Project")
 
17
  generateFiles,
18
  )
19
 
20
+ import importlib
21
+
22
+ # Dynamically import the Code symbol from the agent module
23
+ code_module = importlib.import_module('agent.Code')
24
+ Code = getattr(code_module, 'Code')
25
+
26
  # Set Hugging Face repository URL and project root path
27
  HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/Mistri"
28
  PROJECT_ROOT = "projects"
 
412
  if st.button("Analyze Sentiment"):
413
  sentiment = sentiment_analysis(sentiment_text)
414
  st.write(f"Sentiment: {sentiment}")
415
+ # Function to translate code using the Hugging Face API
416
+ def translate_code(code, input_language, output_language):
417
+ """
418
+ Translates code from one programming language to another using a Hugging Face translation pipeline.
419
+ Args:
420
+ code (str): The code to be translated.
421
+ input_language (str): The source programming language.
422
+ output_language (str): The target programming language.
423
+ Returns:
424
+ str: The translated code.
425
+ """
426
+ # Define a mapping of programming languages to natural languages
427
+ language_map = {
428
+ "python": "English",
429
+ "javascript": "French",
430
+ "java": "German",
431
+ # Add more mappings as needed
432
+ }
433
 
434
+ # Function to translate code using the Hugging Face API
435
+ def translate_code(code, input_language, output_language):
436
+ """
437
+ Translates code from one programming language to another using a Hugging Face translation pipeline.
438
+ Args:
439
+ code (str): The code to be translated.
440
+ input_language (str): The source programming language.
441
+ output_language (str): The target programming language.
442
+ Returns:
443
+ str: The translated code.
444
+ """
445
+ # Define a mapping of programming languages to natural languages
446
+ language_map = {
447
+ "python": "English",
448
+ "javascript": "French",
449
+ "java": "German",
450
+ # Add more mappings as needed
 
 
 
 
 
 
 
 
 
451
  }
 
 
452
 
453
+ # Translate the code using the translation pipeline
454
+ translated_code = translator(code, src_lang=language_map[input_language], tgt_lang=language_map[output_language])[0]['translation_text']
455
+
456
+ st.session_state.current_state['toolbox']['translated_code'] = translated_code
457
+ return translated_code
458
+
459
+ # Function to generate code using the Hugging Face API
460
+ def generate_code(prompt):
461
+ """
462
+ Generates code based on a given prompt using a Hugging Face code generation pipeline.
463
+ Args:
464
+ prompt (str): The prompt describing the code to be generated.
465
+ Returns:
466
+ str: The generated code.
467
+ """
468
+ generated_code = code_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
469
+ st.session_state.current_state['toolbox']['generated_code'] = generated_code
470
+ return generated_code
471
+
472
+ # Function to commit and push changes to the Hugging Face repository
473
+ def commit_and_push_changes(commit_message):
474
+ """
475
+ Commits and pushes changes to the Hugging Face repository.
476
+ Args:
477
+ commit_message (str): The commit message.
478
+ """
479
+ try:
480
+ subprocess.run(["git", "add", "."], check=True)
481
+ subprocess.run(["git", "commit", "-m", commit_message], check=True)
482
+ subprocess.run(["git", "push", HUGGING_FACE_REPO_URL], check=True)
483
+ except subprocess.CalledProcessError as e:
484
+ st.error(f"Error committing and pushing changes: {e}")
485
+
486
+ # Streamlit UI
487
+ st.title("AI Agent Creator and Workspace Chat App")
488
+
489
+ # Sidebar navigation
490
+ st.sidebar.title("Navigation")
491
+ app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
492
+
493
+ # Add dark mode toggle
494
+ if st.sidebar.checkbox("Dark Mode"):
495
+ st.markdown("""
496
+ <style>
497
+ .stApp {
498
+ background-color: #2b2b2b;
499
+ color: #ffffff;
500
+ }
501
+ </style>
502
+ """, unsafe_allow_html=True)
503
+
504
+ if app_mode == "AI Agent Creator":
505
+ st.header("Create an AI Agent")
506
+
507
+ col1, col2 = st.columns(2)
508
+
509
+ with col1:
510
+ agent_name = st.text_input("Enter agent name:")
511
+ agent_description = st.text_area("Enter agent description:")
512
+ agent_skills = st.text_area("Enter agent skills (one per line):")
513
+
514
+ if st.button("Create Agent"):
515
+ skills_list = agent_skills.split('\n')
516
+ new_agent = AIAgent(agent_name, agent_description, skills_list)
517
+ save_agent_to_file(new_agent)
518
+ st.success(f"Agent '{agent_name}' created successfully.")
519
+
520
+ with col2:
521
+ st.subheader("Available Agents")
522
+ for agent in st.session_state.available_agents:
523
+ st.write(f"- {agent}")
524
+
525
+ elif app_mode == "Tool Box":
526
+ st.header("AI-Powered Tools")
527
+
528
+ tool = st.selectbox("Select a tool", ["Chat", "Terminal", "Code Editor", "Summarize Text", "Sentiment Analysis", "Translate Code", "Generate Code"])
529
+
530
+ if tool == "Chat":
531
+ st.subheader("Chat with AI Assistant")
532
+ chat_input = st.text_area("Enter your message:")
533
+ agent_name = st.selectbox("Select an agent (optional):", [""] + st.session_state.available_agents)
534
+
535
+ if st.button("Send"):
536
+ if agent_name:
537
+ chat_response = chat_interface_with_agent(chat_input, agent_name)
538
+ else:
539
+ chat_response = chat_interface(chat_input)
540
+ st.session_state.chat_history.append((chat_input, chat_response))
541
+ st.write(f"AI: {chat_response}")
542
+
543
+ elif tool == "Terminal":
544
+ st.subheader("Terminal")
545
+ terminal_input = st.text_input("Enter a command:")
546
+ project_name = st.text_input("Enter project name (optional):")
547
+
548
+ if st.button("Run Command"):
549
+ terminal_output = terminal_interface(terminal_input, project_name)
550
+ st.session_state.terminal_history.append((terminal_input, terminal_output))
551
+ st.code(terminal_output, language="bash")
552
+
553
+ elif tool == "Code Editor":
554
+ st.subheader("Code Editor")
555
+ code = st_ace(
556
+ placeholder="Write your code here",
557
+ language="python",
558
+ theme="monokai",
559
+ keybinding="vscode",
560
+ font_size=14,
561
+ tab_size=4,
562
+ show_gutter=True,
563
+ show_print_margin=True,
564
+ wrap=False,
565
+ auto_update=False,
566
+ )
567
+ if st.button("Format & Lint"):
568
+ with st.spinner("Formatting and linting..."):
569
+ formatted_code, lint_message = code_editor_interface(code)
570
+ st.code(formatted_code, language="python")
571
+ st.info(lint_message)
572
+
573
+ elif tool == "Summarize Text":
574
+ st.subheader("Summarize Text")
575
+ text_to_summarize = st.text_area("Enter text to summarize:")
576
+ if st.button("Summarize"):
577
+ summary = summarize_text(text_to_summarize)
578
+ st.write("Summary:", summary)
579
+
580
+ elif tool == "Sentiment Analysis":
581
+ st.subheader("Sentiment Analysis")
582
+ text_to_analyze = st.text_area("Enter text for sentiment analysis:")
583
+ if st.button("Analyze Sentiment"):
584
+ sentiment = sentiment_analysis(text_to_analyze)
585
+ st.write("Sentiment:", sentiment)
586
+
587
+ elif tool == "Translate Code":
588
+ st.subheader("Translate Code")
589
+ code_to_translate = st.text_area("Enter code to translate:")
590
+ input_language = st.selectbox("Select input language:", ["python", "javascript", "java"])
591
+ output_language = st.selectbox("Select output language:", ["python", "javascript", "java"])
592
+ if st.button("Translate"):
593
+ translated_code = translate_code(code_to_translate, input_language, output_language)
594
+ st.code(translated_code, language=output_language)
595
+
596
+ elif tool == "Generate Code":
597
+ st.subheader("Generate Code")
598
+ code_prompt = st.text_area("Enter a prompt for code generation:")
599
+ if st.button("Generate Code"):
600
+ generated_code = generate_code(code_prompt)
601
+ st.code(generated_code, language="python")
602
+
603
  elif app_mode == "Workspace Chat App":
604
  st.header("Workspace Chat App")
605
+
606
+ col1, col2 = st.columns(2)
607
+
608
+ with col1:
609
+ st.subheader("Create a New Project")
610
+ project_name = st.text_input("Enter project name:")
611
+ if st.button("Create Project"):
612
+ workspace_status = workspace_interface(project_name)
613
+ st.success(workspace_status)
614
+
615
+ st.subheader("Add Code to Workspace")
616
+ code_to_add = st.text_area("Enter code to add to workspace:")
617
+ file_name = st.text_input("Enter file name (e.g. 'app.py'):")
618
+ if st.button("Add Code"):
619
+ add_code_status = add_code_to_workspace(project_name, code_to_add, file_name)
620
+ st.success(add_code_status)
621
+
622
+ with col2:
623
+ st.subheader("Chat with AI Assistant")
624
+ chat_input = st.text_area("Enter your message for guidance:")
625
+ if st.button("Get Guidance"):
626
+ chat_response = chat_interface(chat_input)
627
+ st.session_state.chat_history.append((chat_input, chat_response))
628
+ st.write(f"AI: {chat_response}")
629
+
630
+ st.subheader("Chat History")
631
+ for user_input, response in st.session_state.chat_history:
632
+ st.write(f"User: {user_input}")
633
+ st.write(f"AI: {response}")
634
+
635
+ st.subheader("Terminal History")
636
+ for command, output in st.session_state.terminal_history:
637
+ st.write(f"Command: {command}")
638
+ st.code(output, language="bash")
639
+
640
+ st.subheader("Workspace Projects")
641
+ for project, details in st.session_state.workspace_projects.items():
642
+ st.write(f"Project: {project}")
643
+ st.write("Files:")
644
+ for file in details["files"]:
645
+ st.write(f"- {file}")
646
+
647
+ # Display the current state
648
+ st.sidebar.subheader("Current State")
649
+ st.sidebar.json(st.session_state.current_state)t.header("Workspace Chat App")
650
 
651
  # Project Workspace Creation
652
  st.subheader("Create a New Project")