Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Hugginface API #11

Open
conceptofmind opened this issue Feb 23, 2023 · 1 comment
Open

Hugginface API #11

conceptofmind opened this issue Feb 23, 2023 · 1 comment

Comments

@conceptofmind
Copy link
Owner

'''
HuggingFace API

Uses HuggingFace's API to generate text.

input_query - A string, the input query (e.g. "what is a dog?")

output - A string, the generated text

API_TOKEN - your HuggingFace API token
'''
def HuggingfaceAPI(input_query: str):
    model_id = "gpt-neox-20b"
    API_TOKEN = "YOUR_API_TOKEN"
    API_URL = "https://api-inference.huggingface.co/models/{model_id}".format(model_id=model_id)
    headers = {"Authorization": f"Bearer {API_TOKEN}".format(API_TOKEN=API_TOKEN)}
    def query(payload):
        data = json.dumps(payload)
        response = requests.request("POST", API_URL, headers=headers, data=data)
        return json.loads(response.content.decode("utf-8"))
    data = query(input_query)
    return data[0]["generated_text"]
@conceptofmind
Copy link
Owner Author

Inception.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant