-
Notifications
You must be signed in to change notification settings - Fork 6
/
Project_Interface.py
155 lines (138 loc) · 4.61 KB
/
Project_Interface.py
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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
from tkinter import *
from PIL import Image, ImageTk
import speech_recognition as sr
import webbrowser
from simpletransformers.classification import ClassificationModel
model = ClassificationModel(
"bert", "checkpoint-117-epoch-3/",use_cuda=False)
root = Tk()
root.geometry("500x600")
root.configure(background="white")
Label(root, text="Türkçe Metin Sınıflandırma ", font=("Helvetica", 11, "bold"),
bg="khaki", width=30).place(x=0, y=10)
Label(root, text="Metin Ekle", font=("Helvetica", 10, "bold"),
bg="gray64", relief="solid", width=18).place(x=10, y=60)
Label(root, text="Türkçe Ses Sınıflandırma", font=("Helvetica", 11, "bold"),
bg="khaki", width=30).place(x=110, y=360)
Label(root, text="BERT", font=("Helvetica", 1),
bg="dark slate gray", width=600).place(x=0, y=320)
def getTextInput():
global c
result=textExample.get("1.0","end")
tahmin=model.predict([result])
if tahmin[0][0] ==0:
c="BİLİM VE TEKNOLOJİ"
elif tahmin[0][0]==1:
c="EKONOMİ"
elif tahmin[0][0]==2:
c="SAĞLIK"
elif tahmin[0][0]==3:
c="SİYASET"
elif tahmin[0][0]==4:
c="SPOR"
else:
c="BULUNAMADI"
Label(root, text=c, bg="gray80", relief="solid", width=30).place(x=250, y=290)
textExample=Text(root, height=10)
textExample.place(x=10, y=90,width=480,height=200)
btnRead=Button(root, text="Metin Kategorisini Tahmin Et:", width=25,command=getTextInput).place(x=20, y=290)
def anka10():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source, duration=1)
recorded_audio = recognizer.listen(source, timeout=10)
try:
text = recognizer.recognize_google(
recorded_audio,
language="tr-tr")
except Exception as ex:
print(ex)
tahmin=model.predict([text])
if tahmin[0][0] ==0:
c="BİLİM VE TEKNOLOJİ"
elif tahmin[0][0]==1:
c="EKONOMİ"
elif tahmin[0][0]==2:
c="SAĞLIK"
elif tahmin[0][0]==3:
c="SİYASET"
elif tahmin[0][0]==4:
c="SPOR"
else:
c="BULUNAMADI"
Label(root, text=c, bg="gray80", relief="solid", width=25).place(x=280, y=420)
button =Button(root, text='Ses Kaydını Başlat (10sn)', width=20,command=anka10)
button.place(x=20, y=390)
def anka30():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source, duration=1)
recorded_audio = recognizer.listen(source, timeout=10)
try:
text = recognizer.recognize_google(
recorded_audio,
language="tr-tr")
except Exception as ex:
print(ex)
tahmin=model.predict([text])
if tahmin[0][0] ==0:
c="BİLİM VE TEKNOLOJİ"
elif tahmin[0][0]==1:
c="EKONOMİ"
elif tahmin[0][0]==2:
c="SAĞLIK"
elif tahmin[0][0]==3:
c="SİYASET"
elif tahmin[0][0]==4:
c="SPOR"
else:
c="BULUNAMADI"
Label(root, text=c, bg="gray80", relief="solid", width=25).place(x=280, y=420)
button =Button(root, text='Ses Kaydını Başlat (30sn)',width=25, command=anka30)
button.place(x=20, y=425)
def anka1():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source, duration=1)
recorded_audio = recognizer.listen(source, timeout=10)
try:
text = recognizer.recognize_google(
recorded_audio,
language="tr-tr")
except Exception as ex:
print(ex)
tahmin=model.predict([text])
if tahmin[0][0] ==0:
c="BİLİM VE TEKNOLOJİ"
elif tahmin[0][0]==1:
c="EKONOMİ"
elif tahmin[0][0]==2:
c="SAĞLIK"
elif tahmin[0][0]==3:
c="SİYASET"
elif tahmin[0][0]==4:
c="SPOR"
else:
c="BULUNAMADI"
Label(root, text=c, bg="gray80", relief="solid", width=25).place(x=280, y=420)
button =Button(root, text='Ses Kaydını Başlat (1 dk)', width=30,command=anka1)
button.place(x=20, y=460)
def ankam():
term=c
url = "https://www.google.com.tr/search?q={}".format(term)
webbrowser.open_new_tab(url)
button =Button(root, text=' Google ', width=13,command=ankam)
button.place(x=190, y=57)
imgg = Image.open("mö.jpg")
imgg = imgg.resize((200, 87))
photoo=ImageTk.PhotoImage(imgg)
labb=Label(image=photoo).place(x=300, y=0)
imggg = Image.open("seso.jpg")
imggg = imggg.resize((550, 100))
photooo=ImageTk.PhotoImage(imggg)
labb=Label(image=photooo).place(x=0, y=500)
root.resizable(0, 0)
root.mainloop()