IPF commited on
Commit
0c1d8cd
·
verified ·
1 Parent(s): 986f38f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -16
app.py CHANGED
@@ -203,6 +203,11 @@ class SimpleBrowser:
203
  url = r.get('link', r.get('url', ''))
204
  snippet = html.escape(r.get('snippet', r.get('summary', '')))
205
 
 
 
 
 
 
206
  try:
207
  domain = url.split('/')[2] if url else ''
208
  except:
@@ -593,7 +598,7 @@ def render_tool_call(fn_name: str, args: dict, browser: SimpleBrowser = None) ->
593
  </div>
594
  </div>'''
595
 
596
- def render_tool_result(result: str, fn_name: str, browser: SimpleBrowser = None) -> str:
597
  """Render tool result in an expanded card with direct HTML rendering."""
598
  import uuid
599
  tool_label = {
@@ -739,20 +744,7 @@ def render_tool_result(result: str, fn_name: str, browser: SimpleBrowser = None)
739
  ref_num = parts_match.group(1)
740
  title = parts_match.group(2)
741
  domain = parts_match.group(3)
742
- # Default URL construction (fallback)
743
  url = f"https://{domain}" if not domain.startswith('http') else domain
744
-
745
- # If browser instance is available, try to get the full URL from link_map
746
- if browser and hasattr(browser, 'link_map'):
747
- try:
748
- idx = int(ref_num)
749
- if idx in browser.link_map:
750
- full_url = browser.link_map[idx].get('url')
751
- if full_url:
752
- url = full_url
753
- except:
754
- pass
755
-
756
  return f'<a href="{html.escape(url)}" target="_blank" style="background: #e0f7fa; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; color: #006064; font-weight: 500; text-decoration: none; display: inline-block;" title="{html.escape(title)}">【{ref_num}†{html.escape(domain)}】</a>'
757
  else:
758
  simple_match = re.match(r'【(\d+)†([^】]+)】', full_text)
@@ -965,7 +957,7 @@ async def run_agent_streaming(
965
  except Exception as e:
966
  result = f"Tool error: {str(e)}\n{traceback.format_exc()}"
967
 
968
- html_parts.append(render_tool_result(result, fn_name, browser))
969
  yield ''.join(html_parts)
970
 
971
  messages.append({
@@ -2574,4 +2566,4 @@ if __name__ == "__main__":
2574
  print("OpenResearcher DeepSearch Agent - ZeroGPU Space")
2575
  print("="*60)
2576
  demo = create_interface()
2577
- demo.queue(default_concurrency_limit=20).launch(server_name="127.0.0.1", server_port=8888, share=True)
 
203
  url = r.get('link', r.get('url', ''))
204
  snippet = html.escape(r.get('snippet', r.get('summary', '')))
205
 
206
+ try:
207
+ domain = url.split('/')[2] if url else ''
208
+ except:
209
+ domain = ''
210
+
211
  try:
212
  domain = url.split('/')[2] if url else ''
213
  except:
 
598
  </div>
599
  </div>'''
600
 
601
+ def render_tool_result(result: str, fn_name: str) -> str:
602
  """Render tool result in an expanded card with direct HTML rendering."""
603
  import uuid
604
  tool_label = {
 
744
  ref_num = parts_match.group(1)
745
  title = parts_match.group(2)
746
  domain = parts_match.group(3)
 
747
  url = f"https://{domain}" if not domain.startswith('http') else domain
 
 
 
 
 
 
 
 
 
 
 
 
748
  return f'<a href="{html.escape(url)}" target="_blank" style="background: #e0f7fa; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; color: #006064; font-weight: 500; text-decoration: none; display: inline-block;" title="{html.escape(title)}">【{ref_num}†{html.escape(domain)}】</a>'
749
  else:
750
  simple_match = re.match(r'【(\d+)†([^】]+)】', full_text)
 
957
  except Exception as e:
958
  result = f"Tool error: {str(e)}\n{traceback.format_exc()}"
959
 
960
+ html_parts.append(render_tool_result(result, fn_name))
961
  yield ''.join(html_parts)
962
 
963
  messages.append({
 
2566
  print("OpenResearcher DeepSearch Agent - ZeroGPU Space")
2567
  print("="*60)
2568
  demo = create_interface()
2569
+ demo.queue(default_concurrency_limit=20).launch()