-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad.py
More file actions
163 lines (136 loc) · 6.62 KB
/
notepad.py
File metadata and controls
163 lines (136 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import gradio as gr
import moduller.atasozlerOneri as atasozlerOneri
import moduller.velhasil as velhasil
import pytesseract
from PIL import Image
class VelhasilApp:
def __init__(self):
self.velhasil_ = velhasil.Velhasil()
def file_open(self, file):
try:
with open(file.name, 'r', encoding="UTF-8") as f:
text = f.read()
return text, f"Opened file: {file.name}"
except Exception as e:
return "", f"Error: {str(e)}"
def atasozuOneri(self, text):
atasozleri_ = atasozlerOneri.AtasozleriOneri()
oneriler = atasozleri_.atasozuBul(text)
oneriler.sort(reverse=True)
return "Atasözü Önerisi Bulunamadı..." if len(oneriler) == 0 else "\n".join(oneriler)
def yazimDenetimi(self, text):
# Denetim sonuçları: kelimeler ve karşılık gelen hata kodları
kelimeler = text.split()
denetim_kodlari = self.velhasil_.yazimDenetimi(text.rstrip())
# Hata kodlarına ait açıklamalar
error_codes = {
0: "Kelime doğru",
1: "Kelime bir noktalama işareti, önündeki boşluk silinmeli",
2: "Kelime yanlış",
3: "Cümleden sonra nokta koyulmalı",
4: "Noktalama işaretinden sonra boşluk bırakılmalı",
5: "Noktadan sonra büyük harf gelmeli",
6: "Kelime doğru ancak Türkçe kelime önerisi var"
}
# Renklendirme için hata kodlarına ait renkler
color_map = {
0: "green",
1: "orange",
2: "red",
3: "blue",
4: "purple",
5: "yellow",
6: "cyan"
}
formatted_output = [
(kelime, color_map.get(kod, None)) for kelime, kod in zip(kelimeler, denetim_kodlari)
]
return formatted_output
def istatistikGoster(self, text):
velhasil__ = velhasil.Velhasil(text)
stats = [
f"Kelime sayısı: {velhasil__.kelimesayisi}",
f"Benzersiz kelime sayısı: {velhasil__.benzersizkelimesayisi}",
f"Karakter sayısı: {velhasil__.karaktersayisi}",
f"Benzersiz karakter sayısı: {velhasil__.benzersizkaraktersayisi}",
f"Paragraf sayısı: {velhasil__.paragrafSayisi}",
f"Cümle sayısı: {velhasil__.cumleSayisi}",
f"Kelimeler: {velhasil__.benzersizkelimeler}"
]
return "\n".join(stats)
def cumleAnalizi(self, text):
velhasil__ = velhasil.Velhasil(text)
bolunebilen_cumle_sayisi = 0
highlighted_sentences = []
for cumle in velhasil__.cumleler:
cumle_bolme_sonucu = velhasil__.cumleBolucu(cumle)
if cumle_bolme_sonucu != 0:
highlighted_sentences.append((cumle, "highlight"))
bolunebilen_cumle_sayisi += 1
else:
highlighted_sentences.append((cumle, None))
analysis = [
f"Metnin içinde {velhasil__.cumleSayisi} cümle bulundu.",
f"Metnin içinde {bolunebilen_cumle_sayisi} bölünmeye müsait cümle bulundu.",
"Metnin daha okunabilir olması için işaretlenen birleşik cümleleri bölebilirsiniz.",
f"Metin {velhasil__.paragrafSayisi} paragraftan oluşuyor."
]
return highlighted_sentences, "\n".join(analysis)
def process_captured_image(self, image):
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
try:
text = pytesseract.image_to_string(image, lang='tur')
return text
except Exception as e:
return f"OCR işlemi sırasında hata oluştu: {str(e)}"
def tumCumleyiKontrolEtVeDuzelt(self, metin):
kelimeler = metin.split()
noktalama_isaretleri = [".", ",", "?", "!", "...", ":", "(", ")"]
duzeltilmis_metin = []
for kelime in kelimeler:
if kelime not in noktalama_isaretleri:
if not self.velhasil_.isCorrect(kelime):
oneriler = self.velhasil_.kelimeOneri(kelime)
if oneriler:
kelime = list(oneriler)[0]
elif len(self.velhasil_.turkcesiniOner(kelime)) > 0:
kelime = self.velhasil_.turkcesiniOner(kelime)[0]
duzeltilmis_metin.append(kelime)
yeni_metin = " ".join(duzeltilmis_metin)
return yeni_metin
def run_app(self):
with gr.Blocks(title="EditorAI - Metin İşleme Aracı") as demo:
gr.Markdown("EditorAI Metin İşleme Aracı")
with gr.Row():
text_box = gr.Textbox(placeholder="Metninizi buraya yazın...", lines=10, label="Metin")
with gr.Row():
open_button = gr.File(label="Dosya Aç", scale=1)
with gr.Row():
image_input = gr.Image(label="Resim Yükle", mirror_webcam=False, scale=1)
with gr.Column():
with gr.Row():
atasozu_button = gr.Button("Atasözü Öner")
yazimdenetim_button = gr.Button("Yazım Denetimi")
with gr.Row():
istatistik_button = gr.Button("Metin İstatistikleri")
cumleanalizi_button = gr.Button("Cümle Analizi")
with gr.Row():
duzelt_button = gr.Button("Metin Duzelt")
highlighted_output = gr.HighlightedText(
label="Yazım Denetimi Sonuçları",
combine_adjacent=True,
color_map={"green": "green", "orange": "orange", "red": "red", "blue": "blue", "purple": "purple", "yellow": "yellow", "cyan": "cyan"},
scale=4
)
output_text = gr.Textbox(label="Çıktı", interactive=False)
open_button.upload(self.file_open, inputs=[open_button], outputs=[text_box, output_text])
atasozu_button.click(self.atasozuOneri, inputs=[text_box], outputs=[output_text])
yazimdenetim_button.click(self.yazimDenetimi, inputs=[text_box], outputs=[highlighted_output])
istatistik_button.click(self.istatistikGoster, inputs=[text_box], outputs=[output_text])
duzelt_button.click(self.tumCumleyiKontrolEtVeDuzelt, inputs=[text_box], outputs=[output_text])
cumleanalizi_button.click(self.cumleAnalizi, inputs=[text_box], outputs=[highlighted_output, output_text])
image_input.upload(self.process_captured_image, inputs=[image_input], outputs=[text_box])
demo.launch()
if __name__ == "__main__":
app = VelhasilApp()
app.run_app()