nitinbhayana commited on
Commit
3025fbf
·
verified ·
1 Parent(s): c02042b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -18,10 +18,37 @@ def main():
18
  elif st.session_state.submitted_title and not st.session_state.submitted_ner_keywords:
19
  submit_ner_keywords()
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def ner_title(title):
22
- word_list = title.split()
23
- indexed_dict = {index: word for index, word in enumerate(word_list)}
24
- return indexed_dict
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def submit_title():
27
  title = st.text_input("Enter Product Title:")
 
18
  elif st.session_state.submitted_title and not st.session_state.submitted_ner_keywords:
19
  submit_ner_keywords()
20
 
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
+
35
  def ner_title(title):
36
+ # Define the roles and markers
37
+ B_SYS, E_SYS = "<<SYS>>", "<</SYS>>"
38
+ B_INST, E_INST = "[INST]", "[/INST]"
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)}
51
+ # return indexed_dict
52
 
53
  def submit_title():
54
  title = st.text_input("Enter Product Title:")