-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
158 lines (137 loc) · 5.62 KB
/
main.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
155
156
157
158
import sys
from threading import Thread
from PyQt5.QtWidgets import QApplication,QMainWindow,QLabel,QVBoxLayout,QFrame,QPushButton,QFileDialog
from PyQt5.QtCore import Qt
import json
from PyQt5.QtWidgets import QWidget, QApplication, QRubberBand
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtCore import Qt, QPoint, QRect
import time
import requests
import openai
def ask_chatgpt(question):
openai.api_key = 'Enter Your own openai api key bro'
question += "Give me the accurate ans of this question"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are jarvis, a large language model trained by subhashis. Your task to help him what he ask you need to answers all requests and follows all instructions And Give 1005 Accurate answer"},
{"role": "user", "content": question},
{"role": "assistant", "content": "Continue"}
],
stream=False
)
response_json = response.__str__()
response_dict = json.loads(response_json)
mainresp = response_dict['choices'][0]['message']['content'].replace("OpenAI", "subhashis")
return mainresp
def extract_text():
upload_url = 'https://lens.google.com/v3/upload?hl=en-IN&re=df&st=1713462961116&vpw=1543&vph=877&ep=gsbubb'
image_path = 'TEST.png'
with open(image_path, 'rb') as image_file:
files = {'encoded_image': (image_path, image_file, 'image/jpeg')}
response = requests.post(upload_url, files=files)
resp = response.text
mainresp = resp.split('"en",[[["')[1].split('"]],')[0]
return mainresp
def showans():
extracted_text = extract_text()
print("====================QUESTION==========================")
print(extracted_text)
print("=====================ANSWER===========================")
print(ask_chatgpt(extracted_text))
print("======================================================")
class Capture(QWidget):
def __init__(self, main_window):
super().__init__()
self.main = main_window
self.main.hide()
self.setMouseTracking(True)
desk_size = QApplication.desktop()
self.setGeometry(0, 0, desk_size.width(), desk_size.height())
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setWindowOpacity(0.15)
self.rubber_band = QRubberBand(QRubberBand.Rectangle, self)
self.origin = QPoint()
QApplication.setOverrideCursor(Qt.CrossCursor)
screen = QApplication.primaryScreen()
rect = QApplication.desktop().rect()
time.sleep(0.31)
self.imgmap = screen.grabWindow(
QApplication.desktop().winId(),
rect.x(), rect.y(), rect.width(), rect.height()
)
def mousePressEvent(self, event: QMouseEvent | None) -> None:
if event.button() == Qt.LeftButton:
self.origin = event.pos()
self.rubber_band.setGeometry(QRect(self.origin, event.pos()).normalized())
self.rubber_band.show()
def mouseMoveEvent(self, event: QMouseEvent | None) -> None:
if not self.origin.isNull():
self.rubber_band.setGeometry(QRect(self.origin, event.pos()).normalized())
def mouseReleaseEvent(self, event: QMouseEvent | None) -> None:
if event.button() == Qt.LeftButton:
self.rubber_band.hide()
rect = self.rubber_band.geometry()
self.imgmap = self.imgmap.copy(rect)
QApplication.restoreOverrideCursor()
clipboard = QApplication.clipboard()
clipboard.setPixmap(self.imgmap)
self.imgmap.save("TEST.png")
self.main.label.setPixmap(self.imgmap)
self.main.show()
self.close()
print("Extracting Answer Please Wait...")
Thread(target=showans).start()
class ScreenRegionSelector(QMainWindow):
def __init__(self,):
super().__init__(None)
self.m_width = 400
self.m_height = 500
self.setWindowTitle("SM ALWAYS PRO")
self.setMinimumSize(self.m_width, self.m_height)
frame = QFrame()
frame.setContentsMargins(0, 0, 0, 0)
lay = QVBoxLayout(frame)
lay.setAlignment(Qt.AlignmentFlag.AlignCenter)
lay.setContentsMargins(5, 5, 5, 5)
self.label = QLabel()
self.btn_capture = QPushButton("Capture")
self.btn_capture.clicked.connect(self.capture)
self.btn_save = QPushButton("Save")
self.btn_save.clicked.connect(self.save)
self.btn_save.setVisible(False)
lay.addWidget(self.label)
lay.addWidget(self.btn_capture)
lay.addWidget(self.btn_save)
self.setCentralWidget(frame)
def capture(self):
self.capturer = Capture(self)
self.capturer.show()
# self.btn_save.setVisible(True)
def save(self):
file_name, _ = QFileDialog.getSaveFileName(self, "Save Image", "", "Image files (*.png *.jpg *.bmp)")
if file_name:
self.capturer.imgmap.save(file_name)
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet("""
QFrame {
background-color: #3f3f3f;
}
QPushButton {
border-radius: 5px;
background-color: rgb(60, 90, 255);
padding: 10px;
color: white;
font-weight: bold;
font-family: Arial;
font-size: 12px;
}
QPushButton::hover {
background-color: rgb(60, 20, 255)
}
""")
selector = ScreenRegionSelector()
selector.show()
app.exit(app.exec_())