Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,53 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
-
import google.generativeai as genai
|
| 4 |
-
from firecrawl import FirecrawlClient
|
| 5 |
-
from dotenv import load_dotenv
|
| 6 |
|
| 7 |
-
load_dotenv()
|
| 8 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return response.text
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
ui = gr.Interface(
|
| 23 |
-
fn=
|
| 24 |
-
inputs=
|
| 25 |
-
outputs="
|
| 26 |
-
title="Open Lovable
|
| 27 |
-
description="
|
| 28 |
)
|
| 29 |
|
| 30 |
-
ui.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 6 |
+
FIRECRAWL_KEY = os.getenv("FIRECRAWL_KEY")
|
| 7 |
|
| 8 |
+
def lovable_agent(query):
|
| 9 |
+
if not GEMINI_API_KEY:
|
| 10 |
+
return "❌ Gemini API key missing"
|
| 11 |
+
if not FIRECRAWL_KEY:
|
| 12 |
+
return "❌ Firecrawl API key missing"
|
| 13 |
|
| 14 |
+
# 🔥 Step 1 — Firecrawl से वेबसर्च / scrape
|
| 15 |
+
crawl = requests.post(
|
| 16 |
+
"https://api.firecrawl.dev/v1/search",
|
| 17 |
+
headers={"Authorization": f"Bearer {FIRECRAWL_KEY}"},
|
| 18 |
+
json={"query": query},
|
| 19 |
+
).json()
|
|
|
|
| 20 |
|
| 21 |
+
context = str(crawl)
|
| 22 |
+
|
| 23 |
+
# 🤖 Step 2 — Gemini reasoning + planning
|
| 24 |
+
payload = {
|
| 25 |
+
"model": "gemini-2.5-flash-lite",
|
| 26 |
+
"messages": [
|
| 27 |
+
{"role": "system", "content": "You are an agentic AI assistant."},
|
| 28 |
+
{"role": "user", "content": f"Research:\n{context}\n\nQuestion: {query}"}
|
| 29 |
+
],
|
| 30 |
+
"max_tokens": 1000,
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
reply = requests.post(
|
| 34 |
+
"https://generativelanguage.googleapis.com/v1beta/openai/chat/completions?key=" + GEMINI_API_KEY,
|
| 35 |
+
json=payload
|
| 36 |
+
).json()
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
return reply["choices"][0]["message"]["content"]
|
| 40 |
+
except:
|
| 41 |
+
return "⚠️ API Response Error:\n" + str(reply)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# UI
|
| 45 |
ui = gr.Interface(
|
| 46 |
+
fn=lovable_agent,
|
| 47 |
+
inputs=gr.Textbox(label="Ask anything", placeholder="Ex: Generate YouTube strategy..."),
|
| 48 |
+
outputs=gr.Textbox(label="Lovable Agent Output"),
|
| 49 |
+
title="❤️ Open Lovable — Agentic Intelligence",
|
| 50 |
+
description="Gemini + Firecrawl powered research agent"
|
| 51 |
)
|
| 52 |
|
| 53 |
+
ui.launch()
|