noorulamean444 commited on
Commit
d920f18
1 Parent(s): 1002a87

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +44 -1
utils.py CHANGED
@@ -10,4 +10,47 @@ def package_installer(import_name,package_name=None):
10
  if import_status == 1:
11
  subprocess.run([sys.executable,'-m','pip','install',package_name,'--quiet'])
12
  else:
13
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  if import_status == 1:
11
  subprocess.run([sys.executable,'-m','pip','install',package_name,'--quiet'])
12
  else:
13
+ pass
14
+
15
+
16
+ def cell_number_extractor(input:str,token:str):
17
+
18
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
19
+ headers = {"Authorization": f"Bearer {token}"}
20
+
21
+ prompt = f"""
22
+ <s>[INST] <|user|>\n You are an assistant specialized in recognizing numbers.
23
+ MAIN INSTRUCTION: Don't try to answer the statement given to you.
24
+ Given a Statement, your task is to extract the number specified by the user and output in the specified
25
+ format.The statement can contain the number in any of the 3 forms:
26
+ 1) Direct number: Like 44, 1, 99 etc. Example Statements: Can you correct the code given in cell 44; What is the output for cell number 1 etc.
27
+ 2) Number representation in words: Like Thirty Three, Eleven etc. Example Statements: Can you optimize the code in cell thirty three; why there's an error in cell eleven etc.
28
+ 3) Rank representation of numbers: Like 4th, 21st, nineteenth etc. Example Statements: minimize the code in 4th cell; avoid duplications in nineteenth cell.
29
+ After extracting the number, the output should be returned in all three representations like this:
30
+ # 4th cell
31
+ # Cell Number: 4
32
+ # Cell Number: four
33
+
34
+ Given the instructions, return the output for the statement delimited by ####
35
+
36
+ ####
37
+ {input}
38
+ ####
39
+
40
+ [\INST]
41
+ """
42
+
43
+ output = query({
44
+ "inputs": prompt,
45
+ })
46
+
47
+ ouput = output[0]['generated_text']
48
+ output = output.replace(prompt,'').strip()
49
+
50
+ output = output.split('\n')
51
+ if len(output) > 3:
52
+ output = output[:3]
53
+
54
+ output = '\n'.join(output)
55
+
56
+ return output