Madiharehan's picture
Update app.py
1da1ffd verified
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()