gaur3009 commited on
Commit
82957ca
Β·
verified Β·
1 Parent(s): 622f41b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from search import search_google
3
  from scraper import scrape_url
@@ -7,25 +8,42 @@ from llm import generate_answer
7
  vs = VectorStore()
8
 
9
  def ask_agent(question):
10
- # Step 1: search
11
  urls = search_google(question, num_results=3)
12
- # Step 2: scrape
13
  texts = [scrape_url(url) for url in urls]
14
- # Step 3: embed + store
15
  vs.add_texts(texts)
16
- # Step 4: retrieve
17
  relevant = vs.retrieve(question, top_k=2)
18
  context = "\n\n".join(relevant)
19
- # Step 5: generate answer
20
  answer = generate_answer(context, question)
21
- return f"### 🧠 Answer:\n{answer}\n\n\n### πŸ”— Sources:\n" + "\n".join(urls)
22
-
23
- with gr.Blocks() as demo:
24
- gr.Markdown("# πŸ” AI Web RAG Agent\nAsk me anything; I'll search, scrape and answer!")
25
- with gr.Row():
26
- inp = gr.Textbox(label="Your question")
27
- out = gr.Markdown()
28
- btn = gr.Button("Ask")
29
- btn.click(fn=ask_agent, inputs=inp, outputs=out)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  demo.launch()
 
1
+ # app.py
2
  import gradio as gr
3
  from search import search_google
4
  from scraper import scrape_url
 
8
  vs = VectorStore()
9
 
10
  def ask_agent(question):
 
11
  urls = search_google(question, num_results=3)
 
12
  texts = [scrape_url(url) for url in urls]
 
13
  vs.add_texts(texts)
 
14
  relevant = vs.retrieve(question, top_k=2)
15
  context = "\n\n".join(relevant)
 
16
  answer = generate_answer(context, question)
17
+ return f"## 🧠 Answer\n\n{answer}\n\n---\n### πŸ”— Sources\n" + "\n".join(f"- [{url}]({url})" for url in urls)
18
+
19
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue")) as demo:
20
+ gr.Markdown("""
21
+ # πŸ” **AI Web RAG Agent**
22
+ _Ask anything, I'll search, scrape & answer in real time!_
23
+ """)
24
+
25
+ with gr.Column(scale=1):
26
+ question = gr.Textbox(
27
+ label="πŸ’‘ Your question",
28
+ placeholder="e.g., Find cheapest flights Kanpur to Mumbai on 30 July",
29
+ show_label=True,
30
+ scale=1
31
+ )
32
+
33
+ btn = gr.Button("πŸš€ Ask")
34
+
35
+ output = gr.Markdown("πŸ€– *Your answer will appear here...*")
36
+
37
+ # Examples help new users
38
+ gr.Examples(
39
+ examples=[
40
+ "Best laptop under 50,000 INR",
41
+ "Latest news about ISRO moon mission",
42
+ "What are some tourist places near Mumbai"
43
+ ],
44
+ inputs=[question]
45
+ )
46
+
47
+ btn.click(fn=ask_agent, inputs=question, outputs=output)
48
 
49
  demo.launch()