Spaces:
Runtime error
Runtime error
# app.py | |
import gradio as gr | |
from search import search_google | |
from scraper import scrape_url | |
from rag import VectorStore | |
from llm import generate_answer | |
vs = VectorStore() | |
def ask_agent(question): | |
urls = search_google(question, num_results=3) | |
texts = [scrape_url(url) for url in urls] | |
vs.add_texts(texts) | |
relevant = vs.retrieve(question, top_k=2) | |
context = "\n\n".join(relevant) | |
answer = generate_answer(context, question) | |
return f"## π§ Answer\n\n{answer}\n\n---\n### π Sources\n" + "\n".join(f"- [{url}]({url})" for url in urls) | |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue")) as demo: | |
gr.Markdown(""" | |
# π **AI Web RAG Agent** | |
_Ask anything, I'll search, scrape & answer in real time!_ | |
""") | |
with gr.Column(scale=1): | |
question = gr.Textbox( | |
label="π‘ Your question", | |
placeholder="e.g., Find cheapest flights Kanpur to Mumbai on 30 July", | |
show_label=True, | |
scale=1 | |
) | |
btn = gr.Button("π Ask") | |
output = gr.Markdown("π€ *Your answer will appear here...*") | |
# Examples help new users | |
gr.Examples( | |
examples=[ | |
"Best laptop under 50,000 INR", | |
"Latest news about ISRO moon mission", | |
"What are some tourist places near Mumbai" | |
], | |
inputs=[question] | |
) | |
btn.click(fn=ask_agent, inputs=question, outputs=output) | |
demo.launch() |