| | import gradio as gr |
| | import tensorflow as tf |
| | import numpy as np |
| | from datasets import load_dataset |
| | from network import create_text_neural_network, create_gating_network |
| | from agent import PrimeAgent, SecondaryAgent |
| |
|
| | |
| | vocab_size = 10000 |
| | embedding_dim = 128 |
| | input_length = 100 |
| | num_classes = 10 |
| | num_experts = 3 |
| |
|
| | gating_network = create_gating_network((input_length,), num_experts) |
| | expert_networks = [create_text_neural_network(vocab_size, embedding_dim, input_length, num_classes) for _ in range(num_experts)] |
| | specialties = ['code writing', 'code debugging', 'code optimization'] |
| | secondary_agents = [SecondaryAgent(expert_networks[i], specialties[i]) for i in range(num_experts)] |
| | prime_agent = PrimeAgent(gating_network, secondary_agents) |
| |
|
| | |
| | def developer_assistant(input_text): |
| | |
| | response = "Understood. Here's what I can suggest:" |
| | |
| | tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=vocab_size) |
| | tokenizer.fit_on_texts([input_text]) |
| | input_data = tokenizer.texts_to_sequences([input_text]) |
| | input_data = tf.keras.preprocessing.sequence.pad_sequences(input_data, maxlen=input_length) |
| |
|
| | |
| | action = prime_agent.act(input_data) |
| | |
| | response += f"\\nExpert {action}: {specialties[action]}." |
| | return response |
| |
|
| | |
| | def display_code(): |
| | code_snippet = ''' |
| | def example_function(param1, param2): |
| | # Example function |
| | result = param1 + param2 |
| | return result |
| | ''' |
| | return code_snippet |
| |
|
| | |
| | gr_interface = gr.Interface( |
| | fn=developer_assistant, |
| | inputs=gr.inputs.Textbox(lines=5, placeholder="Enter your request here..."), |
| | outputs=[ |
| | gr.outputs.Textbox(label="Response"), |
| | gr.outputs.Code(language="python", label="Generated Code") |
| | ], |
| | title="Developer Assistant Chat Interface", |
| | description="Interact with the assistant to get code suggestions, debugging help, and more." |
| | ) |
| |
|
| | |
| | gr_interface.launch() |
| |
|