File size: 909 Bytes
e194444 491b0fa e194444 9b46b44 e194444 e033fcf e194444 be7de0c e033fcf e194444 e033fcf e194444 e033fcf e194444 |
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 |
import os
hf_api_url = os.environ['HF_API_URL']
hf_api_key = os.environ['HF_API_KEY']
### Helper Functions
import requests, json
headers = {
"Authorization": f"Bearer {hf_api_key}",
"Content-Type": "application/json"
}
def get_completion(inputs, parameters = None):
payload = {"inputs" : inputs}
if parameters is not None:
payload.update({"parameters" : parameters})
response = requests.post(hf_api_url, headers = headers, data = json.dumps(payload))
return response.json()
### Gradio App
import gradio as gr
def ner(text):
output = get_completion(text)
return {"text" : text, "entities" : output}
examples = [
"Does Chicago have any stores and does Joe live here?"
]
demo = gr.Interface(ner,
gr.Textbox(placeholder="Enter sentence here..."),
gr.HighlightedText(),
examples = examples)
demo.launch() |