NER_Demo / app.py
Shaffique Aljoofri
Update app.py
e033fcf
raw
history blame contribute delete
909 Bytes
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()