Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,41 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import asyncio
|
| 4 |
-
from smolagents import
|
| 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 |
-
with gr.Blocks() as demo:
|
| 44 |
-
chatbot = gr.Chatbot()
|
| 45 |
-
user_input = gr.Textbox(placeholder="Ask Jobcy about remote jobs or anything else...", label="Your Message")
|
| 46 |
-
state = gr.State([])
|
| 47 |
-
|
| 48 |
-
user_input.submit(chat_with_agent, inputs=[user_input, state], outputs=[chatbot, state])
|
| 49 |
-
|
| 50 |
-
demo.title = "Jobcy Remote Job Search Assistant"
|
| 51 |
-
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import asyncio
|
| 4 |
+
from smolagents import CodeAgent, MCPClient, InferenceClientModel
|
| 5 |
+
|
| 6 |
+
async def main():
|
| 7 |
+
mcp_client = None
|
| 8 |
+
try:
|
| 9 |
+
# Initialize MCPClient for your MCP server
|
| 10 |
+
mcp_client = MCPClient({"url": "https://oppaai-job-search-mcp-server.hf.space/gradio_api/mcp/sse"})
|
| 11 |
+
|
| 12 |
+
# Fetch tools exposed by the MCP server
|
| 13 |
+
tools = await mcp_client.get_tools()
|
| 14 |
+
|
| 15 |
+
# Initialize the model with HF token from env
|
| 16 |
+
model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
|
| 17 |
+
|
| 18 |
+
# Create the agent with the fetched tools and model
|
| 19 |
+
agent = CodeAgent(tools=tools, model=model)
|
| 20 |
+
|
| 21 |
+
async def chat_with_agent(message, history):
|
| 22 |
+
history = history or []
|
| 23 |
+
result = await agent.run(message)
|
| 24 |
+
history.append((message, result))
|
| 25 |
+
return history, history
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
chatbot = gr.Chatbot()
|
| 29 |
+
user_input = gr.Textbox(placeholder="Ask Jobcy about remote jobs or anything else...", label="Your Message")
|
| 30 |
+
state = gr.State([])
|
| 31 |
+
|
| 32 |
+
user_input.submit(chat_with_agent, inputs=[user_input, state], outputs=[chatbot, state])
|
| 33 |
+
|
| 34 |
+
demo.title = "Jobcy Remote Job Search Assistant"
|
| 35 |
+
demo.launch()
|
| 36 |
+
finally:
|
| 37 |
+
if mcp_client:
|
| 38 |
+
await mcp_client.disconnect()
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
asyncio.run(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|