slimaneMakh commited on
Commit
99c2f4b
·
1 Parent(s): 53605e2
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -1,6 +1,11 @@
1
- import gradio as gr
2
  from textblob import TextBlob
3
 
 
 
 
 
 
 
4
  def sentiment_analysis(text: str) -> dict:
5
  """
6
  Analyze the sentiment of the given text.
@@ -20,14 +25,26 @@ def sentiment_analysis(text: str) -> dict:
20
  "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
21
  }
22
 
23
- # Create the Gradio interface
24
- demo = gr.Interface(
25
- fn=sentiment_analysis,
26
- inputs=gr.Textbox(placeholder="Enter text to analyze..."),
27
- outputs=gr.JSON(),
28
- title="Text Sentiment Analysis",
29
- description="Analyze the sentiment of text using TextBlob"
30
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Launch the interface and MCP server
33
  if __name__ == "__main__":
 
 
1
  from textblob import TextBlob
2
 
3
+ import gradio as gr
4
+
5
+ from mcp.client.stdio import StdioServerParameters
6
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection
7
+ from smolagents.mcp_client import MCPClient
8
+
9
  def sentiment_analysis(text: str) -> dict:
10
  """
11
  Analyze the sentiment of the given text.
 
25
  "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
26
  }
27
 
28
+
29
+
30
+ mcp_client = MCPClient(
31
+ {"url": "https://slimanemakh-mcp-course.hf.space/gradio_api/mcp/sse"}
 
 
 
32
  )
33
+ tools = mcp_client.get_tools()
34
+
35
+ model = InferenceClientModel()
36
+ agent = CodeAgent(tools=[*tools], model=model)
37
+
38
+
39
+ demo = gr.ChatInterface(
40
+ fn=lambda message, history: str(agent.run(message)),
41
+ type="messages",
42
+ examples=["Prime factorization of 68"],
43
+ title="Agent with MCP Tools",
44
+ description="This is a simple agent that uses MCP tools to answer questions.",
45
+ messages=[],
46
+ )
47
+
48
 
49
  # Launch the interface and MCP server
50
  if __name__ == "__main__":