|
|
import gradio as gr |
|
|
import requests |
|
|
import os |
|
|
|
|
|
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") |
|
|
FIRECRAWL_KEY = os.getenv("FIRECRAWL_KEY") |
|
|
|
|
|
def lovable_agent(query): |
|
|
if not GEMINI_API_KEY: |
|
|
return "❌ Gemini API key missing" |
|
|
if not FIRECRAWL_KEY: |
|
|
return "❌ Firecrawl API key missing" |
|
|
|
|
|
|
|
|
crawl = requests.post( |
|
|
"https://api.firecrawl.dev/v1/search", |
|
|
headers={"Authorization": f"Bearer {FIRECRAWL_KEY}"}, |
|
|
json={"query": query}, |
|
|
).json() |
|
|
|
|
|
context = str(crawl) |
|
|
|
|
|
|
|
|
payload = { |
|
|
"model": "gemini-2.5-flash-lite", |
|
|
"messages": [ |
|
|
{"role": "system", "content": "You are an agentic AI assistant."}, |
|
|
{"role": "user", "content": f"Research:\n{context}\n\nQuestion: {query}"} |
|
|
], |
|
|
"max_tokens": 1000, |
|
|
} |
|
|
|
|
|
reply = requests.post( |
|
|
"https://generativelanguage.googleapis.com/v1beta/openai/chat/completions?key=" + GEMINI_API_KEY, |
|
|
json=payload |
|
|
).json() |
|
|
|
|
|
try: |
|
|
return reply["choices"][0]["message"]["content"] |
|
|
except: |
|
|
return "⚠️ API Response Error:\n" + str(reply) |
|
|
|
|
|
|
|
|
|
|
|
ui = gr.Interface( |
|
|
fn=lovable_agent, |
|
|
inputs=gr.Textbox(label="Ask anything", placeholder="Ex: Generate YouTube strategy..."), |
|
|
outputs=gr.Textbox(label="Lovable Agent Output"), |
|
|
title="❤️ Open Lovable — Agentic Intelligence", |
|
|
description="Gemini + Firecrawl powered research agent" |
|
|
) |
|
|
|
|
|
ui.launch() |