SergeyO7 commited on
Commit
f77ea9d
·
verified ·
1 Parent(s): 3cdec54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -1,11 +1,9 @@
1
- import gradio as gr
2
- import os
3
- from smolagents import InferenceClientModel, CodeAgent, MCPClient
4
-
5
  from mcp import ClientSession
6
  from mcp.client.sse import sse_client
 
7
  import asyncio
8
 
 
9
  async def run(date_input) -> str:
10
  async with sse_client(url="https://sergeyo7-garden-magus-mcp.hf.space/gradio_api/mcp/sse") as streams:
11
  async with ClientSession(*streams) as session:
@@ -25,25 +23,19 @@ async def run(date_input) -> str:
25
  return result.content[0].text # pyright: ignore[reportAttributeAccessIssue]
26
 
27
 
28
- try:
29
- mcp_client = MCPClient(
30
- {"url": "https://sergeyo7-garden-magus-mcp.hf.space/gradio_api/mcp/sse"}
31
- )
32
- tools = mcp_client.get_tools()
33
-
34
- model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
35
- agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
36
-
37
- demo = gr.ChatInterface(
38
- fn=run, history: str(agent.run(message)),
39
- type="messages",
40
- examples=["Analyze the sentiment of the following text 'This is awesome'"],
41
- title="Agent with MCP Tools",
42
- description="This is a simple agent that uses MCP tools to answer questions.",
43
- )
44
-
45
  demo.launch()
46
- finally:
47
- mcp_client.disconnect()
48
-
49
-
 
 
 
 
 
1
  from mcp import ClientSession
2
  from mcp.client.sse import sse_client
3
+ import gradio as gr
4
  import asyncio
5
 
6
+
7
  async def run(date_input) -> str:
8
  async with sse_client(url="https://sergeyo7-garden-magus-mcp.hf.space/gradio_api/mcp/sse") as streams:
9
  async with ClientSession(*streams) as session:
 
23
  return result.content[0].text # pyright: ignore[reportAttributeAccessIssue]
24
 
25
 
26
+ demo = gr.Interface(
27
+ fn=run,
28
+ inputs=gr.DateTime(
29
+ label="Date and Time",
30
+ type="datetime", # Explicitly set to return datetime object
31
+ timezone="UTC"
32
+ ),
33
+ outputs=gr.Textbox(),
34
+ title="Garden Magus",
35
+ description="Enter date and time to calculate Moon's position and phase, fertility and pruning indices."
36
+ )
37
+
38
+ # Launch the interface
39
+ if __name__ == "__main__":
 
 
 
40
  demo.launch()
41
+ # asyncio.run(run())