forked from vsahni3/EasyMed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml.py
More file actions
38 lines (33 loc) · 1.14 KB
/
ml.py
File metadata and controls
38 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
# url = "https://freeocrapi.com/api"
# filename = "myopd-sample-rx-eng.png"
# data = {'file': open(filename, 'rb')}
# response = requests.request("POST", url, files=data)
# # print(response.text)
# print(dict(response.json())['text'].replace('\n', ' '))
def get_data(filename):
url = "https://freeocrapi.com/api"
data = {'file': open(filename, 'rb')}
response = requests.request("POST", url, files=data)
data = dict(response.json())['text'].replace('\n', ' ')
return data
def extract_data(raw_data):
data = {
'names': [],
'dosages': []
}
for i in range(len(raw_data)):
if raw_data[i:i+2] == 'mg':
start_index = i - 2
cur_dosage = ''
while raw_data[start_index] != ' ':
cur_dosage += raw_data[start_index]
start_index -= 1
data['dosages'].append(cur_dosage[::-1])
start_index -= 1
cur_name = ''
while raw_data[start_index] != ' ':
cur_name += raw_data[start_index]
start_index -= 1
data['names'].append(cur_name[::-1])
return data