nitinbhayana commited on
Commit
a15b3bb
·
verified ·
1 Parent(s): 915ddda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -21,14 +21,18 @@ def main():
21
  import requests
22
 
23
 
 
 
 
24
 
25
- # def query(payload):
26
- # response = requests.post(API_URL, headers=headers, json=payload)
27
- # return response.json()
28
 
29
- from transformers import pipeline
 
 
30
 
31
- pipe = pipeline("text-generation", model="shivanikerai/TinyLlama-1.1B-Chat-v1.0-sku-title-ner-generation-reversed-v1.0")
 
 
32
 
33
 
34
 
@@ -39,12 +43,12 @@ def ner_title(title):
39
  B_in, E_in = "[Title]", "[/Title]"
40
  # Format your prompt template
41
  prompt = f"""{B_INST} {B_SYS} You are a helpful assistant that provides accurate and concise responses. {E_SYS}\nExtract named entities from the given product title. Provide the output in JSON format.\n{B_in} {title.strip()} {E_in}\n{E_INST}\n\n### NER Response:\n{{"{title.split()[0].lower()}"""
42
- # output = query({
43
- # "inputs": prompt,
44
- # })
45
 
46
- return eval(pipe(text)[0]["generated_text"].split("### NER Response:\n")[-1])
47
- #return(eval(output[0]['generated_text'].split("### NER Response:\n")[-1]))
48
  # def ner_title(title):
49
  # word_list = title.split()
50
  # indexed_dict = {index: word for index, word in enumerate(word_list)}
 
21
  import requests
22
 
23
 
24
+ API_URL = "https://api-inference.huggingface.co/models/shivanikerai/TinyLlama-1.1B-Chat-v1.0-sku-title-ner-generation-reversed-v1.0"
25
+ TOKEN = os.environ.get("HUGGING_FACE_TOKEN")
26
+ headers = {"Authorization": f"Bearer {TOKEN}"}
27
 
 
 
 
28
 
29
+ def query(payload):
30
+ response = requests.post(API_URL, headers=headers, json=payload)
31
+ return response.json()
32
 
33
+ # from transformers import pipeline
34
+
35
+ # pipe = pipeline("text-generation", model="shivanikerai/TinyLlama-1.1B-Chat-v1.0-sku-title-ner-generation-reversed-v1.0")
36
 
37
 
38
 
 
43
  B_in, E_in = "[Title]", "[/Title]"
44
  # Format your prompt template
45
  prompt = f"""{B_INST} {B_SYS} You are a helpful assistant that provides accurate and concise responses. {E_SYS}\nExtract named entities from the given product title. Provide the output in JSON format.\n{B_in} {title.strip()} {E_in}\n{E_INST}\n\n### NER Response:\n{{"{title.split()[0].lower()}"""
46
+ output = query({
47
+ "inputs": prompt,
48
+ })
49
 
50
+ #return eval(pipe(text)[0]["generated_text"].split("### NER Response:\n")[-1])
51
+ return(eval(output[0]['generated_text'].split("### NER Response:\n")[-1]))
52
  # def ner_title(title):
53
  # word_list = title.split()
54
  # indexed_dict = {index: word for index, word in enumerate(word_list)}