| | import google.generativeai as genai |
| | import gradio as gr |
| | import os |
| | |
| | api_key = os.getenv("YOUR_GEMINI_API_KEY") |
| | genai.configure(api_key=api_key) |
| | print("Using API key:", api_key) |
| |
|
| | |
| | model = genai.GenerativeModel("gemini-1.5-flash") |
| |
|
| | def build_agent(description): |
| | status_msg = "Generating agent plan... ⏳" |
| | output_md = "" |
| | yield gr.update(value=status_msg), gr.update(value=output_md) |
| | prompt = f""" |
| | You are Google Opal Agent Builder. |
| | The user wants to create an AI Agent. |
| | Agent description: "{description}" |
| | |
| | ✨ Please return in readable text format with headings: |
| | 1. Agent Purpose |
| | 2. Inputs (what the agent expects from the user) |
| | 3. Step-by-step Workflow |
| | 4. Example Interaction (dialogue between user and agent) |
| | """ |
| | response = model.generate_content(prompt) |
| | status_msg = "✅ Done!" |
| | output_md = response.text.strip() |
| | |
| | |
| | yield gr.update(value=status_msg), gr.update(value=output_md) |
| |
|
| | |
| | with gr.Blocks() as demo: |
| | gr.Markdown("## Google Opal Agent Builder (Gemini-powered)") |
| |
|
| | with gr.Row(): |
| | with gr.Column(): |
| | gr.Markdown("### Describe Your Agent") |
| | description_input = gr.Textbox( |
| | lines=3, |
| | placeholder="Enter your agent description here" |
| | ) |
| | build_btn = gr.Button("Build Agent") |
| |
|
| | with gr.Column(): |
| | status_box = gr.Textbox(label="Status", interactive=False) |
| | output_box = gr.Markdown(label="Agent Plan") |
| |
|
| | build_btn.click( |
| | build_agent, |
| | inputs=description_input, |
| | outputs=[status_box, output_box] |
| | ) |
| |
|
| | demo.launch() |