| 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) |
|
|
| |
| |
|
|
|
|
| |
| |
| |