ImranzamanML commited on
Commit
0b1a6b2
·
verified ·
1 Parent(s): 122da1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -57,7 +57,7 @@ def fetch_location(ip_addr):
57
  print("Error while getting location -->", e)
58
  return {}
59
 
60
- def log_ocr_data(method, text_output, input_image):
61
  print("Logging OCR data...")
62
  ip_address = get_ip_address()
63
  location_info = fetch_location(ip_address)
@@ -74,7 +74,7 @@ def log_ocr_data(method, text_output, input_image):
74
  metadata_file_path = os.path.join(save_dir, 'metadata.jsonl')
75
  metadata = {
76
  'id': timestamp,
77
- 'method': method,
78
  'file_name': 'image.png',
79
  'generated_text': text_output,
80
  'ip': ip_address,
@@ -104,7 +104,7 @@ def log_ocr_data(method, text_output, input_image):
104
 
105
  url = 'http://pragnakalpdev35.pythonanywhere.com/HF_space_image_to_text'
106
  payload = {
107
- 'Method': method,
108
  'text_output': text_output,
109
  'img': input_image.tolist(),
110
  'ip_address': ip_address,
@@ -118,13 +118,13 @@ def log_ocr_data(method, text_output, input_image):
118
  """
119
  OCR Generation
120
  """
121
- def generate_ocr_text(method, image):
122
  text_output = ''
123
  if image.any():
124
  text_output = process_image_with_paddleocr(image)
125
 
126
  try:
127
- log_ocr_data(method, text_output, image)
128
  except Exception as e:
129
  print(e)
130
  return text_output
@@ -139,7 +139,7 @@ output_textbox = gr.Textbox(label="Recognized Text", lines=5, placeholder="OCR r
139
 
140
  demo = gr.Interface(
141
  fn=generate_ocr_text,
142
- inputs=[gr.Hidden("PaddleOCR"), image_input],
143
  outputs=output_textbox,
144
  title="PaddleOCR - Optical Character Recognition",
145
  description="Upload an image and extract text using PaddleOCR. This tool supports multiple languages and handles complex layouts.",
@@ -174,6 +174,10 @@ demo = gr.Interface(
174
  border-color: #007bff;
175
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
176
  }
177
- """)
 
 
 
 
178
 
179
  demo.launch()
 
57
  print("Error while getting location -->", e)
58
  return {}
59
 
60
+ def log_ocr_data(text_output, input_image):
61
  print("Logging OCR data...")
62
  ip_address = get_ip_address()
63
  location_info = fetch_location(ip_address)
 
74
  metadata_file_path = os.path.join(save_dir, 'metadata.jsonl')
75
  metadata = {
76
  'id': timestamp,
77
+ 'method': "PaddleOCR",
78
  'file_name': 'image.png',
79
  'generated_text': text_output,
80
  'ip': ip_address,
 
104
 
105
  url = 'http://pragnakalpdev35.pythonanywhere.com/HF_space_image_to_text'
106
  payload = {
107
+ 'Method': "PaddleOCR",
108
  'text_output': text_output,
109
  'img': input_image.tolist(),
110
  'ip_address': ip_address,
 
118
  """
119
  OCR Generation
120
  """
121
+ def generate_ocr_text(image):
122
  text_output = ''
123
  if image.any():
124
  text_output = process_image_with_paddleocr(image)
125
 
126
  try:
127
+ log_ocr_data(text_output, image)
128
  except Exception as e:
129
  print(e)
130
  return text_output
 
139
 
140
  demo = gr.Interface(
141
  fn=generate_ocr_text,
142
+ inputs=[image_input],
143
  outputs=output_textbox,
144
  title="PaddleOCR - Optical Character Recognition",
145
  description="Upload an image and extract text using PaddleOCR. This tool supports multiple languages and handles complex layouts.",
 
174
  border-color: #007bff;
175
  box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
176
  }
177
+ """,
178
+ article="""<p style='text-align: center;'>For inquiries or support, contact us at
179
+ <a href="mailto:[email protected]" target="_blank">[email protected]</a>.</p>
180
+ <p style='text-align: center;'>Developed by: <a href="https://www.example.com" target="_blank">Example Tech Labs</a></p>"""
181
+ )
182
 
183
  demo.launch()