# Transformers Agent

**URL:** <https://discuss.huggingface.co/t/transformers-agent/39566>\
**Category:** 🤗Transformers\
**Created:** [May 11, 2023, 5:08pm UTC](https://discuss.huggingface.co/t/transformers-agent/39566 "2023-05-11T17:08:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ifeanyi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ifeanyi/32/16066_2.png) [@Ifeanyi](https://discuss.huggingface.co/u/Ifeanyi)\
**Post date:** [May 11, 2023, 5:08pm UTC](https://discuss.huggingface.co/t/transformers-agent/39566/1 "2023-05-11T17:08:24Z")

</div>

Hello, I am experimenting with the new Transformer Agents, and I wrote the following script, which I copied from an example:

```auto

# load tools
from transformers.tools import HfAgent
import textract

# load sample pdf document
text = textract.process("/content/sample_data/TechNation.pdf").decode("utf-8")

# create agent
agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")

# instruct agent
agent.run("What is `text` about?", text=text)

```

But I get the following error when I run my script:

```auto
ValueError Traceback (most recent call last)
<ipython-input-25-9fe5f4eb9747> in <cell line: 2>()
      1 # instruct agent
----> 2 agent.run("What is `text` about?", text=text)

1 frames
/usr/local/lib/python3.10/dist-packages/transformers/tools/agents.py in generate_one(self, prompt, stop)
    486 return self._generate_one(prompt)
    487 elif response.status_code != 200:
--> 488 raise ValueError(f"Error {response.status_code}: {response.json()}")
    489 
    490 result = response.json()[0]["generated_text"]

ValueError: Error 400: {'error': 'Authorization header is correct, but the token seems invalid'}

```

Please, what can I do about it? Thanks!

---

<div class="post-metadata">

**Author:** ![ch4db0t](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ch4db0t/32/16098_2.png) [@ch4db0t](https://discuss.huggingface.co/u/ch4db0t)\
**Post date:** [May 12, 2023, 9:02pm UTC](https://discuss.huggingface.co/t/transformers-agent/39566/2 "2023-05-12T21:02:44Z")

</div>

```auto
from huggingface_hub import login
#Do this before HfAgent() and it should work
login("<your HF token>")

```

🤗

---

<div class="post-metadata">

**Author:** ![Ifeanyi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ifeanyi/32/16066_2.png) [@Ifeanyi](https://discuss.huggingface.co/u/Ifeanyi)\
**Post date:** [May 15, 2023, 2:08pm UTC](https://discuss.huggingface.co/t/transformers-agent/39566/3 "2023-05-15T14:08:06Z")

</div>

Hi, thanks for offering your suggestion, which worked. Thanks again! However, while the code runs without breaking, I am being asked to define “labels” in my code. I guess I have not defined the right tool for the task. I am doing a document search, but I do not find where in the Transformer Agents docs that explains how to define labels. Please, I would appreciate it if you point me in the right direction. Thanks!
