Skip to content

Commit c6721a4

Browse files
committed
Upload main sources
1 parent 1f0befe commit c6721a4

File tree

5 files changed

+298
-1
lines changed

5 files changed

+298
-1
lines changed

.gitignore

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/python
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# poetry
102+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103+
# This is especially recommended for binary packages to ensure reproducibility, and is more
104+
# commonly ignored for libraries.
105+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106+
#poetry.lock
107+
108+
# pdm
109+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110+
#pdm.lock
111+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112+
# in version control.
113+
# https://pdm.fming.dev/#use-with-ide
114+
.pdm.toml
115+
116+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117+
__pypackages__/
118+
119+
# Celery stuff
120+
celerybeat-schedule
121+
celerybeat.pid
122+
123+
# SageMath parsed files
124+
*.sage.py
125+
126+
# Environments
127+
.env
128+
.venv
129+
env/
130+
venv/
131+
ENV/
132+
env.bak/
133+
venv.bak/
134+
135+
# Spyder project settings
136+
.spyderproject
137+
.spyproject
138+
139+
# Rope project settings
140+
.ropeproject
141+
142+
# mkdocs documentation
143+
/site
144+
145+
# mypy
146+
.mypy_cache/
147+
.dmypy.json
148+
dmypy.json
149+
150+
# Pyre type checker
151+
.pyre/
152+
153+
# pytype static type analyzer
154+
.pytype/
155+
156+
# Cython debug symbols
157+
cython_debug/
158+
159+
# PyCharm
160+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162+
# and can be added to the global gitignore or merged into this file. For a more nuclear
163+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164+
#.idea/
165+
166+
### Python Patch ###
167+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
168+
poetry.toml
169+
170+
# ruff
171+
.ruff_cache/
172+
173+
# LSP config files
174+
pyrightconfig.json
175+
176+
# End of https://www.toptal.com/developers/gitignore/api/python

HelloWorld.ui

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>900</width>
10+
<height>900</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<widget class="QPlainTextEdit" name="code_before">
17+
<property name="geometry">
18+
<rect>
19+
<x>10</x>
20+
<y>30</y>
21+
<width>430</width>
22+
<height>800</height>
23+
</rect>
24+
</property>
25+
<property name="toolTipDuration">
26+
<number>1</number>
27+
</property>
28+
</widget>
29+
<widget class="QTextBrowser" name="code_cmt">
30+
<property name="geometry">
31+
<rect>
32+
<x>460</x>
33+
<y>30</y>
34+
<width>430</width>
35+
<height>800</height>
36+
</rect>
37+
</property>
38+
<property name="sizePolicy">
39+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
40+
<horstretch>0</horstretch>
41+
<verstretch>0</verstretch>
42+
</sizepolicy>
43+
</property>
44+
</widget>
45+
<widget class="QPushButton" name="btn_cmt">
46+
<property name="geometry">
47+
<rect>
48+
<x>350</x>
49+
<y>840</y>
50+
<width>200</width>
51+
<height>50</height>
52+
</rect>
53+
</property>
54+
<property name="text">
55+
<string>Commenting</string>
56+
</property>
57+
</widget>
58+
</widget>
59+
<resources/>
60+
<connections/>
61+
</ui>

gptcmt.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import openai
2+
import os
3+
from dotenv import load_dotenv
4+
load_dotenv()
5+
openai.api_key = os.environ.get('OPENAI_API_KEY')
6+
openai.organization = os.environ.get('OPENAI_ORGANIZATION')
7+
8+
def generate_comment(code):
9+
prompt = f"This code is {code}."
10+
max_tokens = 100 # Set the desired length of the generated comment
11+
12+
#Call the OpenAI API to generate the comment
13+
response = openai.chat.completions.create(
14+
model="gpt-3.5-turbo",
15+
messages=[ {"role": "system", "content": "You are a autmatic python comment generator for inputed code. You output only commented phrase in python."},
16+
{"role": "user", "content": prompt}],
17+
)
18+
19+
#Extract the generated comment from the API response
20+
comment = response.choices[0].message.content
21+
22+
return comment

main.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Ex 5-1. QPushButton.
2+
3+
import sys
4+
import gptcmt
5+
from PyQt5.QtWidgets import *
6+
from PyQt5 import uic
7+
8+
form_class = uic.loadUiType("HelloWorld.ui")[0]
9+
class MyApp(QMainWindow, form_class):
10+
11+
def __init__(self):
12+
super().__init__()
13+
self.setupUi(self)
14+
15+
#버튼과 연결
16+
self.btn_cmt.clicked.connect(self.printCommentingCode)
17+
18+
19+
def printCommentingCode(self):
20+
txt = self.code_before.toPlainText()
21+
if(txt != ""):
22+
cmtcode = gptcmt.generate_comment(txt)
23+
self.code_cmt.setPlainText(cmtcode)
24+
else:
25+
pass
26+
27+
28+
29+
if __name__ == '__main__':
30+
app = QApplication(sys.argv)
31+
app.setApplicationName('Commenting on the code')
32+
ex = MyApp()
33+
ex.show()
34+
sys.exit(app.exec())
35+
36+
37+
38+

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Automatic Comment Generator
22

3-
주석을 단다.
3+
주석을 단다.

0 commit comments

Comments
 (0)