oguz commited on
Commit
339611b
·
1 Parent(s): 61c6f21

Fix: packages.txt encoding + app.py syntax

Browse files
Files changed (2) hide show
  1. app.py +27 -17
  2. packages.txt +2 -2
app.py CHANGED
@@ -8,11 +8,11 @@ from typing import List, Tuple, Optional
8
 
9
  def process_bulk_images(files: List) -> Tuple[str, Optional[str]]:
10
  """
11
- Toplu resim iÅŸleme fonksiyonu
12
- 70'ten fazla resmi işleyip tüm yazıları tek bir metin olarak birleştirir
13
  """
14
  if not files:
15
- return "Lütfen en az bir resim yükleyin.", None
16
 
17
  all_texts = []
18
  processed_count = 0
@@ -20,12 +20,19 @@ def process_bulk_images(files: List) -> Tuple[str, Optional[str]]:
20
 
21
  for file in files:
22
  try:
23
- image = Image.open(file.name)\n try:\n text = pytesseract.image_to_string(image, lang='tur+eng')\n except TesseractNotFoundError:\n raise TesseractNotFoundError('Tesseract yüklü değil veya PATH içinde değil. Spaces için packages.txt ile kurulur; Windows için README\'deki yolu ayarlayın.')
 
 
 
 
 
 
 
24
  image_name = os.path.basename(file.name)
25
  if text.strip():
26
  all_texts.append(f"\n{'='*60}\n[{image_name}]\n{'='*60}\n{text.strip()}\n")
27
  else:
28
- all_texts.append(f"\n{'='*60}\n[{image_name}]\n{'='*60}\n[Bu resimden metin çıkarılamadı]\n")
29
  processed_count += 1
30
  except Exception as e:
31
  errors.append(f"{os.path.basename(file.name)}: {str(e)}")
@@ -33,16 +40,16 @@ def process_bulk_images(files: List) -> Tuple[str, Optional[str]]:
33
 
34
  combined_text = "\n".join(all_texts)
35
  stats = f"""
36
- İşlenen Resim Sayısı: {processed_count}/{len(files)}
37
- Hata Sayısı: {len(errors)}
38
- Toplam Karakter Sayısı: {len(combined_text)}
39
  """
40
  if errors:
41
  stats += "\nHatalar:\n" + "\n".join(errors)
42
  temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False, encoding='utf-8')
43
  temp_file.write(combined_text)
44
  temp_file.close()
45
- result_message = stats + "\n\nTüm metinler başarıyla birleştirildi. Aşağıdaki düğmeden indirebilirsiniz."
46
  return result_message, temp_file.name
47
 
48
 
@@ -50,19 +57,22 @@ def create_interface():
50
  with gr.Blocks(title="Bulk Tesseract OCR", theme=gr.themes.Soft()) as demo:
51
  gr.Markdown(
52
  """
53
- # 📸 Bulk Tesseract OCR
54
- 70'ten fazla resmi toplu iÅŸleyin; metinler tek bir dosyada.
 
 
 
 
 
55
  """
56
  )
57
- file_input = gr.File(file_count="multiple", label="Resimleri Seçin", file_types=["image"])
58
- process_btn = gr.Button("🚀 Resimleri İşle", variant="primary")
59
- output_text = gr.Textbox(label="İşlem Sonuçları", lines=10, interactive=False)
60
- output_file = gr.File(label="Birleştirilmiş Metin Dosyasını İndir", type="filepath")
61
  process_btn.click(fn=process_bulk_images, inputs=file_input, outputs=[output_text, output_file])
62
  return demo
63
 
64
  if __name__ == "__main__":
65
  demo = create_interface()
66
  demo.launch(share=False, server_name="0.0.0.0", server_port=7860)
67
-
68
-
 
8
 
9
  def process_bulk_images(files: List) -> Tuple[str, Optional[str]]:
10
  """
11
+ Toplu resim işleme fonksiyonu
12
+ 70'ten fazla resmi işleyip tüm yazıları tek bir metin olarak birleştirir
13
  """
14
  if not files:
15
+ return "Lütfen en az bir resim yükleyin.", None
16
 
17
  all_texts = []
18
  processed_count = 0
 
20
 
21
  for file in files:
22
  try:
23
+ image = Image.open(file.name)
24
+ try:
25
+ text = pytesseract.image_to_string(image, lang='tur+eng')
26
+ except TesseractNotFoundError:
27
+ raise TesseractNotFoundError(
28
+ 'Tesseract yüklü değil veya PATH içinde değil. '
29
+ 'Spaces için packages.txt ile kurulur; Windows için README\'deki yolu ayarlayın.'
30
+ )
31
  image_name = os.path.basename(file.name)
32
  if text.strip():
33
  all_texts.append(f"\n{'='*60}\n[{image_name}]\n{'='*60}\n{text.strip()}\n")
34
  else:
35
+ all_texts.append(f"\n{'='*60}\n[{image_name}]\n{'='*60}\n[Bu resimden metin çıkarılamadı]\n")
36
  processed_count += 1
37
  except Exception as e:
38
  errors.append(f"{os.path.basename(file.name)}: {str(e)}")
 
40
 
41
  combined_text = "\n".join(all_texts)
42
  stats = f"""
43
+ İşlenen Resim Sayısı: {processed_count}/{len(files)}
44
+ Hata Sayısı: {len(errors)}
45
+ Toplam Karakter Sayısı: {len(combined_text)}
46
  """
47
  if errors:
48
  stats += "\nHatalar:\n" + "\n".join(errors)
49
  temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False, encoding='utf-8')
50
  temp_file.write(combined_text)
51
  temp_file.close()
52
+ result_message = stats + "\n\nTüm metinler başarıyla birleştirildi. Aşağıdaki düğmeden indirebilirsiniz."
53
  return result_message, temp_file.name
54
 
55
 
 
57
  with gr.Blocks(title="Bulk Tesseract OCR", theme=gr.themes.Soft()) as demo:
58
  gr.Markdown(
59
  """
60
+ # 📸 Bulk Tesseract OCR
61
+ **70'ten fazla resmi toplu olarak işleyin ve tüm yazıları tek bir metin dosyası olarak alın**
62
+
63
+ - Birden fazla resim yükleyebilirsiniz
64
+ - Tüm resimlerden çıkarılan metinler tek bir dosyada birleştirilir
65
+ - Desteklenen formatlar: PNG, JPG, JPEG, TIFF
66
+ - Türkçe ve İngilizce dil desteği
67
  """
68
  )
69
+ file_input = gr.File(file_count="multiple", label="Resimleri Seçin (70'ten fazla resim yükleyebilirsiniz)", file_types=["image"])
70
+ process_btn = gr.Button("🚀 Resimleri İşle", variant="primary", size="lg")
71
+ output_text = gr.Textbox(label="İşlem Sonuçları", lines=10, interactive=False)
72
+ output_file = gr.File(label="Birleştirilmiş Metin Dosyasını İndir", type="filepath")
73
  process_btn.click(fn=process_bulk_images, inputs=file_input, outputs=[output_text, output_file])
74
  return demo
75
 
76
  if __name__ == "__main__":
77
  demo = create_interface()
78
  demo.launch(share=False, server_name="0.0.0.0", server_port=7860)
 
 
packages.txt CHANGED
@@ -1,3 +1,3 @@
1
- tesseract-ocr
2
  tesseract-ocr-tur
3
- tesseract-ocr-eng
 
1
+ tesseract-ocr
2
  tesseract-ocr-tur
3
+ tesseract-ocr-eng