Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,20 +19,20 @@ def main():
|
|
19 |
submit_ner_keywords()
|
20 |
|
21 |
import requests
|
22 |
-
import os
|
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 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
|
37 |
|
38 |
|
@@ -43,12 +43,12 @@ def ner_title(title):
|
|
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 |
-
|
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)}
|
|
|
19 |
submit_ner_keywords()
|
20 |
|
21 |
import requests
|
22 |
+
# import os
|
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(prompt)[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)}
|