Shaffique Aljoofri commited on
Commit
e194444
·
1 Parent(s): 60a647c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ hf_api_url = os.environ('HF_API_URL')
4
+ hf_api_key = os.environ('HF_API_KEY')
5
+
6
+ ### Helper Functions
7
+ import requests, json
8
+
9
+ headers = {
10
+ "Authorization": f"Bearer {hf_api_key}",
11
+ "Content-Type": "application/json"
12
+ }
13
+
14
+ def get_completion(inputs, parameters = None):
15
+
16
+ payload = {"inputs" : inputs}
17
+
18
+ if paramaters is not None:
19
+ payload.update({"parameters" : parameters})
20
+
21
+ response = requests.post(hf_api_url, headers = headers, data = json.dumps(payload))
22
+
23
+ return json.loads(response.content.decode("utf-8"))
24
+
25
+ ### Gradio App
26
+ import gradio as gr
27
+
28
+ def ner(text):
29
+ output = ner_pipeline(text)
30
+ return {"text": text, "entities": output}
31
+
32
+ examples = [
33
+ "Does Chicago have any stores and does Joe live here?",
34
+ ]
35
+
36
+ demo = gr.Interface(fn = ner,
37
+ inputs = gr.Textbox(placeholder="Enter sentence here..."),
38
+ outputs = gr.HighlightedText(),
39
+ examples = examples)
40
+
41
+ demo.launch()