Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import google.generativeai as genai | |
| import os | |
| # β Load your API key securely (use Hugging Face Secrets or .env for local) | |
| genai.configure(api_key=os.getenv("GEMINI_API_KEY")) | |
| # β Load Gemini Pro Model | |
| model = genai.GenerativeModel(model_name="models/gemini-pro") | |
| # β Agentic AI Function | |
| def agentic_ai(user_input, instructions): | |
| # Build prompt: you can adjust this to include history or goals | |
| prompt = f""" | |
| Instructions: {instructions} | |
| User input: {user_input} | |
| Based on the instructions, respond intelligently. | |
| """ | |
| try: | |
| response = model.generate_content(prompt) | |
| return response.text.strip() | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| # β Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### π€ Agentic AI Assistant (Powered by Gemini Pro)") | |
| with gr.Row(): | |
| user_input = gr.Textbox(label="User Input", placeholder="Ask a question or request an action...") | |
| with gr.Row(): | |
| instructions = gr.Textbox( | |
| value="You are an AI assistant. Understand the user's request and respond helpfully.", | |
| label="Runbook Instructions (Editable)" | |
| ) | |
| output = gr.Textbox(label="Agent Response") | |
| run_btn = gr.Button("Run Agent") | |
| run_btn.click(fn=agentic_ai, inputs=[user_input, instructions], outputs=output) | |
| demo.launch() | |