nischaypar commited on
Commit
e35f056
Β·
verified Β·
1 Parent(s): 43d44da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -1,6 +1,9 @@
 
 
1
  import gradio as gr
 
2
  from tool import LinkupSearchTool
3
- from pathlib import Path
4
 
5
  def run_search(query, depth, api_key):
6
  if not query.strip() or not depth or not api_key.strip():
@@ -12,21 +15,28 @@ def run_search(query, depth, api_key):
12
  except Exception as e:
13
  return f"❌ Error: {str(e)}"
14
 
 
15
  def enable_submit(q, d, k):
16
  return gr.Button.update(interactive=bool(q.strip() and d and k.strip()))
17
 
 
18
  def load_readme():
19
  path = Path(__file__).parent / "README.md"
20
- if path.exists():
21
- return path.read_text()
22
 
23
  lines = path.read_text().splitlines()
24
- if lines[0].strip() == "---":
25
- end_index = next((i for i, line in enumerate(lines[1:], 1) if line.strip() == "---"), -1)
 
 
 
 
26
  if end_index != -1:
27
- lines = lines[end_index + 1:] # Skip frontmatter
28
  return "\n".join(lines)
29
 
 
30
  with gr.Blocks(title="Linkup Web Search Tool") as demo:
31
  gr.Markdown(
32
  """
@@ -55,7 +65,9 @@ with gr.Blocks(title="Linkup Web Search Tool") as demo:
55
  )
56
 
57
  search_btn = gr.Button("πŸ” Search", interactive=True)
58
- output = gr.Markdown("πŸ’¬ *Enter a query and click Search to begin.*", elem_id="output")
 
 
59
 
60
  search_btn.click(
61
  fn=run_search,
@@ -64,9 +76,15 @@ with gr.Blocks(title="Linkup Web Search Tool") as demo:
64
  show_progress=True,
65
  )
66
 
67
- query_input.input(enable_submit, [query_input, depth_input, api_key_input], [search_btn])
68
- depth_input.input(enable_submit, [query_input, depth_input, api_key_input], [search_btn])
69
- api_key_input.input(enable_submit, [query_input, depth_input, api_key_input], [search_btn])
 
 
 
 
 
 
70
 
71
  gr.Markdown("---")
72
  gr.Markdown("## πŸ“„ Tool Documentation")
 
1
+ from pathlib import Path
2
+
3
  import gradio as gr
4
+
5
  from tool import LinkupSearchTool
6
+
7
 
8
  def run_search(query, depth, api_key):
9
  if not query.strip() or not depth or not api_key.strip():
 
15
  except Exception as e:
16
  return f"❌ Error: {str(e)}"
17
 
18
+
19
  def enable_submit(q, d, k):
20
  return gr.Button.update(interactive=bool(q.strip() and d and k.strip()))
21
 
22
+
23
  def load_readme():
24
  path = Path(__file__).parent / "README.md"
25
+ if not path.exists():
26
+ return "README.md not found."
27
 
28
  lines = path.read_text().splitlines()
29
+
30
+ # Strip frontmatter if present
31
+ if lines and lines[0].strip() == "---":
32
+ end_index = next(
33
+ (i for i, line in enumerate(lines[1:], 1) if line.strip() == "---"), -1
34
+ )
35
  if end_index != -1:
36
+ lines = lines[end_index + 1 :] # skip frontmatter block
37
  return "\n".join(lines)
38
 
39
+
40
  with gr.Blocks(title="Linkup Web Search Tool") as demo:
41
  gr.Markdown(
42
  """
 
65
  )
66
 
67
  search_btn = gr.Button("πŸ” Search", interactive=True)
68
+ output = gr.Markdown(
69
+ "πŸ’¬ *Enter a query and click Search to begin.*", elem_id="output"
70
+ )
71
 
72
  search_btn.click(
73
  fn=run_search,
 
76
  show_progress=True,
77
  )
78
 
79
+ query_input.input(
80
+ enable_submit, [query_input, depth_input, api_key_input], [search_btn]
81
+ )
82
+ depth_input.input(
83
+ enable_submit, [query_input, depth_input, api_key_input], [search_btn]
84
+ )
85
+ api_key_input.input(
86
+ enable_submit, [query_input, depth_input, api_key_input], [search_btn]
87
+ )
88
 
89
  gr.Markdown("---")
90
  gr.Markdown("## πŸ“„ Tool Documentation")