pragnakalp commited on
Commit
03ceac8
1 Parent(s): f84a87f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -21
app.py CHANGED
@@ -16,22 +16,32 @@ import socket
16
  # from send_email_user import send_user_email
17
  from huggingface_hub import HfApi
18
  import smtplib
19
- # api = HfApi()
20
- # api.upload_folder(
21
- # folder_path="/media/pragnakalpl20/Projects/Pragnakalp_projects/gradio_demo/images",
22
- # path_in_repo="my-dataset/images",
23
- # repo_id="pragnakalp/OCR-image-to-text",
24
- # repo_type="dataset",
25
- # ignore_patterns="**/logs/*.txt",
26
- # )
27
-
28
- # if not os.path.isdir('images'):
29
- # os.mkdir('images')
30
- # print("create folder--->")
31
-
32
- HF_TOKEN = os.getenv('HF_TOKEN')
33
- print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$",type(HF_TOKEN))
34
- hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN,'OCR-image-to-text',True,True)
 
 
 
 
 
 
 
 
 
 
35
  def get_device_ip_address():
36
 
37
  if os.name == "nt":
@@ -55,7 +65,6 @@ def get_device_ip_address():
55
  return result
56
 
57
 
58
-
59
  """
60
  Paddle OCR
61
  """
@@ -115,6 +124,15 @@ def generate_ocr(Method,img):
115
  text_output = ocr_with_keras(img)
116
  if Method == 'PaddleOCR':
117
  text_output = ocr_with_paddle(img)
 
 
 
 
 
 
 
 
 
118
  # save_details(Method,text_output,img)
119
  # sender="[email protected]"
120
  # password="httscgatatbbxxur"
@@ -197,11 +215,10 @@ demo = gr.Interface(
197
  [method,image],
198
  output,
199
  title="Optical Character Recognition",
200
- description="Try OCR with different methods",
201
- theme="darkpeach",
202
  css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}",
203
  allow_flagging = "manual",
204
- flagging_dir = "flagged",
205
- flagging_callback=hf_writer
206
  )
207
  demo.launch(enable_queue = False)
 
16
  # from send_email_user import send_user_email
17
  from huggingface_hub import HfApi
18
  import smtplib
19
+
20
+ # HF_TOKEN = os.getenv('HF_TOKEN')
21
+ # print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$",type(HF_TOKEN))
22
+ # hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN,'OCR-image-to-text',True,True)
23
+
24
+
25
+ DATASET_REPO_URL = "https://huggingface.co/datasets/pragnakalp/OCR-img-to-text"
26
+ DATA_FILENAME = "ocr_data.csv"
27
+ DATA_FILE = os.path.join("ocr_data", DATA_FILENAME)
28
+ HF_TOKEN = os.environ.get("HF_TOKEN")
29
+ DATASET_REPO_ID = "pragnakalp/OCR-img-to-text"
30
+ print("is none?", HF_TOKEN is None)
31
+ try:
32
+ hf_hub_download(
33
+ repo_id=DATASET_REPO_ID,
34
+ filename=DATA_FILENAME,
35
+ cache_dir=DATA_DIRNAME,
36
+ force_filename=DATA_FILENAME
37
+ )
38
+ except:
39
+ print("file not found")
40
+
41
+ repo = Repository(
42
+ local_dir="ocr_data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
43
+ )
44
+
45
  def get_device_ip_address():
46
 
47
  if os.name == "nt":
 
65
  return result
66
 
67
 
 
68
  """
69
  Paddle OCR
70
  """
 
124
  text_output = ocr_with_keras(img)
125
  if Method == 'PaddleOCR':
126
  text_output = ocr_with_paddle(img)
127
+
128
+ with open(DATA_FILE, "a") as csvfile:
129
+ writer = csv.DictWriter(csvfile, fieldnames=["method", "image", "generated_text"])
130
+ writer.writerow(
131
+ {"method": Method, "image": img, "generated_text": text_output}
132
+ )
133
+ commit_url = repo.push_to_hub()
134
+ print(commit_url)
135
+
136
  # save_details(Method,text_output,img)
137
  # sender="[email protected]"
138
  # password="httscgatatbbxxur"
 
215
  [method,image],
216
  output,
217
  title="Optical Character Recognition",
218
+ description="Try OCR with different methods",
 
219
  css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}",
220
  allow_flagging = "manual",
221
+ # flagging_dir = "flagged",
222
+ # flagging_callback=hf_writer
223
  )
224
  demo.launch(enable_queue = False)