Spaces:
Running
Running
Commit
·
0c24a6e
1
Parent(s):
3878fb6
Update app.py
Browse files
app.py
CHANGED
@@ -19,30 +19,30 @@ import socket
|
|
19 |
from huggingface_hub import HfApi
|
20 |
import smtplib
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
DATASET_REPO_URL = "https://huggingface.co/datasets/pragnakalp/OCR-img-to-text"
|
28 |
-
DATA_FILENAME = "ocr_data.csv"
|
29 |
-
DATA_FILE = os.path.join("ocr_data", DATA_FILENAME)
|
30 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
31 |
-
DATASET_REPO_ID = "pragnakalp/OCR-img-to-text"
|
32 |
-
print("is none?", HF_TOKEN is None)
|
33 |
-
try:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
except:
|
41 |
-
|
42 |
-
|
43 |
-
repo = Repository(
|
44 |
-
|
45 |
-
)
|
46 |
|
47 |
def get_device_ip_address():
|
48 |
|
@@ -127,13 +127,13 @@ def generate_ocr(Method,img):
|
|
127 |
if Method == 'PaddleOCR':
|
128 |
text_output = ocr_with_paddle(img)
|
129 |
|
130 |
-
with open(DATA_FILE, "a") as csvfile:
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
commit_url = repo.push_to_hub()
|
136 |
-
print(commit_url)
|
137 |
|
138 |
# save_details(Method,text_output,img)
|
139 |
# sender="[email protected]"
|
@@ -220,7 +220,7 @@ demo = gr.Interface(
|
|
220 |
description="Try OCR with different methods",
|
221 |
css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}",
|
222 |
allow_flagging = "manual",
|
223 |
-
|
224 |
-
|
225 |
)
|
226 |
demo.launch(enable_queue = False)
|
|
|
19 |
from huggingface_hub import HfApi
|
20 |
import smtplib
|
21 |
|
22 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
23 |
+
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$",type(HF_TOKEN))
|
24 |
+
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN,'OCR-img-to-text')
|
25 |
+
|
26 |
+
|
27 |
+
# # DATASET_REPO_URL = "https://huggingface.co/datasets/pragnakalp/OCR-img-to-text"
|
28 |
+
# DATA_FILENAME = "ocr_data.csv"
|
29 |
+
# DATA_FILE = os.path.join("ocr_data", DATA_FILENAME)
|
30 |
+
# HF_TOKEN = os.environ.get("HF_TOKEN")
|
31 |
+
# DATASET_REPO_ID = "pragnakalp/OCR-img-to-text"
|
32 |
+
# print("is none?", HF_TOKEN is None)
|
33 |
+
# try:
|
34 |
+
# hf_hub_download(
|
35 |
+
# repo_id=DATASET_REPO_ID,
|
36 |
+
# filename=DATA_FILENAME,
|
37 |
+
# cache_dir=DATA_DIRNAME,
|
38 |
+
# force_filename=DATA_FILENAME
|
39 |
+
# )
|
40 |
+
# except:
|
41 |
+
# print("file not found")
|
42 |
+
|
43 |
+
# repo = Repository(
|
44 |
+
# local_dir="ocr_data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
45 |
+
# )
|
46 |
|
47 |
def get_device_ip_address():
|
48 |
|
|
|
127 |
if Method == 'PaddleOCR':
|
128 |
text_output = ocr_with_paddle(img)
|
129 |
|
130 |
+
# with open(DATA_FILE, "a") as csvfile:
|
131 |
+
# writer = csv.DictWriter(csvfile, fieldnames=["method", "image", "generated_text"])
|
132 |
+
# writer.writerow(
|
133 |
+
# {"method": Method, "image": img, "generated_text": text_output}
|
134 |
+
# )
|
135 |
+
# commit_url = repo.push_to_hub()
|
136 |
+
# print(commit_url)
|
137 |
|
138 |
# save_details(Method,text_output,img)
|
139 |
# sender="[email protected]"
|
|
|
220 |
description="Try OCR with different methods",
|
221 |
css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}",
|
222 |
allow_flagging = "manual",
|
223 |
+
flagging_dir = "flagged",
|
224 |
+
flagging_callback=hf_writer
|
225 |
)
|
226 |
demo.launch(enable_queue = False)
|