Skip to content

Commit 4971500

Browse files
First beta version.
1 parent ed8a851 commit 4971500

File tree

6 files changed

+251
-5
lines changed

6 files changed

+251
-5
lines changed

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
1-
# PLangRec
2-
Programming language recognizer
1+
# *PLangRec*
2+
3+
[![License](https://img.shields.io/github/license/ComputationalReflection/PLangRec)](LICENSE)
4+
[![Latest release](https://img.shields.io/github/v/release/computationalreflection/plangrec?include_prereleases)](https://github.com/ComputationalReflection/PLangRec/releases)
5+
<img alt="Code size" src="https://img.shields.io/github/languages/code-size/ComputationalReflection/PLangRec">
6+
<img alt="Repo size" src="https://img.shields.io/github/repo-size/ComputationalReflection/PLangRec">
7+
8+
*Programming language recognizer*
9+
10+
*PLangRec* is a character-level deep model to recognize the programming language of source code.
11+
12+
*PLangRec* is provided as a Python desktop application, web API and web application.
13+
14+
## Python desktop application
15+
16+
Make sure you have Python installed. Then, install all the required packages:
17+
18+
``` bash
19+
pip install -r requirements.txt --upgrade
20+
```
21+
22+
Make sure you have downloaded both the both `common` and the `desktop` folders, and they are
23+
both subdirectories of the same parent directory (the must be sibling directories).
24+
25+
Finally, run *PLangRec* as a Python application (the model will be downloaded from the Internet,
26+
so the first execution may take minutes):
27+
28+
``` bash
29+
cd desktop-app
30+
python main.py
31+
```
32+
33+
![Desktop application screenshot](img/desktop-app.png)
34+
35+
## Web API
36+
37+
Make sure you have Python installed. Then, install all the required packages:
38+
39+
``` bash
40+
pip install -r requirements.txt --upgrade
41+
```
42+
43+
Make sure you have downloaded both the both `common` and the `web-api` folders, and they are
44+
both subdirectories of the same parent directory (the must be sibling directories).
45+
46+
Finally, run *PLangRec* as a Web API (the model will be downloaded from the Internet,
47+
so the first execution may take minutes):
48+
49+
``` bash
50+
cd web-api
51+
python main.py
52+
```
53+
54+
## Web application
55+
56+
For the web application, you need to deploy the Web API
57+
because the application consumes the API.
58+
59+
Steps:
60+
61+
1. Deploy the Web API in one server.
62+
2. Download the `web-app` folder to your web server.
63+
3. Modify the value of the `WEB_SERVER` variable in the `index.html` file,
64+
setting its value to the server where you have the web API (step 1).
65+
66+
The Web application will be ready, calling the Web API.
67+
68+
![Web application screenshot](img/web-app.png)
69+
70+
## License
71+
72+
[MIT license](LICENSE).

desktop-app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from tkinter import Tk, END, E, W, ttk, StringVar, BooleanVar, NORMAL, DISABLED, Text, Event
22
from tkinter.ttk import Button, Combobox, LabelFrame, Treeview, Style
33
from example_code import PROGRAM_EXAMPLES
4-
from languages import LANGUAGES
54

65

76
def sort_number(table: Treeview, column_name: str, ascending: bool) -> None:
@@ -53,6 +52,7 @@ def main() -> None:
5352
query_frame.columnconfigure(1, weight=1)
5453

5554
# Combobox inside LabelFrame to pick one predefined text of source code
55+
from languages import LANGUAGES
5656
cmb = Combobox(query_frame, values=LANGUAGES, state="readonly")
5757
cmb.grid(row=1, column=0, padx=5, pady=(15, 0))
5858
cmb.current(0) # Default pick

img/desktop-app.png

15.5 KB
Loading

img/web-app.png

63.4 KB
Loading

requirements.txt

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
absl-py==2.0.0
2+
anyio==4.2.0
3+
argon2-cffi==23.1.0
4+
argon2-cffi-bindings==21.2.0
5+
arrow==1.3.0
6+
asttokens==2.4.1
7+
astunparse==1.6.3
8+
async-lru==2.0.4
9+
attrs==23.2.0
10+
Babel==2.14.0
11+
bcrypt==4.0.1
12+
beautifulsoup4==4.12.3
13+
bleach==6.1.0
14+
blinker==1.6.3
15+
cachetools==5.3.2
16+
certifi==2023.7.22
17+
cffi==1.16.0
18+
chardet==5.2.0
19+
charset-normalizer==3.3.2
20+
click==8.1.7
21+
colorama==0.4.6
22+
coloredlogs==15.0.1
23+
colour==0.1.5
24+
comm==0.2.1
25+
contourpy==1.1.1
26+
cryptography==41.0.4
27+
cycler==0.12.1
28+
debugpy==1.8.0
29+
decorator==5.1.1
30+
defusedxml==0.7.1
31+
dm-tree==0.1.8
32+
dtreeviz==2.2.2
33+
executing==2.0.1
34+
fastjsonschema==2.19.1
35+
Flask==3.0.0
36+
Flask-Cors==4.0.0
37+
flatbuffers==23.5.26
38+
fonttools==4.43.1
39+
fqdn==1.5.1
40+
gast==0.5.4
41+
google-auth==2.25.2
42+
google-auth-oauthlib==1.1.0
43+
google-pasta==0.2.0
44+
graphviz==0.20.1
45+
greenlet==3.0.0
46+
grpcio==1.60.0
47+
h5py==3.10.0
48+
humanfriendly==10.0
49+
idna==3.4
50+
iniconfig==2.0.0
51+
ipykernel==6.29.0
52+
ipython==8.21.0
53+
ipywidgets==8.1.1
54+
isoduration==20.11.0
55+
itsdangerous==2.1.2
56+
jedi==0.19.1
57+
Jinja2==3.1.2
58+
joblib==1.3.2
59+
json5==0.9.14
60+
jsonpointer==2.4
61+
jsonschema==4.21.1
62+
jsonschema-specifications==2023.12.1
63+
jupyter==1.0.0
64+
jupyter-console==6.6.3
65+
jupyter-events==0.9.0
66+
jupyter-lsp==2.2.2
67+
jupyter_client==8.6.0
68+
jupyter_core==5.7.1
69+
jupyter_server==2.12.5
70+
jupyter_server_terminals==0.5.2
71+
jupyterlab==4.0.12
72+
jupyterlab-widgets==3.0.9
73+
jupyterlab_pygments==0.3.0
74+
jupyterlab_server==2.25.2
75+
keras==2.15.0
76+
kiwisolver==1.4.5
77+
libclang==16.0.6
78+
logging==0.4.9.6
79+
Markdown==3.5.1
80+
markdown-it-py==3.0.0
81+
MarkupSafe==2.1.3
82+
matplotlib==3.8.0
83+
matplotlib-inline==0.1.6
84+
mdurl==0.1.2
85+
mistune==3.0.2
86+
ml-dtypes==0.2.0
87+
mpld3==0.5.10
88+
namex==0.0.7
89+
nbclient==0.9.0
90+
nbconvert==7.14.2
91+
nbformat==5.9.2
92+
nest-asyncio==1.6.0
93+
notebook==7.0.7
94+
notebook_shim==0.2.3
95+
numpy==1.26.1
96+
oauthlib==3.2.2
97+
opt-einsum==3.3.0
98+
overrides==7.7.0
99+
packaging==23.2
100+
pandas==2.1.1
101+
pandocfilters==1.5.1
102+
paramiko==3.3.1
103+
parso==0.8.3
104+
patsy==0.5.3
105+
Pillow==10.1.0
106+
platformdirs==4.2.0
107+
pluggy==1.3.0
108+
prometheus-client==0.19.0
109+
prompt-toolkit==3.0.43
110+
protobuf==4.23.4
111+
psutil==5.9.8
112+
psycopg2==2.9.9
113+
psycopg2-binary==2.9.9
114+
pure-eval==0.2.2
115+
pyasn1==0.5.1
116+
pyasn1-modules==0.3.0
117+
pycparser==2.21
118+
Pygments==2.17.2
119+
PyNaCl==1.5.0
120+
pyparsing==3.1.1
121+
pyreadline3==3.4.1
122+
pytest==7.4.3
123+
python-dateutil==2.8.2
124+
python-json-logger==2.0.7
125+
pytz==2023.3.post1
126+
pywin32==306
127+
pywinpty==2.0.12
128+
PyYAML==6.0.1
129+
pyzmq==25.1.2
130+
qtconsole==5.5.1
131+
QtPy==2.4.1
132+
referencing==0.33.0
133+
requests==2.31.0
134+
requests-oauthlib==1.3.1
135+
rfc3339-validator==0.1.4
136+
rfc3986-validator==0.1.1
137+
rich==13.7.0
138+
rpds-py==0.17.1
139+
rsa==4.9
140+
scikit-learn==1.3.1
141+
scipy==1.11.3
142+
seaborn==0.13.2
143+
Send2Trash==1.8.2
144+
six==1.16.0
145+
sklearn==0.0.post10
146+
sniffio==1.3.0
147+
soupsieve==2.5
148+
SQLAlchemy==2.0.22
149+
sshtunnel==0.4.0
150+
stack-data==0.6.3
151+
statsmodels==0.14.0
152+
tensorboard==2.15.1
153+
tensorboard-data-server==0.7.2
154+
tensorflow==2.15.0
155+
tensorflow-estimator==2.15.0
156+
tensorflow-intel==2.15.0
157+
tensorflow-io-gcs-filesystem==0.31.0
158+
termcolor==2.4.0
159+
terminado==0.18.0
160+
threadpoolctl==3.2.0
161+
tinycss2==1.2.1
162+
tornado==6.4
163+
traitlets==5.14.1
164+
types-python-dateutil==2.8.19.20240106
165+
typing_extensions==4.8.0
166+
tzdata==2023.3
167+
uri-template==1.3.0
168+
urllib3==2.0.7
169+
wcwidth==0.2.13
170+
webcolors==1.13
171+
webencodings==0.5.1
172+
websocket-client==1.7.0
173+
Werkzeug==3.0.1
174+
widgetsnbextension==4.0.9
175+
wrapt==1.14.1

wep-app/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<h1 class="display-4">
5757
PLangRec
5858
</h1>
59-
<p class="text-secondary" style="font-size:1.5em;"><i>Character-level model to recognize the programming language of source code</i></p>
59+
<p class="text-secondary" style="font-size:1.5em;"><i>Character-level deep model to recognize the programming language of source code</i></p>
6060

6161

6262
<div id="analysisRowDiv" class="row pt-4">
@@ -153,6 +153,7 @@ <h2 class="p-3 col-11 text-center">Programming Language</h2>
153153
</body>
154154

155155
<script>
156+
const WEB_SERVER = 'http://127.0.0.1:5000'
156157
function selectExampleLanguage(language) {
157158
const example_code = {
158159
"Assembly": "ADD CX, [BX+SI*2+10]",
@@ -185,7 +186,7 @@ <h2 class="p-3 col-11 text-center">Programming Language</h2>
185186
}
186187
function buttonClicked() {
187188
// do the prediction by calling the web API
188-
fetch('http://127.0.0.1:5000/BRNN/predict?source_code=' + document.getElementById("source-code").value)
189+
fetch(WEB_SERVER + '/BRNN/predict?source_code=' + document.getElementById("source-code").value)
189190
.then(response => response.json())
190191
.then(data => {
191192
// Handle the response data and populate the HTML table

0 commit comments

Comments
 (0)