/upload.html
here i want to send a file i.e.image directly inside a python script and read a file inside a script.basically i want to read a file inside that script and put a result in html
<html>
<head>
<title>Upload File</title>
</head>
<body>
<h1>Upload File</h1>
<form action="/home/rohit/tesseract/py1.py" method="POST" enctype="multipart/form-data">
File: <input name="file" type="file">
<input name="submit" type="submit">
</form>
</body>
</html>
//py1.py
import pytesser
import match_data
import re
import pandas as pd
#txt = pytesser.image_file_to_string("20181003_121034.jpg")
By default language is eng, and page seg mode auto
from sqlalchemy import create_engine
i want to pass a file here for furthur process
To give specifify parameters:
txt = pytesser.image_file_to_string("i want to pass a file here","eng",pytesser.PSM_SINGLE_COLUMN)
print(txt.split('\n'))
d = txt.split('\n')
test_name,result,ref_value = [],[],[]
for ds in d:
# print ds
# print(match_data.fetch_profile(ds))
res = match_data.fetch_profile(ds)
# print res
try:
if res[0] == 1:
#rint ds
print res[1]
ds = re.sub(' +',' ',ds)
# print ds.split()[ds.split().index(res[1].split()[-1])+1]
result.append(ds.split()[ds.split().index(res[1].split()[-1])+1])
test_name.append(res[1])
ref_value.append(match_data.get_ref_value(res[1]))
except (TypeError,IndexError) as e:
# print e
pass
df =pd.DataFrame(list(zip(test_name,result,ref_value)),columns=['Test Name','Result','Ref Value'])
engine = create_engine('mysql://root:root@/practice?charset=utf8')
conn = engine.connect()
df.to_sql(name= 'imgtxt', con=engine, if_exists='append', index=False)
print df
Comments
Post a Comment