Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -55,7 +55,7 @@ def check_rate_limit(request: gr.Request):
|
|
55 |
|
56 |
# ----------------- JigsawStack API Wrappers ------------------
|
57 |
|
58 |
-
def web_ai_search(query, ai_overview, safe_search, spell_check,
|
59 |
rate_limit_ok, rate_limit_msg = check_rate_limit(request)
|
60 |
if not rate_limit_ok:
|
61 |
return f"❌ {rate_limit_msg}", "", [], ""
|
@@ -66,18 +66,17 @@ def web_ai_search(query, ai_overview, safe_search, spell_check, deep_research, m
|
|
66 |
"query": query.strip(),
|
67 |
"ai_overview": ai_overview,
|
68 |
"safe_search": safe_search,
|
69 |
-
"spell_check": spell_check
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
config["target_output_tokens"] = target_output_tokens
|
80 |
-
payload["deep_research_config"] = config
|
81 |
try:
|
82 |
response = requests.post(f"{BASE_URL}/web/search", headers=headers, json=payload)
|
83 |
if response.status_code != 200:
|
@@ -114,8 +113,7 @@ with gr.Blocks() as demo:
|
|
114 |
ai_overview = gr.Checkbox(label="AI Overview", value=True)
|
115 |
safe_search = gr.Dropdown(choices=["moderate", "strict", "off"], value="moderate", label="Safe Search")
|
116 |
spell_check = gr.Checkbox(label="Spell Check", value=True)
|
117 |
-
|
118 |
-
with gr.Group(visible=True) as deep_research_group:
|
119 |
max_depth = gr.Number(label="Max Depth", value=3, precision=0)
|
120 |
max_breadth = gr.Number(label="Max Breadth", value=3, precision=0)
|
121 |
max_output_tokens = gr.Number(label="Max Output Tokens", value=32000, precision=0)
|
@@ -129,12 +127,10 @@ with gr.Blocks() as demo:
|
|
129 |
search_json_box = gr.Accordion("Raw JSON Response", open=False)
|
130 |
with search_json_box:
|
131 |
search_json_output = gr.Textbox(show_label=False, lines=20, interactive=False)
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
return web_ai_search(query, overview, safe, spell, deep, d_depth, d_breadth, d_tokens, d_target, request)
|
137 |
-
search_btn.click(fn=on_search, inputs=[search_query, ai_overview, safe_search, spell_check, deep_research, max_depth, max_breadth, max_output_tokens, target_output_tokens],
|
138 |
outputs=[search_status, overview_box, results_box, search_json_output])
|
139 |
def clear_search():
|
140 |
return "", "", [], ""
|
|
|
55 |
|
56 |
# ----------------- JigsawStack API Wrappers ------------------
|
57 |
|
58 |
+
def web_ai_search(query, ai_overview, safe_search, spell_check, max_depth, max_breadth, max_output_tokens, target_output_tokens, request: gr.Request):
|
59 |
rate_limit_ok, rate_limit_msg = check_rate_limit(request)
|
60 |
if not rate_limit_ok:
|
61 |
return f"❌ {rate_limit_msg}", "", [], ""
|
|
|
66 |
"query": query.strip(),
|
67 |
"ai_overview": ai_overview,
|
68 |
"safe_search": safe_search,
|
69 |
+
"spell_check": spell_check,
|
70 |
+
"deep_research": True
|
71 |
}
|
72 |
+
config = {
|
73 |
+
"max_depth": max_depth if max_depth is not None else 3,
|
74 |
+
"max_breadth": max_breadth if max_breadth is not None else 3,
|
75 |
+
"max_output_tokens": max_output_tokens if max_output_tokens is not None else 32000
|
76 |
+
}
|
77 |
+
if target_output_tokens is not None and target_output_tokens != "":
|
78 |
+
config["target_output_tokens"] = target_output_tokens
|
79 |
+
payload["deep_research_config"] = config
|
|
|
|
|
80 |
try:
|
81 |
response = requests.post(f"{BASE_URL}/web/search", headers=headers, json=payload)
|
82 |
if response.status_code != 200:
|
|
|
113 |
ai_overview = gr.Checkbox(label="AI Overview", value=True)
|
114 |
safe_search = gr.Dropdown(choices=["moderate", "strict", "off"], value="moderate", label="Safe Search")
|
115 |
spell_check = gr.Checkbox(label="Spell Check", value=True)
|
116 |
+
with gr.Group() as deep_research_group:
|
|
|
117 |
max_depth = gr.Number(label="Max Depth", value=3, precision=0)
|
118 |
max_breadth = gr.Number(label="Max Breadth", value=3, precision=0)
|
119 |
max_output_tokens = gr.Number(label="Max Output Tokens", value=32000, precision=0)
|
|
|
127 |
search_json_box = gr.Accordion("Raw JSON Response", open=False)
|
128 |
with search_json_box:
|
129 |
search_json_output = gr.Textbox(show_label=False, lines=20, interactive=False)
|
130 |
+
|
131 |
+
def on_search(query, overview, safe, spell, d_depth, d_breadth, d_tokens, d_target, request: gr.Request):
|
132 |
+
return web_ai_search(query, overview, safe, spell, d_depth, d_breadth, d_tokens, d_target, request)
|
133 |
+
search_btn.click(fn=on_search, inputs=[search_query, ai_overview, safe_search, spell_check, max_depth, max_breadth, max_output_tokens, target_output_tokens],
|
|
|
|
|
134 |
outputs=[search_status, overview_box, results_box, search_json_output])
|
135 |
def clear_search():
|
136 |
return "", "", [], ""
|