Spaces:
Sleeping
Sleeping
init
Browse files- .gradio/certificate.pem +31 -0
- __pycache__/server.cpython-311.pyc +0 -0
- client.py +29 -0
- mac.json +11 -0
- server.py +42 -0
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu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27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
__pycache__/server.cpython-311.pyc
ADDED
Binary file (1.54 kB). View file
|
|
client.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
from mcp import StdioServerParameters
|
5 |
+
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
|
6 |
+
|
7 |
+
|
8 |
+
try:
|
9 |
+
mcp_client = MCPClient(
|
10 |
+
{
|
11 |
+
"url": "http://localhost:7860/gradio_api/mcp/sse"
|
12 |
+
} # This is the MCP Server we created in the previous section
|
13 |
+
)
|
14 |
+
tools = mcp_client.get_tools()
|
15 |
+
|
16 |
+
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
17 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
18 |
+
|
19 |
+
demo = gr.ChatInterface(
|
20 |
+
fn=lambda message, history: str(agent.run(message)),
|
21 |
+
type="messages",
|
22 |
+
examples=["Prime factorization of 68"],
|
23 |
+
title="Agent with MCP Tools",
|
24 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
25 |
+
)
|
26 |
+
|
27 |
+
demo.launch()
|
28 |
+
finally:
|
29 |
+
mcp_client.disconnect()
|
mac.json
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mcpServers": {
|
3 |
+
"gradio": {
|
4 |
+
"command": "npx",
|
5 |
+
"args": [
|
6 |
+
"mcp-remote",
|
7 |
+
"http://localhost:7860/gradio_api/mcp/sse"
|
8 |
+
]
|
9 |
+
}
|
10 |
+
}
|
11 |
+
}
|
server.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> dict:
|
6 |
+
"""
|
7 |
+
Analyze the sentiment of the given text.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
text (str): The text to analyze
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
14 |
+
"""
|
15 |
+
blob = TextBlob(text)
|
16 |
+
sentiment = blob.sentiment
|
17 |
+
|
18 |
+
return {
|
19 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
20 |
+
"subjectivity": round(
|
21 |
+
sentiment.subjectivity, 2
|
22 |
+
), # 0 (objective) to 1 (subjective)
|
23 |
+
"assessment": (
|
24 |
+
"positive"
|
25 |
+
if sentiment.polarity > 0
|
26 |
+
else "negative" if sentiment.polarity < 0 else "neutral"
|
27 |
+
),
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
# Create the Gradio interface
|
32 |
+
demo = gr.Interface(
|
33 |
+
fn=sentiment_analysis,
|
34 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
35 |
+
outputs=gr.JSON(),
|
36 |
+
title="Text Sentiment Analysis",
|
37 |
+
description="Analyze the sentiment of text using TextBlob",
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the interface and MCP server
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch(mcp_server=True, share=True)
|