File size: 1,557 Bytes
fb8d4bc
87ea659
fb8d4bc
 
 
87ea659
fb8d4bc
87ea659
 
 
 
 
fb8d4bc
87ea659
 
 
 
 
 
fb8d4bc
87ea659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb8d4bc
87ea659
 
 
 
 
fb8d4bc
 
87ea659
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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"

    # 🔥 Step 1 — Firecrawl से वेबसर्च / scrape
    crawl = requests.post(
        "https://api.firecrawl.dev/v1/search",
        headers={"Authorization": f"Bearer {FIRECRAWL_KEY}"},
        json={"query": query},
    ).json()

    context = str(crawl)

    # 🤖 Step 2 — Gemini reasoning + planning
    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
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()