Vikas01 commited on
Commit
197e2b4
·
1 Parent(s): 1ec7b60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import numpy as np
2
  import cv2
 
3
  import imutils
4
  import pytesseract
5
  import pandas as pd
@@ -9,6 +10,13 @@ import os
9
  from PIL import Image
10
  import streamlit as st
11
 
 
 
 
 
 
 
 
12
  bytes_data = None
13
 
14
  img_file_buffer = st.camera_input("Take a picture")
@@ -62,13 +70,14 @@ if img_file_buffer is not None:
62
  file_path = os.path.join("data", "data.csv")
63
  if os.path.exists(file_path):
64
  # Append the data to the existing CSV file
65
- with open(file_path, "a") as f:
66
- df.to_csv(f, header=False, index=False)
 
 
 
67
  else:
68
  # Create a new CSV file and write the data
69
- with open(file_path, "w") as f:
70
- df.to_csv(f, index=False)
71
-
72
 
73
 
74
  # Print recognized text
 
1
  import numpy as np
2
  import cv2
3
+ import csv
4
  import imutils
5
  import pytesseract
6
  import pandas as pd
 
10
  from PIL import Image
11
  import streamlit as st
12
 
13
+ #
14
+ # Create a directory for storing data
15
+ if not os.path.exists("data"):
16
+ os.makedirs("data")
17
+
18
+
19
+
20
  bytes_data = None
21
 
22
  img_file_buffer = st.camera_input("Take a picture")
 
70
  file_path = os.path.join("data", "data.csv")
71
  if os.path.exists(file_path):
72
  # Append the data to the existing CSV file
73
+ with open(file_path, mode='a', newline='') as file:
74
+ writer = csv.writer(file)
75
+ if os.stat(file_path).st_size == 0:
76
+ writer.writerow(df.columns)
77
+ writer.writerow(df.iloc[0])
78
  else:
79
  # Create a new CSV file and write the data
80
+ df.to_csv(file_path, index=False)
 
 
81
 
82
 
83
  # Print recognized text