I have followed a lesson correctly but whenever I run it, it comes up with an error message

Does it have something to do with the CPU and if so how can i fix it

Current behavior:
giving an error message after running.

Desired behavior
it should run and provide a link to a GPT-2 language model

Repl link:

code snippet

can you show the error message

1 Like
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    inference = InferenceApi(repo_id="gpt2-large", token=API_Token)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/huggingface_hub/inference_api.py", line 124, in __init__
    model_info = HfApi(token=token).model_info(repo_id=repo_id)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1625, in model_info
    r = requests.get(path, headers=headers, timeout=timeout, params=params)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/sessions.py", line 573, in request
    prep = self.prepare_request(req)
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/sessions.py", line 484, in prepare_request
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/models.py", line 369, in prepare
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/models.py", line 491, in prepare_headers
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/utils.py", line 1043, in check_header_validity
    _validate_header_part(value, "value", HEADER_VALIDATORS[type(value)][1])
  File "/home/runner/Day-2/venv/lib/python3.10/site-packages/requests/utils.py", line 1048, in _validate_header_part
    raise InvalidHeader(
requests.exceptions.InvalidHeader: Invalid leading whitespace, reserved character(s), or returncharacter(s) in header value: 'Bearer import gradio as gr\n\ndef hello(input):\n   \n   return "Hello " + input + "!"\n\ndemo = gr.Interface(fn=hello, inputs="text", outputs="text")\n\ndemo.launch(debug=True, share=True)'

dang I think that’s an error with the package… What’s basically happening is that they are sending bad “code” (headers) to the hugging face “API,” this is a package problem. Sorry, nothing you can do as far as I can tell other than edit the package. If this solved your problem, even if it’s not satisfying lol, please mark as solved

how could i edit the package

I don’t really know what’s wrong lol

Does token or repo_id have a space at the beginning, by chance?

no there’s no spaces