File size: 2,678 Bytes
f9f4d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16a729a
f9f4d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16a729a
 
 
f9f4d6d
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import asyncio

import gradio as gr
import nest_asyncio
from huggingface_hub import login

from src.agent_hackathon.consts import PROJECT_ROOT_DIR
from src.agent_hackathon.logger import get_logger
from src.agent_hackathon.multiagent import MultiAgentWorkflow

nest_asyncio.apply()

logger = get_logger(log_name="multiagent", log_dir=PROJECT_ROOT_DIR / "logs")

PRIMARY_HEADING = """# ML Topics Deep Research"""
SECONDARY_HEADING = """### This multi agent framework queries a DB containing arxiv ML research papers from Jan 2020 - Jun 6th 2025 for select categories, and finds events/conferences related to the user's query.

For more details on the filtered arxiv ds refer [here](https://huggingface.co/datasets/Shamik/arxiv_cs_2020_07_2025)
"""
workflow = MultiAgentWorkflow()

_login_done = False


def run(
    query: str, api_key: str, chat_history: list[dict[str, str | None]]
) -> tuple[str,list[dict[str, str | None]]] | None:
    global _login_done
    if not api_key or not api_key.startswith("hf"):
        raise ValueError("Incorrect HuggingFace Inference API Key")
    if not _login_done:
        login(token=api_key)
        _login_done = True
    try:
        result = asyncio.run(workflow.run(user_query=query))
        chat_history.append({"role": "user", "content": query})
        chat_history.append({"role": "assistant", "content": result})
        return "", chat_history
    except Exception as err:
        logger.error(f"Error during workflow execution: {err}")
        return None


with gr.Blocks(fill_height=True) as demo:
    gr.Markdown(value=PRIMARY_HEADING)
    gr.Markdown(value=SECONDARY_HEADING)
    gr.Markdown(
        value="""<span style="color:red"> Please use a πŸ€— Inference API Key </span>"""
    )
    api_key = gr.Textbox(
        placeholder="Enter your HuggingFace Inference API KEY HERE",
        label="πŸ€— Inference API Key",
        show_label=True,
        type="password",
    )
    chatbot = gr.Chatbot(
        type="messages", label="DeepResearch", show_label=True, height=500,
        show_copy_all_button=True, show_copy_button=True
    )
    msg = gr.Textbox(
        placeholder="Type your message here and press enter...",
        show_label=True,
        label="Input",
        submit_btn=True,
        stop_btn=True,
    )
    clear = gr.ClearButton(components=[msg, chatbot])
    msg.submit(fn=run, inputs=[msg, api_key, chatbot], outputs=[msg, chatbot])

    demo.queue(max_size=1).launch(share=False)

# if __name__ == "__main__":
#     demo.queue(max_size=1).launch(share=False)


# example queries
# tell me about reinforcement learning in robotics
# give me event details on reinforcement learning & robotics