Spaces:
Runtime error
Runtime error
Charles Azam
commited on
Commit
·
915df4b
1
Parent(s):
0159aaf
feat: add gradio tools
Browse files- data/figure.png +0 -0
- gradio_app.py +1 -47
- src/deepengineer/backend/gradio_tools.py +49 -0
- tests/deepsearch/test_main_agent.py +9 -1
data/figure.png
CHANGED
|
|
gradio_app.py
CHANGED
|
@@ -1,52 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from deepengineer.deepsearch.main_agent import main_search
|
| 4 |
|
| 5 |
-
|
| 6 |
-
# ---------- 4. Wrapper that streams -------------------------
|
| 7 |
-
def run_agent_stream(user_input: str):
|
| 8 |
-
"""
|
| 9 |
-
Generator wired to Gradio:
|
| 10 |
-
– starts the agent in a background thread
|
| 11 |
-
– while the agent runs, flushes anything that tools
|
| 12 |
-
have pushed into `log_queue`
|
| 13 |
-
– finally yields the agent’s answer
|
| 14 |
-
Yields tuples: (agent_output, log_output)
|
| 15 |
-
"""
|
| 16 |
-
log_queue = queue.Queue()
|
| 17 |
-
|
| 18 |
-
# empty queue before each run
|
| 19 |
-
while not log_queue.empty():
|
| 20 |
-
log_queue.get_nowait()
|
| 21 |
-
|
| 22 |
-
answer_container = {"text": None}
|
| 23 |
-
done = threading.Event()
|
| 24 |
-
|
| 25 |
-
def _worker():
|
| 26 |
-
answer_container["text"] = main_search(user_input, log_queue)
|
| 27 |
-
done.set()
|
| 28 |
-
|
| 29 |
-
threading.Thread(target=_worker, daemon=True).start()
|
| 30 |
-
|
| 31 |
-
# stream logs until the agent finishes
|
| 32 |
-
log_buffer = ""
|
| 33 |
-
while not done.is_set() or not log_queue.empty():
|
| 34 |
-
while not log_queue.empty():
|
| 35 |
-
log_line = log_queue.get()
|
| 36 |
-
log_buffer += log_line + "\n"
|
| 37 |
-
# keep agent_output None until we have the final answer
|
| 38 |
-
yield (None, log_buffer.rstrip())
|
| 39 |
-
time.sleep(0.1)
|
| 40 |
-
|
| 41 |
-
# one last flush in case something arrived after last poll
|
| 42 |
-
while not log_queue.empty():
|
| 43 |
-
log_line = log_queue.get()
|
| 44 |
-
log_buffer += log_line + "\n"
|
| 45 |
-
|
| 46 |
-
# final yield: agent_output filled, log_output frozen
|
| 47 |
-
yield (answer_container["text"], log_buffer.rstrip())
|
| 48 |
-
|
| 49 |
-
# ---------- 5. Gradio UI ------------------------------------
|
| 50 |
with gr.Blocks() as demo:
|
| 51 |
gr.Markdown("# Agent Interface with Real‑Time Tool Logging")
|
| 52 |
user_input = gr.Textbox(label="User Message")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from deepengineer.backend.gradio_tools import run_agent_stream
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
with gr.Blocks() as demo:
|
| 5 |
gr.Markdown("# Agent Interface with Real‑Time Tool Logging")
|
| 6 |
user_input = gr.Textbox(label="User Message")
|
src/deepengineer/backend/gradio_tools.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import threading
|
| 2 |
+
import time
|
| 3 |
+
import queue
|
| 4 |
+
|
| 5 |
+
from deepengineer.deepsearch.main_agent import main_search
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def run_agent_stream(user_input: str):
|
| 9 |
+
"""
|
| 10 |
+
Generator wired to Gradio:
|
| 11 |
+
– starts the agent in a background thread
|
| 12 |
+
– while the agent runs, flushes anything that tools
|
| 13 |
+
have pushed into `log_queue`
|
| 14 |
+
– finally yields the agent’s answer
|
| 15 |
+
Yields tuples: (agent_output, log_output)
|
| 16 |
+
"""
|
| 17 |
+
log_queue = queue.Queue()
|
| 18 |
+
|
| 19 |
+
# empty queue before each run
|
| 20 |
+
while not log_queue.empty():
|
| 21 |
+
print("Emptying log queue")
|
| 22 |
+
log_queue.get_nowait()
|
| 23 |
+
|
| 24 |
+
answer_container = {"text": None}
|
| 25 |
+
done = threading.Event()
|
| 26 |
+
|
| 27 |
+
def _worker():
|
| 28 |
+
answer_container["text"] = main_search(user_input, log_queue)
|
| 29 |
+
done.set()
|
| 30 |
+
|
| 31 |
+
threading.Thread(target=_worker, daemon=True).start()
|
| 32 |
+
|
| 33 |
+
# stream logs until the agent finishes
|
| 34 |
+
log_buffer = ""
|
| 35 |
+
while not done.is_set() or not log_queue.empty():
|
| 36 |
+
while not log_queue.empty():
|
| 37 |
+
log_line = log_queue.get()
|
| 38 |
+
log_buffer += log_line + "\n"
|
| 39 |
+
# keep agent_output None until we have the final answer
|
| 40 |
+
yield (None, log_buffer.rstrip())
|
| 41 |
+
time.sleep(0.1)
|
| 42 |
+
|
| 43 |
+
# one last flush in case something arrived after last poll
|
| 44 |
+
while not log_queue.empty():
|
| 45 |
+
log_line = log_queue.get()
|
| 46 |
+
log_buffer += log_line + "\n"
|
| 47 |
+
|
| 48 |
+
# final yield: agent_output filled, log_output frozen
|
| 49 |
+
yield (answer_container["text"], log_buffer.rstrip())
|
tests/deepsearch/test_main_agent.py
CHANGED
|
@@ -1,12 +1,20 @@
|
|
| 1 |
-
from deepengineer.deepsearch.main_agent import main_search
|
| 2 |
import queue
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
def test_main_agent():
|
| 6 |
log_queue = queue.Queue()
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
main_search(
|
| 9 |
task="""
|
| 10 |
Search a paper called "High Energy Physics Opportunities Using Reactor Antineutrinos" on arXiv, download it and extract the table of contents
|
| 11 |
""", log_queue=log_queue
|
| 12 |
)
|
|
|
|
|
|
|
|
|
| 1 |
import queue
|
| 2 |
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from deepengineer.deepsearch.main_agent import main_search
|
| 6 |
|
| 7 |
+
|
| 8 |
+
@pytest.mark.skip(reason="This test is very long to run")
|
| 9 |
def test_main_agent():
|
| 10 |
log_queue = queue.Queue()
|
| 11 |
+
while not log_queue.empty():
|
| 12 |
+
print("Emptying log queue")
|
| 13 |
+
log_queue.get_nowait()
|
| 14 |
|
| 15 |
main_search(
|
| 16 |
task="""
|
| 17 |
Search a paper called "High Energy Physics Opportunities Using Reactor Antineutrinos" on arXiv, download it and extract the table of contents
|
| 18 |
""", log_queue=log_queue
|
| 19 |
)
|
| 20 |
+
|