File size: 3,009 Bytes
ff8e6c8
 
 
 
 
 
 
 
 
 
 
8c03bb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cf2b92
8c03bb8
 
 
 
 
 
1cf2b92
8c03bb8
 
 
 
 
 
 
 
ff8e6c8
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Mcp Tiny Agent
emoji: πŸ“‰
colorFrom: pink
colorTo: blue
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
---

# MCP Tiny Agent with Sentiment Analysis

An AI agent built with smolagents that connects to an MCP sentiment analysis server.

## πŸš€ HuggingFace Space Deployment

### Quick Deploy

1. **Push to HuggingFace Space**
   ```bash
   git add .
   git commit -m "Deploy MCP Tiny Agent"
   git push
   ```

2. **Configure Secrets** (Required)
   - Go to your Space β†’ **Settings** β†’ **Secrets**
   - Add a new secret:
     - **Key**: `HF_TOKEN`
     - **Value**: Your HuggingFace token (get it from https://huggingface.co/settings/tokens)
   - Click **Save**

3. **The Space will automatically:**
   - Install dependencies from `requirements.txt`
   - Run `app.py`
   - Make the agent available at your Space URL

### HuggingFace Space Features

- βœ… **Automatic Token Access**: If you're the Space owner, `HF_TOKEN` is automatically available
- βœ… **Secrets Management**: Secure API key storage via Space Settings
- βœ… **Public Access**: Share your agent with others via Space URL
- βœ… **Auto-Deploy**: Updates automatically on git push

## πŸ’» Local Setup

### 1. Install Dependencies

```bash
pip install -r requirements.txt
```

### 2. Configure API Key

For Nebius provider, you need to set up authentication. Choose one of these methods:

**Option 1: Environment Variable (Recommended)**
```bash
# Windows PowerShell
$env:HF_TOKEN="your_huggingface_token_here"

# Windows CMD
set HF_TOKEN=your_huggingface_token_here

# Linux/Mac
export HF_TOKEN="your_huggingface_token_here"
```

**Option 2: HuggingFace CLI Login**
```bash
huggingface-cli login
```


### 3. Get Your HuggingFace Token

1. Go to https://huggingface.co/settings/tokens
2. Create a new token (read access is sufficient)
3. Copy the token and set it as an environment variable

### 4. Run the Application

```bash
python app.py
```

## ✨ Features

- **Sentiment Analysis**: Uses MCP sentiment analysis server to analyze text sentiment
- **Qwen 2.5 72B Model**: Powered by Qwen/Qwen2.5-72B-Instruct via HuggingFace Inference API
- **Gradio Interface**: User-friendly chat interface
- **Fallback Support**: Automatically falls back to TextBlob if MCP server is unavailable
- **Dual Deployment**: Works both locally and on HuggingFace Spaces

## πŸ”§ Model Configuration

The agent is configured to use `Qwen/Qwen2.5-72B-Instruct` via HuggingFace Inference API. 
If you hit rate limits, see the comments in `app.py` for alternative model configurations.

## πŸ“ Notes

- **HuggingFace Spaces**: The code automatically detects if it's running in a Space and uses the appropriate token
- **Local Development**: Set `HF_TOKEN` environment variable or use `huggingface-cli login`
- **Secrets**: Never commit API keys to git. Use Space Secrets for deployment or environment variables for local development

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference