Spaces:
Sleeping
Sleeping
File size: 1,399 Bytes
4b42f38 ea9aafe 38812af 4b42f38 3f18472 38812af 4b42f38 b7d44c8 4b42f38 47e2986 38812af 9a62fc6 ea9aafe 4b42f38 ea9aafe 4b42f38 3f18472 501c4dc 4b42f38 | 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 | from llama_index.core.agent.workflow import AgentWorkflow
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
from llama_index.core.workflow import Context
# Import our custom tools from their modules
from tools import get_weather_info_tool, get_hub_stats_tool, search_tool
from retriever import guest_info_tool
import gradio as gr
import asyncio
llm = HuggingFaceInferenceAPI(model_name='Qwen/Qwen2.5-Coder-32B-Instruct')
alfred = AgentWorkflow.from_tools_or_functions(
tools_or_functions=[
get_weather_info_tool,
get_hub_stats_tool,
search_tool,
guest_info_tool
],
llm=llm,
verbose=True,
)
ctx = Context(alfred)
# Define a function to interact with the AgentWorkflow
async def async_interact_with_agent(input_text, ctx=ctx):
response = await alfred.run(input_text, ctx=ctx)
return response
def interact_with_agent(input_text):
# Ensure the async function is run in an event loop
return asyncio.run(async_interact_with_agent(input_text))
if __name__ == "__main__":
# Create a Gradio interface
interface = gr.Interface(
fn=interact_with_agent,
inputs=gr.Textbox(label="Enter your query"),
outputs=gr.Textbox(label="Response"),
title="Agent Workflow Interface",
description="Interact with the AgentWorkflow using this Gradio interface."
)
interface.launch()
|