├── .gitignore ├── .status ├── LICENSE.txt ├── MANIFEST.in ├── README.md ├── __init__.py ├── ai_virtual_assistant.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── entry_points.txt ├── requires.txt └── top_level.txt ├── data ├── __init__.py ├── cpp_template.txt ├── cpp_template_info.txt ├── data.py ├── get_template.py ├── py_template.txt └── py_template_info.txt ├── dist ├── ai_virtual_assistant-0.0.7-py3-none-any.whl ├── ai_virtual_assistant-0.0.8-py3-none-any.whl ├── ai_virtual_assistant-0.0.9-py3-none-any.whl ├── ai_virtual_assistant-0.1.0-py3-none-any.whl ├── ai_virtual_assistant-0.1.1-py3-none-any.whl ├── ai_virtual_assistant-0.1.2-py3-none-any.whl ├── ai_virtual_assistant-0.1.3-py3-none-any.whl ├── ai_virtual_assistant-0.1.4-py3-none-any.whl ├── ai_virtual_assistant-0.1.5-py3-none-any.whl ├── ai_virtual_assistant-0.1.6-py3-none-any.whl ├── ai_virtual_assistant-0.1.7-py3-none-any.whl ├── ai_virtual_assistant-0.1.8-py3-none-any.whl ├── ai_virtual_assistant-0.1.9-py3-none-any.whl ├── ai_virtual_assistant-0.2.0-py3-none-any.whl ├── ai_virtual_assistant-0.2.1-py3-none-any.whl ├── ai_virtual_assistant-0.2.2-py3-none-any.whl ├── ai_virtual_assistant-0.2.3-py3-none-any.whl ├── ai_virtual_assistant-0.2.4-py3-none-any.whl ├── ai_virtual_assistant-0.2.5-py3-none-any.whl ├── ai_virtual_assistant-0.2.6-py3-none-any.whl ├── ai_virtual_assistant-0.2.7-py3-none-any.whl ├── ai_virtual_assistant-0.2.8-py3-none-any.whl ├── ai_virtual_assistant-0.2.9-py3-none-any.whl ├── ai_virtual_assistant-0.3.0-py3-none-any.whl ├── ai_virtual_assistant-0.3.1-py3-none-any.whl ├── ai_virtual_assistant-0.3.2-py3-none-any.whl ├── ai_virtual_assistant-0.3.3-py3-none-any.whl ├── ai_virtual_assistant-0.3.4-py3-none-any.whl ├── ai_virtual_assistant-0.3.5-py3-none-any.whl ├── ai_virtual_assistant-0.3.6-py3-none-any.whl ├── ai_virtual_assistant-0.3.7-py3-none-any.whl ├── ai_virtual_assistant-0.3.8-py3-none-any.whl ├── ai_virtual_assistant-0.3.9-py3-none-any.whl ├── ai_virtual_assistant-1.0.0-py3-none-any.whl ├── ai_virtual_assistant-1.0.1-py3-none-any.whl ├── ai_virtual_assistant-1.0.2-py3-none-any.whl ├── ai_virtual_assistant-1.0.3-py3-none-any.whl └── ai_virtual_assistant-1.0.4-py3-none-any.whl ├── main.py ├── manual_installation.md ├── manual_setup.py ├── requirements.txt ├── run.py ├── run ├── __init__.py ├── cp_run.py ├── main.py └── run.py ├── settings ├── .trained ├── __init__.py ├── _first_load_.py ├── bot.json ├── compiler.py ├── config.py ├── default.conf ├── logs.py ├── settings.conf └── settings.py ├── setup.py ├── setup.py.bc4d43a15726dde0ae1be748c656face.py ├── system ├── __about__.py ├── __init__.py ├── features_installation.py ├── get_time.py ├── install.py ├── internet.py ├── notifications.py ├── path.py └── screen_text.py └── tools ├── AI ├── .learnt ├── __init__.py ├── ai.py ├── conversations.json └── data.py ├── ConfigParser.py ├── OJ ├── __init__.py ├── client.py ├── cp.py ├── socket_manager.py ├── test.cpp └── testing.py ├── TODO_management.py ├── __init__.py ├── assistant.py ├── browser ├── __init__.py ├── goto.py └── search.py ├── calculation.py ├── credits.py ├── downloader.py ├── google_answer.py ├── interaction ├── __init__.py ├── get_audio.py └── speak.py ├── json_manager.py ├── run_program.py ├── shell.py ├── string_processing.py └── wiki_search.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | build 3 | .vim 4 | .vscode 5 | x.py 6 | test.py 7 | *.log 8 | *.pickle 9 | test.py 10 | test_main.py 11 | 12 | -------------------------------------------------------------------------------- /.status: -------------------------------------------------------------------------------- 1 | {"status": "error", "messages": ["onlinejudge.type.LoginError: failed to login"], "result": null} 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Saurav Paul 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge,copies of the Software, and to permit persons to 9 | whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md LICENSE.txt req.txt requirements.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI virtual assitant 2 | 3 | It is a terminal-based virtual assistant especially made for competitive programming. It has a lot of features, including running python or c++ file, parsing problem set with test cases and test against all the cases in one click, test with brute force solution, and many more. It will help you to boost your programming skill and help you to do a good performance in the programming contest. 4 | 5 | It can give voice reply and take your voice command. You can turn off or on these features. Basic settings can be easily changed from config option. 6 | 7 | For installing write the given commands, 8 | 9 | > pip3 install wheel 10 | 11 | and 12 | 13 | > pip3 install ai-virtual-assistant 14 | 15 | I recommand after installing checkout the config file. 16 | The config can be open by the given command, 17 | 18 | > jarvis -config 19 | 20 | ![Welcome](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20welcome%20screen.png) 21 | 22 | ## Programming Features 23 | 24 | - [x] [Run c++ or python program](#run-python-or-cpp-program) 25 | - [x] [Competitive Companion Support](#Competitive-companion) 26 | - [x] [parse problemset](#Parsing-Problem-from-online-judge) 27 | - [x] [generate file with template](#generate-file-with-template) 28 | - [x] [test code against testcases](#Test-solution) 29 | - [x] [add testcase](#Add-testcase) 30 | - [x] [bruteforce test solution](#Test-solution-with-bruteforce) 31 | - [x] [Generate-testcase-genarator-automatically](#Generate-testcase-genarator-automatically) 32 | - [x] [login online judge](#login-and-submit-to-online-judge) 33 | - [x] [submit code](#Login-and-Submit-to-online-Judge) 34 | - [x] [Parse contest](#parsing-contest) 35 | - [x] [Cf tool mode](#cf-tool-mode) 36 | 37 | ## Other Features 38 | 39 | - [x] [Speaking Capability](#speaking-and-voice-command) 40 | - [x] [taking voice command](#speaking-and-voice-command) 41 | - [x] [Speech Recognition](#speech-recognition) 42 | - [x] [Ai to answer quesion](#AI-to-answer-question) 43 | - [x] [goto any website](#goto-website) 44 | - [x] [solving math](#solve-math) 45 | - [x] [wiki search](#wiki-search) 46 | - [x] [google search](#search-google) 47 | - [x] [YouTube search & play videos](#search-youtube) 48 | - [x] [install python module](#) 49 | - [x] [learn from answer](#) 50 | - [x] [download files](#download-files) 51 | - [x] [access from anywhere](#) 52 | 53 | --- 54 | 55 | ### [setup competitive companion](#Competitive-companion) 56 | 57 | ### [Installation](#Installation) 58 | 59 | --- 60 | 61 | ## Run python or cpp program 62 | 63 | Any python or c++ files from the current directory can be run using one command. The command is given below, 64 | 65 | > jarvis -r "file_name" 66 | 67 | or, 68 | 69 | > Cp -r "file_name" 70 | 71 | If you don't specify the file_name, it will list all the available python and c++ files in the current directory and you have to choose. 72 | 73 | You can run in debug mode. Debug mode is running C++ file with custom flags. The command for running in debug mode is given below, 74 | 75 | > Cp -r -d 76 | 77 | If you want to run the program more than one time you can do that. I thing this is one of the useful command because it helps to check mulitple tests in just one command and one compilation , that saves time. The command for running more than one time is given below, 78 | 79 | > Cp -r -'number of times' 80 | 81 | If you want to keep executable file after running, you can use '-c' command, 82 | 83 | An example is given below, 84 | 85 | > Cp -r -c -3 'file_name' 86 | 87 | with debug, 88 | 89 | > Cp -r -cd -3 'file_name' 90 | 91 | it will run jarvis in debug mode and it will run 3 times. And after execution, it will keep the executable file. 92 | 93 | ![Running program](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20run%20program.png) 94 | 95 | ## Parsing Problem from online judge 96 | 97 | Competitive Companion support makes parsing problems really very easy. Just give the command, 98 | 99 | > jarvis -cp parse 100 | 101 | or, 102 | 103 | > Cp parse 104 | 105 | or, 106 | 107 | > jarvis -cp listen 108 | 109 | or, 110 | 111 | > Cp listen 112 | 113 | Here -cp represent competitive programming, 114 | 115 | It will start listening, then you can just click the competitive companion browser extension. It will parse the problem. 116 | 117 | After parsing there will create a new folder according to the contest name and in that folder will be another folder according to the problem name. And it will contain all the sample test cases of that problem. 118 | 119 | ![parsing-problem](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20parse%20using%20competitive%20companion.png) 120 | 121 | Also, the problem can be parsed without competitive companion though I don't recommend this. the command is given below, 122 | 123 | > jarvis -cp parse link 124 | 125 | or 126 | 127 | > Cp parse link 128 | 129 | 130 | There is another way possible for parsing problem using id, which only works for 131 | codeforces. The command is, 132 | 133 | > Cp parse id 134 | 135 | 136 | After giving the command it will ask for the problem URL. Just give the URL,it will parse the problem. There will be created a folder according to the problem name. And it will contain all the sample test cases of that problem. 137 | 138 | 139 | *If you want to automtically open in editor after parsing you need to specify your editor from config option. By default it is set as None.* 140 | 141 | 142 | ![parsing-problem](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/parsing%20problem.png) 143 | 144 | ## Generate File with Template 145 | 146 | You can easily generate your file with the template by the given command, 147 | 148 | > jarvis -cp -t "file_name" 149 | 150 | or 151 | 152 | > Cp -t "file_name" 153 | 154 | If you don't specify the file_name it will be automatically created as "sol.cpp". You can create a python or c++ file. 155 | 156 | You have to specify your template path. Just open config file and find template_path and give your path for c++ and python. 157 | 158 | You can use variables in your template file which you will be replaced, 159 | 160 | variable available, 161 | 162 | - $%CODER%$ 163 | - $%DATE_TIME%$ 164 | - $%PROBLEM_NAME%$ 165 | - $%PROBLEM_URL%$ 166 | - $%TIMELIMIT%$ 167 | - $%MEMORYLIMIT%$ 168 | 169 | $%CODER%$ will be replaced by your name. It can be specified in coder_name in config file. Otherwise just change boss name from config. Boss name will be automatically mirrored to the coder_name. 170 | 171 | $%DATE_TIME%$ will be replaced by your file creating time and date. 172 | 173 | Example : 174 | 175 | Template file, 176 | 177 | ```c++ 178 | 179 | /** 180 | * author: $%CODER%$ 181 | * created: $%DATE_TIME%$ 182 | **/ 183 | 184 | #include 185 | using namespace std; 186 | 187 | int main(){ 188 | 189 | 190 | 191 | return 0; 192 | } 193 | 194 | ``` 195 | 196 | Genarated file, 197 | 198 | ```c++ 199 | 200 | /** 201 | * author: Saurav Paul 202 | * created: Jun 06 2020 9:05 PM 203 | **/ 204 | 205 | #include 206 | using namespace std; 207 | 208 | int main(){ 209 | 210 | 211 | 212 | return 0; 213 | } 214 | 215 | ``` 216 | 217 | ![genarating file](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/template_c%2B%2B.png) 218 | 219 | ## Test solution 220 | 221 | After parsing problem set, the solution can be tested by the given command, 222 | 223 | > jarvis -cp test "filename" 224 | 225 | or 226 | 227 | > Cp test "filename" 228 | 229 | *Giving filename is optional* 230 | 231 | It will run all the sample and custom cases from the test folder(Test folder contains all the sample cases after parsing problem set) and check whether your solution is passed. It will show the taken time for running each case. If your code failed any test cases it will show the differences between the correct answer and your output. If every case passed then it will show passed. 232 | 233 | It is not necessary to have a parsed problem set for using this command. You can make a test folder and add input(.in) and output(.out) case into that folder and then run this command. 234 | 235 | > Cp test --show 236 | 237 | This command will show full datails even solution passed against testcases. 238 | 239 | ![Test-solution](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20testing%20program.png) 240 | 241 | ![Test-solution-with-diff-table](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/fdab4b8b2c7c0dc2996a33b155c9c23cbdae32d5/images/jarvis%20test%20diff%20table%20new.png) 242 | 243 | ## Add Testcase 244 | 245 | Adding testcase is really very easy. Just give the command, 246 | 247 | > jarvis -cp add 248 | 249 | or 250 | 251 | > Cp add 252 | 253 | Yes, that simple :sunglasses: . 254 | 255 | It will ask for input and output for your new case. Then it will add this case. 256 | 257 | ## Test solution with bruteforce 258 | 259 | If you have any doubts about your optimal solution, then you can write a brute-force solution and write a random test case generator. You can test your optimal solution with a brute force solution using a random test case. 260 | 261 | For that, you need three files. 262 | 263 | 1. Main solution 264 | 2. Bruteforce solution 265 | 3. Testcase Generator (My AI can generate it automatically) 266 | 267 | Then run this command, 268 | 269 | > jarvis -cp brute 270 | 271 | or 272 | 273 | > Cp brute 274 | 275 | It will ask for the number of times you want to generate random test cases and test solutions (Stress). 276 | 277 | It will match output with the brute-force solution's output. If it failed, it will show the differences and ask you to add this to your test case so that you can test this later. Otherwise, it will show Accepted :smile: . 278 | 279 | ![bruteforce-solution](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20bruteforce.png) 280 | 281 | ## Generate testcase generator automatically 282 | 283 | Test case generator can be generated using the given command, 284 | 285 | > jarvis -cp gen 286 | 287 | or 288 | 289 | > Cp gen 290 | 291 | It will analyze all the sample cases and generate gen.py(Test case generator) automatically. Yes, sometimes it might fail (In case of complex test cases). 292 | In this case, you have to write a generator manually (You can write in python or c++). 293 | 294 | There is also one command, to generate gen.py, brute.cpp(empty file) and sol.cpp(with your template). The command is given below, 295 | 296 | > jarvis -cp setup 297 | 298 | or 299 | 300 | > Cp setup 301 | 302 | ![testcase generator](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20automatically%20setup.png) 303 | 304 | ## Login and submit to online Judge 305 | 306 | For login write the given command, 307 | 308 | > jarvis -cp login 309 | 310 | or 311 | 312 | > Cp login 313 | 314 | It will open login page in browser. You need webdriver for that purpose. 315 | Install webdriver for your browser. It's really very easy. 316 | 317 | 318 | For submitting code just write the given command, 319 | 320 | > jarvis -cp submit 321 | 322 | or 323 | 324 | > Cp submit 325 | 326 | N.B.: I have used online-judge-api-client for login and submitting codes. 327 | 328 | ![login and submitting demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20login%20and%20submit.png) 329 | 330 | ## Parsing contest 331 | 332 | Parsing contest is the same as parsing problems using the competitive companion. Just write command, 333 | 334 | > jarvis -cp parse 335 | 336 | or 337 | 338 | > Cp parse 339 | 340 | then it will start listening, then just open the contest link and click the browser extension, it will parse all the problems and create a folder for each contest with their test cases. 341 | 342 | Also, the contest can be parsed without competitive companion though I don't recommend this. the command is given below, 343 | 344 | > jarvis -cp parse contest 345 | 346 | or 347 | 348 | > Cp parse contest 349 | 350 | It will ask for the contest link. Then it will parse all the problems. 351 | 352 | ## cf tool mode 353 | 354 | If you use cf tool for submiting and racing contest. You can use enable this mode. 355 | If cf tool mode is enable it will use cf-tool for submitting problem in codeforces. 356 | 357 | You can enable this mode from config option. 358 | 359 | ## Open problem page in browser 360 | 361 | You can open problem in browser by the given command, 362 | 363 | > Cp open 364 | 365 | You have to be in problem folder. 366 | 367 | ## Open standing page in browser 368 | 369 | You can open standing page in browser by the given command, 370 | 371 | > Cp stand 372 | 373 | or 374 | 375 | > Cp stand 376 | 377 | You have to be in problem folder. 378 | 379 | --- 380 | 381 | ## Speaking and voice command 382 | 383 | This ai can speak with you. It will reply in voice and text both. You can toggle them from config. 384 | 385 | You can also give voice commands. But you have turned this feature on from config. 386 | 387 | For opening config option just write the following command, 388 | 389 | > jarvis -config 390 | 391 | ## Speech Recognition 392 | 393 | Jarvis can recognize the speech using google voice recognition API. 394 | 395 | ## AI to answer question 396 | 397 | As the name suggests you can have chat with it. You can ask jarvis a question, it will reply to you with his intelligence. 398 | 399 | ## goto website 400 | 401 | To be honest this is one of my favorite features. You can ask Jarvis to go to any websites as with wish. It will open that in your browser. 402 | 403 | The command is given below, 404 | 405 | > Jarvis goto "website name" 406 | 407 | It will open codeforces contest page for you. Basically, you can ask him to go to any website you want. 408 | 409 | It is okay to make some typing mistakes while writing a website name. It will still find it out. 410 | 411 | ![goto-demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20goto.png) 412 | 413 | ## Solve Math 414 | 415 | This ai can solve simple math. Just ask him to solve it will solve it for you. 416 | 417 | The command is given below, 418 | 419 | > jarvis solve ( "math" ) 420 | 421 | ![math-solving-demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20math%20solving%20.png) 422 | 423 | ## wiki search 424 | 425 | For searching something on wikipedia the command is given below, 426 | 427 | > jarvis search wikipedia "your text" 428 | 429 | ## Search google 430 | 431 | For searching something on google the command is given below, 432 | 433 | > jarvis search google "your text" 434 | 435 | ## Search youtube 436 | 437 | For searching something on youtube the command is given below, 438 | 439 | > jarvis search youtube "your text" 440 | 441 | ## Play video on youtube 442 | 443 | > jarvis play youtube "song name" 444 | 445 | ## Download Files 446 | 447 | For downloading the command is given below, 448 | 449 | > jarvis download 450 | 451 | Then it will ask for the download link. 452 | 453 | --- 454 | 455 | ## Config 456 | 457 | If you want to change settings, write the given command, 458 | 459 | > jarvis -config 460 | 461 | ## Competitive companion 462 | 463 | Competitive companion is a browser extension that helps to parse problems from various online judges in just one click. 464 | 465 | For setting the competitive companion, you have to install the extension to your browser. Just search google, you will find the extension. 466 | 467 | By default this project listens on port 10043, which is a port Competitive Companion already sends parsed problems to by default. If you change the port this project listens on for problems received from Competitive Companion, you'll need to make sure Competitive Companion is properly configured to send problems to that port. To do this, right-click on the extension icon and click "Manage Extension". Then go to "Preferences" and add the port to the "Custom ports" field. 468 | 469 | To open config write the following command, 470 | 471 | > jarvis -config 472 | 473 | --- 474 | 475 | # Installation 476 | 477 | Pre-requirements : 478 | 479 | 1. Python-3.5+ 480 | 2. Pip3 481 | 482 | For installing write the given commands, 483 | 484 | > pip3 install wheel 485 | 486 | and 487 | 488 | > pip3 install ai-virtual-assistant 489 | 490 | I recommand after installing checkout the config file. 491 | The config can be open by the given command, 492 | 493 | > jarvis -config 494 | 495 | N.B : It works fine on Linux. It also should work on Mac os. Unfortunately, it has some problems with windows. If you want to install on windows, you have to install it via WSL(Windows Subsystem for Linux). 496 | 497 | ### If you want to contribute on this project you are welcome. 498 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/__init__.py -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: ai-virtual-assistant 3 | Version: 1.0.4 4 | Summary: CLI virtual assitant for competitive programming 5 | Home-page: https://github.com/Saurav-Paul/AI-virtual-assistant-python 6 | Author: Saurav Paul 7 | Author-email: sauravpaul.sunny@gmail.com 8 | License: MIT License 9 | Description: # AI virtual assitant 10 | 11 | It is a terminal-based virtual assistant especially made for competitive programming. It has a lot of features, including running python or c++ file, parsing problem set with test cases and test against all the cases in one click, test with brute force solution, and many more. It will help you to boost your programming skill and help you to do a good performance in the programming contest. 12 | 13 | It can give voice reply and take your voice command. You can turn off or on these features. Basic settings can be easily changed from config option. 14 | 15 | For installing write the given commands, 16 | 17 | > pip3 install wheel 18 | 19 | and 20 | 21 | > pip3 install ai-virtual-assistant 22 | 23 | I recommand after installing checkout the config file. 24 | The config can be open by the given command, 25 | 26 | > jarvis -config 27 | 28 | ![Welcome](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20welcome%20screen.png) 29 | 30 | ## Programming Features 31 | 32 | - [x] [Run c++ or python program](#run-python-or-cpp-program) 33 | - [x] [Competitive Companion Support](#Competitive-companion) 34 | - [x] [parse problemset](#Parsing-Problem-from-online-judge) 35 | - [x] [generate file with template](#generate-file-with-template) 36 | - [x] [test code against testcases](#Test-solution) 37 | - [x] [add testcase](#Add-testcase) 38 | - [x] [bruteforce test solution](#Test-solution-with-bruteforce) 39 | - [x] [Generate-testcase-genarator-automatically](#Generate-testcase-genarator-automatically) 40 | - [x] [login online judge](#login-and-submit-to-online-judge) 41 | - [x] [submit code](#Login-and-Submit-to-online-Judge) 42 | - [x] [Parse contest](#parsing-contest) 43 | - [x] [Cf tool mode](#cf-tool-mode) 44 | 45 | ## Other Features 46 | 47 | - [x] [Speaking Capability](#speaking-and-voice-command) 48 | - [x] [taking voice command](#speaking-and-voice-command) 49 | - [x] [Speech Recognition](#speech-recognition) 50 | - [x] [Ai to answer quesion](#AI-to-answer-question) 51 | - [x] [goto any website](#goto-website) 52 | - [x] [solving math](#solve-math) 53 | - [x] [wiki search](#wiki-search) 54 | - [x] [google search](#search-google) 55 | - [x] [YouTube search & play videos](#search-youtube) 56 | - [x] [install python module](#) 57 | - [x] [learn from answer](#) 58 | - [x] [download files](#download-files) 59 | - [x] [access from anywhere](#) 60 | 61 | --- 62 | 63 | ### [setup competitive companion](#Competitive-companion) 64 | 65 | ### [Installation](#Installation) 66 | 67 | --- 68 | 69 | ## Run python or cpp program 70 | 71 | Any python or c++ files from the current directory can be run using one command. The command is given below, 72 | 73 | > jarvis -r "file_name" 74 | 75 | or, 76 | 77 | > Cp -r "file_name" 78 | 79 | If you don't specify the file_name, it will list all the available python and c++ files in the current directory and you have to choose. 80 | 81 | You can run in debug mode. Debug mode is running C++ file with custom flags. The command for running in debug mode is given below, 82 | 83 | > Cp -r -d 84 | 85 | If you want to run the program more than one time you can do that. I thing this is one of the useful command because it helps to check mulitple tests in just one command and one compilation , that saves time. The command for running more than one time is given below, 86 | 87 | > Cp -r -'number of times' 88 | 89 | If you want to keep executable file after running, you can use '-c' command, 90 | 91 | An example is given below, 92 | 93 | > Cp -r -c -3 'file_name' 94 | 95 | with debug, 96 | 97 | > Cp -r -cd -3 'file_name' 98 | 99 | it will run jarvis in debug mode and it will run 3 times. And after execution, it will keep the executable file. 100 | 101 | ![Running program](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20run%20program.png) 102 | 103 | ## Parsing Problem from online judge 104 | 105 | Competitive Companion support makes parsing problems really very easy. Just give the command, 106 | 107 | > jarvis -cp parse 108 | 109 | or, 110 | 111 | > Cp parse 112 | 113 | or, 114 | 115 | > jarvis -cp listen 116 | 117 | or, 118 | 119 | > Cp listen 120 | 121 | Here -cp represent competitive programming, 122 | 123 | It will start listening, then you can just click the competitive companion browser extension. It will parse the problem. 124 | 125 | After parsing there will create a new folder according to the contest name and in that folder will be another folder according to the problem name. And it will contain all the sample test cases of that problem. 126 | 127 | ![parsing-problem](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20parse%20using%20competitive%20companion.png) 128 | 129 | Also, the problem can be parsed without competitive companion though I don't recommend this. the command is given below, 130 | 131 | > jarvis -cp parse link 132 | 133 | or 134 | 135 | > Cp parse link 136 | 137 | 138 | There is another way possible for parsing problem using id, which only works for 139 | codeforces. The command is, 140 | 141 | > Cp parse id 142 | 143 | 144 | After giving the command it will ask for the problem URL. Just give the URL,it will parse the problem. There will be created a folder according to the problem name. And it will contain all the sample test cases of that problem. 145 | 146 | 147 | *If you want to automtically open in editor after parsing you need to specify your editor from config option. By default it is set as None.* 148 | 149 | 150 | ![parsing-problem](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/parsing%20problem.png) 151 | 152 | ## Generate File with Template 153 | 154 | You can easily generate your file with the template by the given command, 155 | 156 | > jarvis -cp -t "file_name" 157 | 158 | or 159 | 160 | > Cp -t "file_name" 161 | 162 | If you don't specify the file_name it will be automatically created as "sol.cpp". You can create a python or c++ file. 163 | 164 | You have to specify your template path. Just open config file and find template_path and give your path for c++ and python. 165 | 166 | You can use variables in your template file which you will be replaced, 167 | 168 | variable available, 169 | 170 | - $%CODER%$ 171 | - $%DATE_TIME%$ 172 | - $%PROBLEM_NAME%$ 173 | - $%PROBLEM_URL%$ 174 | - $%TIMELIMIT%$ 175 | - $%MEMORYLIMIT%$ 176 | 177 | $%CODER%$ will be replaced by your name. It can be specified in coder_name in config file. Otherwise just change boss name from config. Boss name will be automatically mirrored to the coder_name. 178 | 179 | $%DATE_TIME%$ will be replaced by your file creating time and date. 180 | 181 | Example : 182 | 183 | Template file, 184 | 185 | ```c++ 186 | 187 | /** 188 | * author: $%CODER%$ 189 | * created: $%DATE_TIME%$ 190 | **/ 191 | 192 | #include 193 | using namespace std; 194 | 195 | int main(){ 196 | 197 | 198 | 199 | return 0; 200 | } 201 | 202 | ``` 203 | 204 | Genarated file, 205 | 206 | ```c++ 207 | 208 | /** 209 | * author: Saurav Paul 210 | * created: Jun 06 2020 9:05 PM 211 | **/ 212 | 213 | #include 214 | using namespace std; 215 | 216 | int main(){ 217 | 218 | 219 | 220 | return 0; 221 | } 222 | 223 | ``` 224 | 225 | ![genarating file](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/template_c%2B%2B.png) 226 | 227 | ## Test solution 228 | 229 | After parsing problem set, the solution can be tested by the given command, 230 | 231 | > jarvis -cp test "filename" 232 | 233 | or 234 | 235 | > Cp test "filename" 236 | 237 | *Giving filename is optional* 238 | 239 | It will run all the sample and custom cases from the test folder(Test folder contains all the sample cases after parsing problem set) and check whether your solution is passed. It will show the taken time for running each case. If your code failed any test cases it will show the differences between the correct answer and your output. If every case passed then it will show passed. 240 | 241 | It is not necessary to have a parsed problem set for using this command. You can make a test folder and add input(.in) and output(.out) case into that folder and then run this command. 242 | 243 | > Cp test --show 244 | 245 | This command will show full datails even solution passed against testcases. 246 | 247 | ![Test-solution](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20testing%20program.png) 248 | 249 | ![Test-solution-with-diff-table](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/fdab4b8b2c7c0dc2996a33b155c9c23cbdae32d5/images/jarvis%20test%20diff%20table%20new.png) 250 | 251 | ## Add Testcase 252 | 253 | Adding testcase is really very easy. Just give the command, 254 | 255 | > jarvis -cp add 256 | 257 | or 258 | 259 | > Cp add 260 | 261 | Yes, that simple :sunglasses: . 262 | 263 | It will ask for input and output for your new case. Then it will add this case. 264 | 265 | ## Test solution with bruteforce 266 | 267 | If you have any doubts about your optimal solution, then you can write a brute-force solution and write a random test case generator. You can test your optimal solution with a brute force solution using a random test case. 268 | 269 | For that, you need three files. 270 | 271 | 1. Main solution 272 | 2. Bruteforce solution 273 | 3. Testcase Generator (My AI can generate it automatically) 274 | 275 | Then run this command, 276 | 277 | > jarvis -cp brute 278 | 279 | or 280 | 281 | > Cp brute 282 | 283 | It will ask for the number of times you want to generate random test cases and test solutions (Stress). 284 | 285 | It will match output with the brute-force solution's output. If it failed, it will show the differences and ask you to add this to your test case so that you can test this later. Otherwise, it will show Accepted :smile: . 286 | 287 | ![bruteforce-solution](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20bruteforce.png) 288 | 289 | ## Generate testcase generator automatically 290 | 291 | Test case generator can be generated using the given command, 292 | 293 | > jarvis -cp gen 294 | 295 | or 296 | 297 | > Cp gen 298 | 299 | It will analyze all the sample cases and generate gen.py(Test case generator) automatically. Yes, sometimes it might fail (In case of complex test cases). 300 | In this case, you have to write a generator manually (You can write in python or c++). 301 | 302 | There is also one command, to generate gen.py, brute.cpp(empty file) and sol.cpp(with your template). The command is given below, 303 | 304 | > jarvis -cp setup 305 | 306 | or 307 | 308 | > Cp setup 309 | 310 | ![testcase generator](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20automatically%20setup.png) 311 | 312 | ## Login and submit to online Judge 313 | 314 | For login write the given command, 315 | 316 | > jarvis -cp login 317 | 318 | or 319 | 320 | > Cp login 321 | 322 | It will open login page in browser. You need webdriver for that purpose. 323 | Install webdriver for your browser. It's really very easy. 324 | 325 | 326 | For submitting code just write the given command, 327 | 328 | > jarvis -cp submit 329 | 330 | or 331 | 332 | > Cp submit 333 | 334 | N.B.: I have used online-judge-api-client for login and submitting codes. 335 | 336 | ![login and submitting demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20login%20and%20submit.png) 337 | 338 | ## Parsing contest 339 | 340 | Parsing contest is the same as parsing problems using the competitive companion. Just write command, 341 | 342 | > jarvis -cp parse 343 | 344 | or 345 | 346 | > Cp parse 347 | 348 | then it will start listening, then just open the contest link and click the browser extension, it will parse all the problems and create a folder for each contest with their test cases. 349 | 350 | Also, the contest can be parsed without competitive companion though I don't recommend this. the command is given below, 351 | 352 | > jarvis -cp parse contest 353 | 354 | or 355 | 356 | > Cp parse contest 357 | 358 | It will ask for the contest link. Then it will parse all the problems. 359 | 360 | ## cf tool mode 361 | 362 | If you use cf tool for submiting and racing contest. You can use enable this mode. 363 | If cf tool mode is enable it will use cf-tool for submitting problem in codeforces. 364 | 365 | You can enable this mode from config option. 366 | 367 | ## Open problem page in browser 368 | 369 | You can open problem in browser by the given command, 370 | 371 | > Cp open 372 | 373 | You have to be in problem folder. 374 | 375 | ## Open standing page in browser 376 | 377 | You can open standing page in browser by the given command, 378 | 379 | > Cp stand 380 | 381 | or 382 | 383 | > Cp stand 384 | 385 | You have to be in problem folder. 386 | 387 | --- 388 | 389 | ## Speaking and voice command 390 | 391 | This ai can speak with you. It will reply in voice and text both. You can toggle them from config. 392 | 393 | You can also give voice commands. But you have turned this feature on from config. 394 | 395 | For opening config option just write the following command, 396 | 397 | > jarvis -config 398 | 399 | ## Speech Recognition 400 | 401 | Jarvis can recognize the speech using google voice recognition API. 402 | 403 | ## AI to answer question 404 | 405 | As the name suggests you can have chat with it. You can ask jarvis a question, it will reply to you with his intelligence. 406 | 407 | ## goto website 408 | 409 | To be honest this is one of my favorite features. You can ask Jarvis to go to any websites as with wish. It will open that in your browser. 410 | 411 | The command is given below, 412 | 413 | > Jarvis goto "website name" 414 | 415 | It will open codeforces contest page for you. Basically, you can ask him to go to any website you want. 416 | 417 | It is okay to make some typing mistakes while writing a website name. It will still find it out. 418 | 419 | ![goto-demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20goto.png) 420 | 421 | ## Solve Math 422 | 423 | This ai can solve simple math. Just ask him to solve it will solve it for you. 424 | 425 | The command is given below, 426 | 427 | > jarvis solve ( "math" ) 428 | 429 | ![math-solving-demo](https://github.com/Saurav-Paul/Saurav-Paul.github.io/blob/master/images/jarvis%20math%20solving%20.png) 430 | 431 | ## wiki search 432 | 433 | For searching something on wikipedia the command is given below, 434 | 435 | > jarvis search wikipedia "your text" 436 | 437 | ## Search google 438 | 439 | For searching something on google the command is given below, 440 | 441 | > jarvis search google "your text" 442 | 443 | ## Search youtube 444 | 445 | For searching something on youtube the command is given below, 446 | 447 | > jarvis search youtube "your text" 448 | 449 | ## Play video on youtube 450 | 451 | > jarvis play youtube "song name" 452 | 453 | ## Download Files 454 | 455 | For downloading the command is given below, 456 | 457 | > jarvis download 458 | 459 | Then it will ask for the download link. 460 | 461 | --- 462 | 463 | ## Config 464 | 465 | If you want to change settings, write the given command, 466 | 467 | > jarvis -config 468 | 469 | ## Competitive companion 470 | 471 | Competitive companion is a browser extension that helps to parse problems from various online judges in just one click. 472 | 473 | For setting the competitive companion, you have to install the extension to your browser. Just search google, you will find the extension. 474 | 475 | By default this project listens on port 10043, which is a port Competitive Companion already sends parsed problems to by default. If you change the port this project listens on for problems received from Competitive Companion, you'll need to make sure Competitive Companion is properly configured to send problems to that port. To do this, right-click on the extension icon and click "Manage Extension". Then go to "Preferences" and add the port to the "Custom ports" field. 476 | 477 | To open config write the following command, 478 | 479 | > jarvis -config 480 | 481 | --- 482 | 483 | # Installation 484 | 485 | Pre-requirements : 486 | 487 | 1. Python-3.5+ 488 | 2. Pip3 489 | 490 | For installing write the given commands, 491 | 492 | > pip3 install wheel 493 | 494 | and 495 | 496 | > pip3 install ai-virtual-assistant 497 | 498 | I recommand after installing checkout the config file. 499 | The config can be open by the given command, 500 | 501 | > jarvis -config 502 | 503 | N.B : It works fine on Linux. It also should work on Mac os. Unfortunately, it has some problems with windows. If you want to install on windows, you have to install it via WSL(Windows Subsystem for Linux). 504 | 505 | ### If you want to contribute on this project you are welcome. 506 | 507 | Keywords: ai virtual assitant 508 | Platform: UNKNOWN 509 | Classifier: Development Status :: 5 - Production/Stable 510 | Classifier: Environment :: Console 511 | Classifier: Intended Audience :: End Users/Desktop 512 | Classifier: Operating System :: POSIX :: Linux 513 | Classifier: Operating System :: MacOS :: MacOS X 514 | Classifier: License :: OSI Approved :: MIT License 515 | Requires-Python: >=3.5 516 | Description-Content-Type: text/markdown 517 | -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE.txt 2 | MANIFEST.in 3 | README.md 4 | requirements.txt 5 | setup.py 6 | ai_virtual_assistant.egg-info/PKG-INFO 7 | ai_virtual_assistant.egg-info/SOURCES.txt 8 | ai_virtual_assistant.egg-info/dependency_links.txt 9 | ai_virtual_assistant.egg-info/entry_points.txt 10 | ai_virtual_assistant.egg-info/requires.txt 11 | ai_virtual_assistant.egg-info/top_level.txt 12 | data/__init__.py 13 | data/data.py 14 | data/get_template.py 15 | run/__init__.py 16 | run/cp_run.py 17 | run/main.py 18 | run/run.py 19 | settings/__init__.py 20 | settings/_first_load_.py 21 | settings/compiler.py 22 | settings/config.py 23 | settings/logs.py 24 | settings/settings.py 25 | system/__about__.py 26 | system/__init__.py 27 | system/features_installation.py 28 | system/get_time.py 29 | system/install.py 30 | system/internet.py 31 | system/notifications.py 32 | system/path.py 33 | system/screen_text.py 34 | tools/ConfigParser.py 35 | tools/TODO_management.py 36 | tools/__init__.py 37 | tools/assistant.py 38 | tools/calculation.py 39 | tools/credits.py 40 | tools/downloader.py 41 | tools/google_answer.py 42 | tools/json_manager.py 43 | tools/run_program.py 44 | tools/shell.py 45 | tools/string_processing.py 46 | tools/wiki_search.py 47 | tools/AI/__init__.py 48 | tools/AI/ai.py 49 | tools/AI/data.py 50 | tools/OJ/__init__.py 51 | tools/OJ/client.py 52 | tools/OJ/cp.py 53 | tools/OJ/socket_manager.py 54 | tools/OJ/test.py 55 | tools/OJ/testing.py 56 | tools/browser/__init__.py 57 | tools/browser/goto.py 58 | tools/browser/search.py 59 | tools/interaction/__init__.py 60 | tools/interaction/get_audio.py 61 | tools/interaction/speak.py -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/entry_points.txt: -------------------------------------------------------------------------------- 1 | [console_scripts] 2 | CP = run.cp_run:cp_start 3 | Cp = run.cp_run:cp_start 4 | ai = run.run:start 5 | jarvis = run.run:start 6 | 7 | -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4 2 | fuzzywuzzy 3 | google 4 | lxml 5 | online-judge-api-client 6 | online-judge-tools 7 | plyer 8 | pyfiglet 9 | requests 10 | tcgen 11 | termcolor 12 | tqdm 13 | wget 14 | wikipedia-api 15 | wolframalpha 16 | selenium 17 | -------------------------------------------------------------------------------- /ai_virtual_assistant.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | data 2 | run 3 | settings 4 | system 5 | tools 6 | -------------------------------------------------------------------------------- /data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/data/__init__.py -------------------------------------------------------------------------------- /data/cpp_template.txt: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * author: $%CODER%$ 4 | * created: $%DATE_TIME%$ 5 | * @genarated by ai-virtual-assistant 6 | **/ 7 | 8 | #include 9 | using namespace std; 10 | 11 | int main(){ 12 | ios_base::sync_with_stdio(false); 13 | 14 | 15 | return 0 ; 16 | } 17 | -------------------------------------------------------------------------------- /data/cpp_template_info.txt: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * author : $%CODER%$ 4 | * created : $%DATE_TIME%$ 5 | * Problem Name : $%PROBLEM_NAME%$ 6 | * Problem Limit : $%TIMELIMIT%$ , $%MEMORYLIMIT%$ 7 | * Problem Url : $%PROBLEM_URL%$ 8 | * @genarated by : ai-virtual-assistant 9 | **/ 10 | 11 | #include 12 | using namespace std; 13 | 14 | int main(){ 15 | ios_base::sync_with_stdio(false); 16 | 17 | 18 | 19 | return 0 ; 20 | } 21 | -------------------------------------------------------------------------------- /data/data.py: -------------------------------------------------------------------------------- 1 | 2 | bye = [ 3 | 'bye','tata' , 'exit' , 'quit' ,'stop' , 4 | ] 5 | -------------------------------------------------------------------------------- /data/get_template.py: -------------------------------------------------------------------------------- 1 | import os 2 | from system.path import getpath 3 | 4 | def get_template(fileName): 5 | path = getpath(__file__) 6 | writen = '' 7 | with open(os.path.join(path,fileName),'r') as f: 8 | writen = f.read() 9 | 10 | return writen 11 | 12 | if __name__ == "__main__": 13 | print(get_template('cpp_template.txt') ) 14 | print(get_template('py_template.txt') ) -------------------------------------------------------------------------------- /data/py_template.txt: -------------------------------------------------------------------------------- 1 | """ 2 | author: $%CODER%$ 3 | created: $%DATE_TIME%$ 4 | @genarated by ai-virtual-assistant 5 | 6 | """ 7 | -------------------------------------------------------------------------------- /data/py_template_info.txt: -------------------------------------------------------------------------------- 1 | """ 2 | author : $%CODER%$ 3 | created : $%DATE_TIME%$ 4 | Problem Name : $%PROBLEM_NAME%$ 5 | Problem Url : $%PROBLEM_URL%$ 6 | Problem Limit : $%TIMELIMIT%$ , $%MEMORYLIMIT%$ 7 | Problem Url : $%PROBLEM_URL%$ 8 | @genarated by : ai-virtual-assistant 9 | 10 | """ 11 | -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.0.7-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.0.7-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.0.8-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.0.8-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.0.9-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.0.9-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.0-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.6-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.7-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.7-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.8-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.8-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.1.9-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.1.9-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.0-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.6-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.7-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.7-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.8-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.8-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.2.9-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.2.9-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.0-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.6-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.7-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.7-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.8-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.8-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-0.3.9-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-0.3.9-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-1.0.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-1.0.0-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-1.0.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-1.0.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-1.0.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-1.0.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-1.0.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-1.0.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/ai_virtual_assistant-1.0.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/dist/ai_virtual_assistant-1.0.4-py3-none-any.whl -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ python3 2 | 3 | from tools.interaction.speak import speak 4 | from tools.interaction.get_audio import get_audio 5 | from tools.AI.ai import ai 6 | from settings.logs import * 7 | from data.data import bye 8 | from tools.string_processing import string_process 9 | from system.screen_text import asci_banner , line_sep , clear_screen 10 | from settings.settings import START_SCREEN_NAME 11 | from tools.AI.data import google 12 | import os 13 | 14 | def check_done(msg): 15 | for i in google: 16 | if i in msg: 17 | return False 18 | for i in bye: 19 | if i in msg: 20 | return True 21 | return False 22 | 23 | def main(get='',orginal_path='') : 24 | 25 | logger.debug('Bot starts at ' + str(os.getcwd())) 26 | asci_banner(' '+START_SCREEN_NAME) 27 | if get == '': 28 | speak('Hello sir, how can I help you?') 29 | while True : 30 | get =string_process(get_audio()) 31 | print() 32 | if check_done(get): 33 | break 34 | if get == 'clear': 35 | clear_screen() 36 | else : 37 | msg = ai(get,orginal_path) 38 | speak(msg) 39 | line_sep() 40 | speak('Good Bye Sir.') 41 | asci_banner('BYE!') 42 | else : 43 | msg = ai(get,orginal_path) 44 | speak(msg) 45 | line_sep(t=2) 46 | logger.debug('Bot stopped.') 47 | 48 | 49 | if __name__ == "__main__": 50 | main() 51 | 52 | -------------------------------------------------------------------------------- /manual_installation.md: -------------------------------------------------------------------------------- 1 | # need to install few dependency 2 | 3 | ## incase you are running linux first run this 4 | 5 | * sudo apt-get install python3-dev build-essential 6 | * playsound -> plaing sound 7 | 8 | * pip3 install playsound 9 | 10 | * gTTS 11 | * pip3 install gTTS 12 | * S peechRecognition 13 | * pip3 install SpeechRecognition 14 | * pyaudio 15 | * sudo apt-get install python3-pyaudio 16 | * google 17 | * pip3 install google 18 | * wikipedia 19 | * pip3 install wikipedia 20 | 21 | 22 | * install them through pip3 23 | - requests==2.22.0 24 | - lxml==4.4.1 25 | - google==2.0.2 26 | - beautifulsoup4==4.8.0 27 | 28 | * install wolframalpha 29 | * pip3 install wolframalpha 30 | * pickle 31 | * pip3 install pickle-mixin 32 | * pyfiglet 33 | * pip3 install pyfiglet 34 | * pip3 install tcgen 35 | 36 | * fuzzy 37 | * pip3 install fuzzywuzzy 38 | * pip3 install python-Levenshtein-wheels 39 | * pip3 install python-Levenshtein 40 | 41 | * pyttsx3 42 | * pip3 install pyttsx3 43 | * pip3 install pypiwin32 # Windows 44 | * plyer 45 | * pip3 install plyer 46 | 47 | * wget 48 | * pip3 install wget 49 | * tqdm 50 | * pip3 install tqdm 51 | 52 | 53 | * pip3 install online-judge-api-client 54 | * pip3 install online-judge-tools 55 | * pip3 install online-judge-template-generator 56 | * pip3 install tqdm 57 | * pip3 install termcolor -------------------------------------------------------------------------------- /manual_setup.py: -------------------------------------------------------------------------------- 1 | 2 | from os import system,name 3 | 4 | def setup(): 5 | # system('pip3 install -i requirements.txt') 6 | # for windows 7 | if name == 'nt': 8 | print("System found : Windows.") 9 | system('pip3 install pypiwin32') 10 | 11 | # for mac and linux(here, os.name is 'posix') 12 | else: 13 | print("System found : Linux.") 14 | system('sudo apt-get install python3-dev build-essential') 15 | system('sudo apt-get install python3-pyaudio') 16 | system('pip3 install pyttsx3') 17 | 18 | with open('requirements.txt') as f: 19 | need = f.read() 20 | 21 | system("pip install wheel") 22 | lt = need.split('\n') 23 | # print(lt) 24 | ok = True 25 | for module in lt: 26 | if module == '': 27 | continue 28 | try : 29 | system('pip3 install '+module) 30 | except: 31 | print("Can't install "+module + " :(") 32 | ok = False 33 | 34 | if ok: 35 | print('\nSetup is completed.') 36 | 37 | 38 | if __name__ == "__main__": 39 | setup() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4 2 | fuzzywuzzy 3 | google 4 | lxml 5 | online-judge-api-client 6 | online-judge-tools 7 | pickle-mixin 8 | ply 9 | plyer 10 | psutil 11 | PyAudio 12 | pyfiglet 13 | python-Levenshtein 14 | python-Levenshtein-wheels 15 | pyttsx3 16 | requests 17 | SpeechRecognition 18 | tcgen 19 | termcolor 20 | tqdm 21 | wget 22 | wikipedia 23 | wolframalpha 24 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | from settings._first_load_ import check_if_first_time 2 | from main import main 3 | import sys , os 4 | from settings.settings import read_bot 5 | from system.path import getpath 6 | 7 | 8 | def get_args(lt,lim): 9 | get = '' 10 | for i in range(1,lim): 11 | get += str(lt[i]) + ' ' 12 | return get.strip() 13 | 14 | def all_args(lt): 15 | ok = False 16 | arg = '' 17 | for w in lt: 18 | if ok: 19 | arg += w +' ' 20 | if w=='-arg': 21 | ok = True 22 | return arg.strip() 23 | 24 | def make_path(lt,lim): 25 | path = '' 26 | ok = False 27 | for i in range(1,lim): 28 | if lt[i] == '-arg': 29 | break 30 | if ok: 31 | path += ' ' 32 | path += lt[i] 33 | ok = True 34 | return path 35 | 36 | if __name__ == "__main__": 37 | try : 38 | total = len(sys.argv) 39 | lt = list(sys.argv) 40 | if '-arg' in lt: 41 | # orginal_path = lt[0] 42 | # orginal_path = orginal_path[0:len(orginal_path)-6] 43 | # print(orginal_path) 44 | orginal_path = getpath(__file__) 45 | p = str(sys.argv) 46 | file_path = make_path(lt,total) 47 | os.chdir(file_path) 48 | # print(orginal_path) 49 | arg = all_args(lt) 50 | main(arg,orginal_path) 51 | else : 52 | arg = get_args(lt,len(lt)) 53 | main(arg.strip() , orginal_path=os.getcwd()) 54 | 55 | except Exception as e: 56 | # print(e) 57 | main(orginal_path=os.getcwd()) 58 | 59 | 60 | def start(): 61 | try : 62 | total = len(sys.argv) 63 | lt = list(sys.argv) 64 | if '-arg' in lt: 65 | # orginal_path = lt[0] 66 | # orginal_path = orginal_path[0:len(orginal_path)-6] 67 | # print(orginal_path) 68 | orginal_path = getpath(__file__) 69 | p = str(sys.argv) 70 | file_path = make_path(lt,total) 71 | os.chdir(file_path) 72 | # print(orginal_path) 73 | arg = all_args(lt) 74 | main(arg,orginal_path) 75 | else : 76 | arg = get_args(lt,len(lt)) 77 | main(arg.strip() , orginal_path=os.getcwd()) 78 | 79 | except Exception as e: 80 | # print(e) 81 | main(orginal_path=os.getcwd()) 82 | 83 | -------------------------------------------------------------------------------- /run/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/run/__init__.py -------------------------------------------------------------------------------- /run/cp_run.py: -------------------------------------------------------------------------------- 1 | from settings._first_load_ import check_if_first_time 2 | import sys , os 3 | from termcolor import cprint 4 | import random 5 | 6 | def print_start_name(name,weight,name_col,border_col) : 7 | spaceno = weight - len(name) - 2 8 | spaceno = int(spaceno/2) 9 | cprint('-'*weight , border_col) 10 | cprint('|'+' '*spaceno ,border_col,end='' ) 11 | cprint(name,name_col,end='') 12 | cprint(' '*spaceno + '|',border_col) 13 | cprint('-'*weight , border_col) 14 | 15 | 16 | 17 | def cp_start(): 18 | 19 | try : 20 | 21 | color = ['magenta','yellow','cyan','blue'] 22 | pt = 50 23 | name_col = random.choice(color) 24 | border_col = random.choice(color) 25 | print_start_name('ai-virtual-assistant',50 ,name_col,border_col) 26 | 27 | pt = '-'*pt 28 | cprint(pt,border_col) 29 | # from system.screen_text import asci_banner 30 | from tools.OJ.cp import cp_manager 31 | # from settings.settings import START_SCREEN_NAME 32 | # asci_banner(' '+START_SCREEN_NAME) 33 | # total = len(sys.argv) 34 | lt = list(sys.argv) 35 | lt = lt[1:] 36 | msg = '' 37 | for w in lt: 38 | msg +=w+' ' 39 | status = cp_manager(msg.strip()) 40 | 41 | cprint(pt,border_col) 42 | cprint(f' (^-^) -> Good luck sir.','green') 43 | cprint(pt,border_col) 44 | 45 | if status == '$SHELL' : 46 | os.system('$SHELL') 47 | 48 | except : 49 | cprint("Can't open sir.",'red') 50 | -------------------------------------------------------------------------------- /run/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ python3 2 | 3 | from tools.interaction.speak import speak 4 | from tools.interaction.get_audio import get_audio 5 | from tools.AI.ai import ai 6 | from settings.logs import * 7 | from data.data import bye 8 | from tools.string_processing import string_process 9 | from system.screen_text import asci_banner , line_sep , clear_screen 10 | from settings.settings import START_SCREEN_NAME 11 | from tools.AI.data import google 12 | import os 13 | 14 | def check_done(msg): 15 | for i in google: 16 | if i in msg: 17 | return False 18 | for i in bye: 19 | if i in msg: 20 | return True 21 | return False 22 | 23 | def main(get='',orginal_path='') : 24 | 25 | logger.debug('Bot starts at ' + str(os.getcwd())) 26 | asci_banner(START_SCREEN_NAME) 27 | if get == '': 28 | speak('Hello sir, how can I help you?') 29 | while True : 30 | get =string_process(get_audio()) 31 | print() 32 | if check_done(get): 33 | break 34 | if get == 'clear': 35 | clear_screen() 36 | else : 37 | msg = ai(get,orginal_path) 38 | speak(msg) 39 | line_sep() 40 | speak('Good Bye Sir.') 41 | asci_banner('BYE!') 42 | else : 43 | msg = ai(get,orginal_path) 44 | speak(msg) 45 | line_sep(t=2) 46 | logger.debug('Bot stopped.') 47 | 48 | 49 | if __name__ == "__main__": 50 | main() -------------------------------------------------------------------------------- /run/run.py: -------------------------------------------------------------------------------- 1 | from settings._first_load_ import check_if_first_time 2 | from run.main import main 3 | import sys , os 4 | from settings.settings import read_bot 5 | from system.path import getpath 6 | from termcolor import cprint 7 | 8 | def get_args(lt,lim): 9 | get = '' 10 | for i in range(1,lim): 11 | get += str(lt[i]) + ' ' 12 | return get.strip() 13 | 14 | def all_args(lt): 15 | ok = False 16 | arg = '' 17 | for w in lt: 18 | if ok: 19 | arg += w +' ' 20 | if w=='-arg': 21 | ok = True 22 | return arg.strip() 23 | 24 | def make_path(lt,lim): 25 | path = '' 26 | ok = False 27 | for i in range(1,lim): 28 | if lt[i] == '-arg': 29 | break 30 | if ok: 31 | path += ' ' 32 | path += lt[i] 33 | ok = True 34 | return path 35 | 36 | if __name__ == "__main__": 37 | try : 38 | total = len(sys.argv) 39 | lt = list(sys.argv) 40 | if '-arg' in lt: 41 | # orginal_path = lt[0] 42 | # orginal_path = orginal_path[0:len(orginal_path)-6] 43 | # print(orginal_path) 44 | orginal_path = getpath(__file__) 45 | p = str(sys.argv) 46 | file_path = make_path(lt,total) 47 | os.chdir(file_path) 48 | # print(orginal_path) 49 | arg = all_args(lt) 50 | main(arg,orginal_path) 51 | else : 52 | arg = get_args(lt,len(lt)) 53 | main(arg.strip() , orginal_path=os.getcwd()) 54 | 55 | except Exception as e: 56 | # print(e) 57 | main(orginal_path=os.getcwd()) 58 | 59 | 60 | def start(): 61 | try : 62 | total = len(sys.argv) 63 | lt = list(sys.argv) 64 | if '-arg' in lt: 65 | # orginal_path = lt[0] 66 | # orginal_path = orginal_path[0:len(orginal_path)-6] 67 | # print(orginal_path) 68 | orginal_path = getpath(__file__) 69 | p = str(sys.argv) 70 | file_path = make_path(lt,total) 71 | os.chdir(file_path) 72 | # print(orginal_path) 73 | arg = all_args(lt) 74 | main(arg,orginal_path) 75 | else : 76 | arg = get_args(lt,len(lt)) 77 | main(arg.strip() , orginal_path=os.getcwd()) 78 | 79 | except Exception as e: 80 | # print(e) 81 | main(orginal_path=os.getcwd()) 82 | 83 | 84 | 85 | # def cp_start(): 86 | 87 | # try : 88 | # from system.screen_text import asci_banner 89 | # from tools.OJ.cp import cp_manager 90 | # from settings.settings import START_SCREEN_NAME 91 | # asci_banner(START_SCREEN_NAME) 92 | # total = len(sys.argv) 93 | # lt = list(sys.argv) 94 | # lt = lt[1:] 95 | # msg = '' 96 | # for w in lt: 97 | # msg +=w+' ' 98 | # cp_manager(msg.strip()) 99 | 100 | # pt = '-'*50 101 | # cprint(pt,'magenta') 102 | # cprint(f' (^-^) -> Good luck sir.','green') 103 | # cprint(pt,'magenta') 104 | 105 | # except Exception as e: 106 | # # print(e) 107 | # main(orginal_path=os.getcwd()) -------------------------------------------------------------------------------- /settings/.trained: -------------------------------------------------------------------------------- 1 | {"Who is sushant singh?": "An indian actor.", "tell me about sushant singh": "Sushant Singh Rajput (21 January 1986 \u2013 14 June 2020) was an Indian actor. Rajput started his career with television serials.", "tell me about kk": "Krishnakumar Kunnath (popularly known as KK, K.K.", "star wars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "tell me about bighero": "Big Hero 6 is a 2014 American 3D computer animated superhero film produced by Walt Disney Animation Studios and released by Walt Disney Pictures. Loosely based on the superhero team of the same name by Marvel Comics, the film is the 54th Disney animated feature film.", "tell me about starwars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "tell me about superman": "Superman is a fictional superhero. The character was created by writer Jerry Siegel and artist Joe Shuster, and first appeared in Action Comics #1, a comic book published on April 18, 1938.", "what is a umbrella": "An umbrella or parasol is a folding canopy supported by wooden or metal ribs that is usually mounted on a wooden, metal, or plastic pole. It is designed to protect a person against rain or sunlight.", "starwars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "Who is me ?": "You are my boss. ", "botany": "Botany, also called plant science(s), plant biology or phytology, is the science of plant life and a branch of biology. A botanist, plant scientist or phytologist is a scientist who specialises in this field.", "tell me about sunlight": "Sunlight is a portion of the electromagnetic radiation given off by the Sun, in particular infrared, visible, and ultraviolet light. On Earth, sunlight is scattered and filtered through Earth's atmosphere, and is obvious as daylight when the Sun is above the horizon.", "I am bored": "Talk to your friend sir."} -------------------------------------------------------------------------------- /settings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/settings/__init__.py -------------------------------------------------------------------------------- /settings/_first_load_.py: -------------------------------------------------------------------------------- 1 | import os 2 | from tools.ConfigParser import ConfigParser_manager as CM 3 | from system.path import getpath 4 | from termcolor import cprint 5 | 6 | conf_path = os.path.join(getpath(__file__),'settings.conf') 7 | default_path = os.path.join(getpath(__file__),'default.conf') 8 | export_file_name = 'ai_virtual_assistant_configs.conf' 9 | 10 | def import_settings(): 11 | if not os.path.exists(export_file_name): 12 | return False 13 | else : 14 | cprint(' Export file exists. Do you want import(y/n) : ','cyan',end='') 15 | confirm = input() 16 | positive = ['y', 'yes', 'ok', 'okay'] 17 | if confirm.lower() in positive : 18 | from settings.settings import all_sections 19 | try : 20 | obj = CM() 21 | for section in all_sections : 22 | data = obj.read(export_file_name,section = section) 23 | conf_data = obj.read(conf_path,section = section) 24 | 25 | for key in conf_data: 26 | try : 27 | x = data[key] 28 | conf_data[key] = x 29 | except: 30 | pass 31 | obj.update(conf_path,conf_data,section = section) 32 | 33 | cprint(" Configs are successfully imported.",'green') 34 | return True 35 | 36 | except Exception as e: 37 | cprint(f" Sorry sir can't import. Error : {e}",'red') 38 | return False 39 | else : 40 | return False 41 | 42 | 43 | def first_time() : 44 | pt = 22 * '-' + 'First time setup' + 22 * '-' 45 | done = import_settings() 46 | 47 | if done : 48 | return 49 | 50 | try : 51 | with open(default_path) as f : 52 | default_value = f.read() 53 | with open(conf_path,'w') as f : 54 | f.write(default_value) 55 | except Exception as e: 56 | cprint(e,'red') 57 | 58 | cprint(pt,'magenta') 59 | print() 60 | cprint(" (^-^) Enter your name : ",'cyan',end='') 61 | name = input() 62 | section = 'bot' 63 | obj = CM() 64 | x = obj.read(conf_path,section) 65 | x['boss'] = name 66 | obj.update(conf_path,x,section) 67 | 68 | print() 69 | cprint(f' (^-^) Hello {name} , do you want me to speak ?(Y/N) ','cyan',end='') 70 | confirm = input() 71 | positive_keys = ['y','yes','ok','okay'] 72 | if confirm.lower() in positive_keys: 73 | from system.features_installation import install_speaking_system 74 | install_speaking_system() 75 | section = 'interaction_setting' 76 | x = obj.read(conf_path,section) 77 | x['voice_reply'] = 'True' 78 | obj.update(conf_path,x,section) 79 | else : 80 | section = 'interaction_setting' 81 | x = obj.read(conf_path,section) 82 | x['voice_reply'] = 'False' 83 | obj.update(conf_path,x,section) 84 | 85 | 86 | print() 87 | 88 | cprint(f' (^-^) Hello {name} , do you want me to work faster ?(Y/N) ','cyan',end='') 89 | confirm = input() 90 | positive_keys = ['y','yes','ok','okay'] 91 | if confirm.lower() in positive_keys: 92 | from system.features_installation import speed_up 93 | speed_up() 94 | 95 | print() 96 | print() 97 | cprint(len(pt)*'-','magenta') 98 | from system.screen_text import clear_screen 99 | clear_screen(start=False) 100 | 101 | def check_if_first_time(): 102 | section = 'start_time' 103 | obj = CM() 104 | dic = obj.read(conf_path,section) 105 | if dic['first_start'] == 'False': 106 | return False 107 | else : 108 | first_time() 109 | dic['first_start'] = 'False' 110 | obj.update(conf_path,dic,section) 111 | return True 112 | pass 113 | 114 | check_if_first_time() 115 | -------------------------------------------------------------------------------- /settings/bot.json: -------------------------------------------------------------------------------- 1 | {"name": "Paul", "gender": "male", "Boss": "Saurav Paul", "voice_engine": "robotic"} -------------------------------------------------------------------------------- /settings/compiler.py: -------------------------------------------------------------------------------- 1 | from tools.ConfigParser import ConfigParser_manager as CM 2 | from system.path import getpath 3 | import os 4 | from termcolor import cprint 5 | from settings.settings import bot 6 | 7 | positive = ['yes','1','true'] 8 | 9 | compiler = { 10 | "c++" : "g++ '{filename}' -o '{executable}' && ./'{executable}'", 11 | "c++ debug" : "g++ -std=c++17 -O2 -DPAUL -Wshift-overflow=2 -Wshadow -Wall '{filename}' -o '{executable}' && ./'{executable}'", 12 | "python" :"python3 '{filename}'", 13 | 14 | } 15 | 16 | template_path = { 17 | 'c++' :'/media/saurav/Programming/GIthub/Code-Lab/geany/ai_template.cpp', 18 | 'python':'/media/saurav/Programming/GIthub/Code-Lab/geany/ai_template.py', 19 | } 20 | cf_tool_mode = False 21 | 22 | DEBUG = True 23 | editor = '$NONE' 24 | editor_name = 'NONE' 25 | coder_name = bot['boss'] 26 | competitive_companion_port = 10043 27 | parse_problem_with_template = True # If true, after parsing all the codes will contain a file name sol.cpp (with your template) 28 | 29 | 30 | conf_path = os.path.join(getpath(__file__),'settings.conf') 31 | 32 | try : 33 | 34 | section = 'cp' 35 | obj = CM() 36 | x = obj.read(conf_path,section = section) 37 | coder_name = x['coder_name'] 38 | 39 | try : 40 | editor = x['editor'] 41 | editor_name = x['editor_name'] 42 | except : 43 | pass 44 | 45 | if x['cf_tool_mode'] == 'True': 46 | cf_tool_mode = True 47 | 48 | if coder_name == "${boss}": 49 | coder_name = bot['boss'] 50 | 51 | competitive_companion_port = int(x['competitive_companion_port']) 52 | parse_problem_with_template = x['parse_problem_with_template'] 53 | if parse_problem_with_template.lower() in positive: 54 | parse_problem_with_template = True 55 | else: 56 | parse_problem_with_template = False 57 | 58 | section = 'template_path' 59 | x = obj.read(conf_path,section= section) 60 | 61 | template_path['c++'] = x['cpp'] 62 | template_path['python'] = x['python'] 63 | 64 | section = 'compiler' 65 | x = obj.read(conf_path,section) 66 | 67 | compiler['c++'] = x['cpp'] 68 | compiler['c++ debug'] = x['cpp_debug'] 69 | compiler['python'] = x['python'] 70 | 71 | section = 'developer' 72 | x = obj.read(conf_path,section=section) 73 | 74 | if x['debug'].lower() in positive: 75 | DEBUG = True 76 | else : 77 | DEBUG = False 78 | 79 | 80 | except Exception as e: 81 | print(e) 82 | cprint("Settings error.",'red') 83 | 84 | def update_ccp(port): 85 | global competitive_companion_port 86 | competitive_companion_port = port 87 | 88 | def update_tp(x): 89 | global template_path 90 | template_path = x 91 | 92 | def update_compiler(x): 93 | global compiler 94 | compiler = x 95 | 96 | def update_cf_mode(x) : 97 | global cf_tool_mode 98 | cf_tool_mode = x 99 | -------------------------------------------------------------------------------- /settings/config.py: -------------------------------------------------------------------------------- 1 | from tools.ConfigParser import ConfigParser_manager as CM 2 | from system.path import getpath 3 | import os 4 | from termcolor import cprint 5 | from settings.settings import bot as bt 6 | from settings.settings import interaction_setting as its 7 | from settings.settings import update_bot 8 | from tools.json_manager import JsonManager as JM 9 | 10 | config_keys = ['-config','-settings'] 11 | conf_path = os.path.join(getpath(__file__),'settings.conf') 12 | default_path = os.path.join(getpath(__file__),'default.conf') 13 | train_path = os.path.join(getpath(__file__),'.trained') 14 | 15 | yes = ['yes','y'] 16 | 17 | class Config: 18 | export_file_name = 'ai_virtual_assistant_configs.conf' 19 | obj = CM() 20 | lt = ['Bot','Interaction','Competitive Programming','Features Installation','Training Mode','Export/Import settings'] 21 | cp = [ 22 | 'Coder Name', 23 | 'Competitive companion port number', 24 | 'Parse Problem with template', 25 | 'Template Path', 26 | 'Compiler' 27 | ] 28 | confirm_keys = ['y','yes','ok'] 29 | def change_gender(self): 30 | pt = '-'*22 + 'Gender Change' +'-'*22 31 | cprint(pt,'magenta') 32 | print() 33 | cprint(f" Current gender : {bt['gender']}",'yellow') 34 | cprint(" Enter new gender : ",'cyan',end='') 35 | new_name = input() 36 | cprint(" Do you want to update?(Y/N) : ",'cyan',end='') 37 | confirm = input() 38 | if confirm.lower() in yes: 39 | section = 'bot' 40 | x = self.obj.read(conf_path,section) 41 | x['gender'] = new_name 42 | self.obj.update(conf_path,x,section) 43 | bt['gender'] = new_name 44 | update_bot(bt) 45 | cprint("Gender Changed successfully.",'green') 46 | else : 47 | cprint("Cancelled.",'red') 48 | 49 | 50 | def change_name(self): 51 | pt = '-'*22 + 'Name Change' +'-'*22 52 | cprint(pt,'magenta') 53 | print() 54 | cprint(f" Current Name : {bt['name']}",'yellow') 55 | cprint(" Enter new name : ",'cyan',end='') 56 | new_name = input() 57 | cprint(" Do you want to update?(Y/N) : ",'cyan',end='') 58 | confirm = input() 59 | if confirm.lower() in yes: 60 | section = 'bot' 61 | x = self.obj.read(conf_path,section) 62 | x['name'] = new_name 63 | self.obj.update(conf_path,x,section) 64 | bt['name'] = new_name 65 | update_bot(bt) 66 | cprint("Name Changed successfully.",'green') 67 | else : 68 | cprint("Cancelled.",'red') 69 | 70 | def change_boss(self): 71 | 72 | pt = '-'*22 + 'Boss Change' +'-'*22 73 | cprint(pt,'magenta') 74 | print() 75 | cprint(f" Current Boss : {bt['boss']}",'yellow') 76 | cprint(" Enter new boss : ",'cyan',end='') 77 | new_name = input() 78 | cprint(" Do you want to update?(Y/N) : ",'cyan',end='') 79 | confirm = input() 80 | if confirm.lower() in yes: 81 | section = 'bot' 82 | x = self.obj.read(conf_path,section) 83 | x['boss'] = new_name 84 | self.obj.update(conf_path,x,section) 85 | bt['boss'] = new_name 86 | update_bot(bt) 87 | cprint("Boss Changed successfully.",'green') 88 | else : 89 | cprint("Cancelled.",'red') 90 | 91 | def change_voice_engine(self): 92 | pt = '-'*22 + 'Voice Engine Change' +'-'*22 93 | cprint(pt,'magenta') 94 | print() 95 | cprint(f" Current voice engine : {bt['boss']}",'yellow') 96 | 97 | 98 | def bot(self,no): 99 | bot = [ 100 | 'Name', 101 | 'Gender', 102 | 'Boss', 103 | 'Voice_engine' 104 | ] 105 | pt = '-'*22 + self.lt[no] +'-'*22 106 | cprint(pt,'magenta') 107 | cprint(" Select the index to change,",'yellow') 108 | 109 | print() 110 | # print(bt) 111 | for i,w in enumerate(bot): 112 | cprint(f' {i+1}) {w} : {bt[w.lower()]}','blue') 113 | cprint(' 0) Cancel','red') 114 | print() 115 | ok = True 116 | 117 | while ok: 118 | ok = False 119 | cprint(" Enter the index number : ",'cyan',end='') 120 | no = int(input()) 121 | if no == 0: 122 | cprint(" Operation cancelled.",'red') 123 | return 124 | elif no == 1: 125 | cprint(f' You have selected {bot[no-1]} .','yellow') 126 | self.change_name() 127 | elif no == 2: 128 | cprint(f' You have selected {bot[no-1]} .','yellow') 129 | self.change_gender() 130 | elif no == 3: 131 | cprint(f' You have selected {bot[no-1]} .','yellow') 132 | self.change_boss() 133 | elif no == 4: 134 | cprint(" Sorry temporary this option is unavailable.",'red') 135 | ok = True 136 | continue 137 | cprint(f' You have selected {bot[no-1]} .','yellow') 138 | self.change_voice_engine() 139 | else : 140 | ok = True 141 | cprint(" You have selected wrong index. Please try again.",'red') 142 | 143 | 144 | 145 | def Interaction(self,no): 146 | 147 | options = [ 148 | 'voice_reply', 149 | 'text_reply', 150 | 'voice_read_voice_reply', 151 | 'text_read' 152 | ] 153 | pt = '-'*22 + self.lt[no] +'-'*22 154 | cprint(pt,'magenta') 155 | cprint(" Select the index to change,",'yellow') 156 | 157 | print() 158 | 159 | for i,w in enumerate(options): 160 | cprint(f' {i+1}) {w} : {its[w.lower()]}','blue') 161 | cprint(' 0) Cancel','red') 162 | print() 163 | ok = True 164 | 165 | while ok: 166 | ok = False 167 | cprint(" Enter the index number : ",'cyan',end='') 168 | no = int(input()) 169 | if no == 0: 170 | cprint(" Operation cancelled.",'red') 171 | return 172 | elif no == 1: 173 | cprint(f' You have selected {options[no-1]} .','yellow') 174 | key = options[no-1] 175 | if its[key] : 176 | cprint(f' Do you want to turn {key} to False?(Y/N) : ','cyan',end='') 177 | confirm = input() 178 | if confirm.lower() in yes: 179 | its[key] = False 180 | section = 'interaction_setting' 181 | x = self.obj.read(conf_path,section) 182 | x[key] = 'False' 183 | self.obj.update(conf_path,x,section) 184 | 185 | cprint(" Successfully updated.",'green') 186 | else : 187 | cprint("Cancelled.",'red') 188 | else : 189 | cprint(f' Do you want to turn {key} to True?(Y/N) : ','cyan',end='') 190 | confirm = input() 191 | if confirm.lower() in yes: 192 | try : 193 | from system.features_installation import install_speaking_system 194 | install_speaking_system() 195 | except: 196 | pass 197 | its[key] = True 198 | section = 'interaction_setting' 199 | x = self.obj.read(conf_path,section) 200 | x[key] = 'True' 201 | self.obj.update(conf_path,x,section) 202 | 203 | cprint(" Successfully updated.",'green') 204 | else : 205 | cprint("Cancelled.",'red') 206 | 207 | 208 | elif no == 2: 209 | cprint(f' You have selected {options[no-1]} .','yellow') 210 | key = options[no-1] 211 | if its[key] : 212 | cprint(f' Do you want to turn {key} to False?(Y/N) : ','cyan',end='') 213 | confirm = input() 214 | if confirm.lower() in yes: 215 | its[key] = False 216 | section = 'interaction_setting' 217 | x = self.obj.read(conf_path,section) 218 | x[key] = 'False' 219 | self.obj.update(conf_path,x,section) 220 | 221 | cprint(" Successfully updated.",'green') 222 | else : 223 | cprint("Cancelled.",'red') 224 | else : 225 | cprint(f' Do you want to turn {key} to True?(Y/N) : ','cyan',end='') 226 | confirm = input() 227 | if confirm.lower() in yes: 228 | its[key] = True 229 | section = 'interaction_setting' 230 | x = self.obj.read(conf_path,section) 231 | x[key] = 'True' 232 | self.obj.update(conf_path,x,section) 233 | 234 | cprint(" Successfully updated.",'green') 235 | else : 236 | cprint("Cancelled.",'red') 237 | 238 | elif no == 3: 239 | cprint(f' You have selected {options[no-1]} .','yellow') 240 | key = options[no-1] 241 | if its[key] : 242 | cprint(f' Do you want to turn {key} to False?(Y/N) : ','cyan',end='') 243 | confirm = input() 244 | if confirm.lower() in yes: 245 | its[key] = False 246 | section = 'interaction_setting' 247 | x = self.obj.read(conf_path,section) 248 | x[key] = 'False' 249 | self.obj.update(conf_path,x,section) 250 | 251 | cprint(" Successfully updated.",'green') 252 | else : 253 | cprint("Cancelled.",'red') 254 | else : 255 | cprint(f' Do you want to turn {key} to True?(Y/N) : ','cyan',end='') 256 | confirm = input() 257 | if confirm.lower() in yes: 258 | try : 259 | from system.features_installation import install_command_system,install_speaking_system 260 | install_speaking_system() 261 | install_command_system() 262 | except Exception as e: 263 | cprint(e,'red') 264 | 265 | its[key] = True 266 | section = 'interaction_setting' 267 | x = self.obj.read(conf_path,section) 268 | x[key] = 'True' 269 | self.obj.update(conf_path,x,section) 270 | 271 | cprint(" Successfully updated.",'green') 272 | else : 273 | cprint("Cancelled.",'red') 274 | 275 | elif no == 4: 276 | cprint(f' You have selected {options[no-1]} .','yellow') 277 | key = options[no-1] 278 | if its[key] : 279 | cprint(f' Do you want to turn {key} to False?(Y/N) : ','cyan',end='') 280 | confirm = input() 281 | if confirm.lower() in yes: 282 | its[key] = False 283 | section = 'interaction_setting' 284 | x = self.obj.read(conf_path,section) 285 | x[key] = 'False' 286 | self.obj.update(conf_path,x,section) 287 | 288 | cprint(" Successfully updated.",'green') 289 | else : 290 | cprint("Cancelled.",'red') 291 | else : 292 | cprint(f' Do you want to turn {key} to True?(Y/N) : ','cyan',end='') 293 | confirm = input() 294 | if confirm.lower() in yes: 295 | its[key] = True 296 | section = 'interaction_setting' 297 | x = self.obj.read(conf_path,section) 298 | x[key] = 'True' 299 | self.obj.update(conf_path,x,section) 300 | 301 | cprint(" Successfully updated.",'green') 302 | else : 303 | cprint("Cancelled.",'red') 304 | 305 | else : 306 | ok = True 307 | cprint(" You have selected wrong index. Please try again.",'red') 308 | 309 | def competitive_companion(self): 310 | try : 311 | from settings.compiler import competitive_companion_port as ccp, update_ccp 312 | pt = '-'*22 + 'Competitive Companion' +'-'*22 313 | cprint(pt,'magenta') 314 | print() 315 | 316 | cprint(" Current port number : " + str(ccp),'yellow') 317 | 318 | cprint(' 1) Change port.','blue') 319 | cprint(' 0) Back.','red') 320 | 321 | ok = True 322 | while ok: 323 | ok = False 324 | cprint(' Enter the index number : ','cyan',end='') 325 | no = int(input()) 326 | if no == 0: 327 | cprint(" Going back.",'red') 328 | self.competitve_programming() 329 | elif no == 1: 330 | print() 331 | cprint(" Enter new port number(must be integer) : ",'cyan',end='') 332 | port = int(input()) 333 | # ccp = port 334 | update_ccp(port) 335 | section = 'cp' 336 | x = self.obj.read(conf_path,section) 337 | x['competitive_companion_port'] = str(port) 338 | self.obj.update(conf_path,x,section) 339 | cprint(' Competitive companion port updated succussfully.','green') 340 | self.competitive_companion() 341 | else: 342 | cprint(" You have choosen wrong index.",'red') 343 | ok = True 344 | except Exception as e: 345 | cprint(e,'red') 346 | 347 | def dev_mode(self): 348 | 349 | from settings.settings import update_dev 350 | 351 | pt = '-'*10 + 'Welcome to secret mode for developer' +'-'*10 352 | cprint(pt,'magenta') 353 | print() 354 | section = 'developer' 355 | dev = self.obj.read(conf_path,section) 356 | options = { 357 | 'Debug Mode ': dev['debug'], 358 | 'Learning Mode ' : dev['learn'] 359 | } 360 | for i , w in enumerate(options): 361 | cprint(f' {i+1}) {w} : {options[w]}','blue') 362 | 363 | cprint(f' 0) Back','red') 364 | print() 365 | 366 | ok = True 367 | while ok: 368 | cprint("Enter index number : ",'cyan',end = '') 369 | no = int(input()) 370 | ok = False 371 | 372 | if no == 0 : 373 | cprint("Going Back.",'red') 374 | return 375 | elif no == 1: 376 | cprint("Do you want to toggle Debug mode ?(Y/N) : ",'cyan',end='') 377 | confirm = input() 378 | if confirm.lower() == 'y': 379 | if dev['debug'] == 'True': 380 | dev['debug'] = 'False' 381 | else : 382 | dev['debug'] = 'True' 383 | 384 | self.obj.update(conf_path,dev,section) 385 | update_dev(dev) 386 | cprint("Debug mode toggled successfully.",'green') 387 | else : 388 | cprint("Cancelled.",'red') 389 | self.dev_mode() 390 | elif no == 2: 391 | cprint("Do you want to toggle Learning mode ?(Y/N) : ",'cyan',end='') 392 | confirm = input() 393 | if confirm.lower() == 'y': 394 | if dev['learn'] == 'True': 395 | dev['learn'] = 'False' 396 | else : 397 | dev['learn'] = 'True' 398 | 399 | self.obj.update(conf_path,dev,section) 400 | update_dev(dev) 401 | cprint("Learning mode toggled successfully.",'green') 402 | else : 403 | cprint("Cancelled.",'red') 404 | self.dev_mode() 405 | else : 406 | cprint("Wrong index. Try again.") 407 | ok = True 408 | print() 409 | cprint('-'*len(pt),'magenta') 410 | 411 | def cpp_template(self): 412 | from settings.compiler import template_path as tp , update_tp 413 | pt = '-'*22 + 'c++ Template' +'-'*22 414 | cprint(pt,'magenta') 415 | print() 416 | cprint(f" Current Template : {tp['c++']}",'yellow') 417 | cprint(" Do you want to update?(Y/N) : ",'cyan',end='') 418 | confirm = input() 419 | 420 | if confirm.lower() not in yes: 421 | cprint(" Cancelled.",'red') 422 | return 423 | 424 | ok = True 425 | while ok : 426 | ok = False 427 | cprint(" Enter template path (enter cancel to cancel): ",'cyan',end='') 428 | path = input() 429 | 430 | if path.lower() == 'cancel': 431 | cprint(" Cancelled.",'red') 432 | return 433 | elif os.path.isfile(path): 434 | pt = '-'*22 +'code'+'-'*22 435 | cprint(pt,'magenta') 436 | 437 | with open(path) as f: 438 | code = f.read() 439 | cprint(code,'yellow') 440 | 441 | pt = '-'*46 442 | cprint(pt,'magenta') 443 | 444 | sec = 'template_path' 445 | x = self.obj.read(conf_path,sec) 446 | x['cpp'] = path 447 | tp['c++'] = path 448 | self.obj.update(conf_path,x,sec) 449 | update_tp(tp) 450 | cprint("C++ template updated successfully.",'green') 451 | else : 452 | ok = True 453 | cprint("Path doesn't exist. Try again.",'red') 454 | 455 | 456 | 457 | 458 | def python_template(self): 459 | from settings.compiler import template_path as tp , update_tp 460 | pt = '-'*22 + 'Python Template' +'-'*22 461 | cprint(pt,'magenta') 462 | print() 463 | cprint(f" Current Template : {tp['python']}",'yellow') 464 | cprint(" Do you want to update?(Y/N) : ",'cyan',end='') 465 | confirm = input() 466 | 467 | if confirm.lower() not in yes: 468 | cprint(" Cancelled.",'red') 469 | return 470 | 471 | ok = True 472 | while ok : 473 | ok = False 474 | cprint(" Enter template path (enter cancel to cancel): ",'cyan',end='') 475 | path = input() 476 | 477 | if path.lower() == 'cancel': 478 | cprint(" Cancelled.",'red') 479 | return 480 | elif os.path.isfile(path): 481 | pt = '-'*22 +'code'+'-'*22 482 | cprint(pt,'magenta') 483 | 484 | with open(path) as f: 485 | code = f.read() 486 | cprint(code,'yellow') 487 | 488 | pt = '-'*46 489 | cprint(pt,'magenta') 490 | 491 | sec = 'template_path' 492 | x = self.obj.read(conf_path,sec) 493 | x['python'] = path 494 | tp['python'] = path 495 | self.obj.update(conf_path,x,sec) 496 | update_tp(tp) 497 | cprint("Python template updated successfully.",'green') 498 | else : 499 | ok = True 500 | cprint("Path doesn't exist. Try again.",'red') 501 | 502 | 503 | 504 | 505 | def temp_path(self): 506 | try : 507 | 508 | optinos = [ 509 | 'C++', 510 | 'Python' 511 | ] 512 | pt = '-'*22 + 'Templates Path' +'-'*22 513 | cprint(pt,'magenta') 514 | print() 515 | cprint(" All the available settings are given below,",'yellow') 516 | 517 | print() 518 | # print(bt) 519 | for i,w in enumerate(optinos): 520 | cprint(f' {i+1}) {w}','blue') 521 | cprint(' 0) Cancel','red') 522 | print() 523 | ok = True 524 | 525 | while ok: 526 | ok = False 527 | cprint(" Enter the index number : ",'cyan',end='') 528 | no = int(input()) 529 | if no == 0: 530 | cprint(" Operation cancelled.",'red') 531 | return 532 | elif no == 1: 533 | cprint(f' You have selected {optinos[no-1]} .','yellow') 534 | self.cpp_template() 535 | elif no == 2: 536 | cprint(f' You have selected {optinos[no-1]} .','yellow') 537 | self.python_template() 538 | else : 539 | ok = True 540 | cprint(" You have selected wrong index. Please try again.",'red') 541 | 542 | 543 | 544 | except Exception as e: 545 | cprint(e,'red') 546 | 547 | def cpp_compiler(self): 548 | try : 549 | from settings.compiler import compiler, update_compiler 550 | pt = '-'*22 + 'C++ Compiler' +'-'*22 551 | cprint(pt,'magenta') 552 | print() 553 | # print(compiler) 554 | ccp = compiler['c++'] 555 | # print(ccp) 556 | cprint(" Current Compiling Command : ",'yellow',end='') 557 | cprint(str(ccp),'cyan') 558 | print() 559 | 560 | cprint(' 1) Change command.','blue') 561 | cprint(' 0) Back.','red') 562 | print() 563 | 564 | ok = True 565 | while ok: 566 | ok = False 567 | cprint(' Enter the index number : ','cyan',end='') 568 | no = int(input()) 569 | if no == 0: 570 | cprint(" Going back.",'red') 571 | self.competitve_programming() 572 | elif no == 1: 573 | print() 574 | cprint(" Enter new command(wrong command might broke c++ compiling and testing) : ",'cyan',end='') 575 | command = input() 576 | # ccp = port 577 | section = 'compiler' 578 | x = self.obj.read(conf_path,section) 579 | x['cpp'] = str(command) 580 | self.obj.update(conf_path,x,section) 581 | compiler['c++'] = command 582 | update_compiler(compiler) 583 | cprint(' C++ compiling command updated succussfully.','green') 584 | self.cpp_compiler() 585 | else: 586 | cprint(" You have choosen wrong index.",'red') 587 | ok = True 588 | except Exception as e: 589 | cprint(e,'red') 590 | def cpp_debug_compiler(self): 591 | try : 592 | from settings.compiler import compiler, update_compiler 593 | pt = '-'*22 + 'C++ Debug Compiler' +'-'*22 594 | cprint(pt,'magenta') 595 | print() 596 | # print(compiler) 597 | ccp = compiler['c++ debug'] 598 | # print(ccp) 599 | cprint(" Current Compiling Command : ",'yellow',end='') 600 | cprint(str(ccp),'cyan') 601 | print() 602 | 603 | cprint(' 1) Change command.','blue') 604 | cprint(' 0) Back.','red') 605 | print() 606 | 607 | ok = True 608 | while ok: 609 | ok = False 610 | cprint(' Enter the index number : ','cyan',end='') 611 | no = int(input()) 612 | if no == 0: 613 | cprint(" Going back.",'red') 614 | self.competitve_programming() 615 | elif no == 1: 616 | print() 617 | cprint(" Enter new command(wrong command might broke c++ debug compiling and testing) : ",'cyan',end='') 618 | command = input() 619 | # ccp = port 620 | section = 'compiler' 621 | x = self.obj.read(conf_path,section) 622 | x['cpp_debug'] = str(command) 623 | self.obj.update(conf_path,x,section) 624 | compiler['c++ debug'] = command 625 | update_compiler(compiler) 626 | cprint(' C++ debug compiling command updated succussfully.','green') 627 | self.cpp_debug_compiler() 628 | else: 629 | cprint(" You have choosen wrong index.",'red') 630 | ok = True 631 | except Exception as e: 632 | cprint(e,'red') 633 | 634 | def python_compiler(self): 635 | try : 636 | from settings.compiler import compiler, update_compiler 637 | pt = '-'*22 + 'Python Run Command' +'-'*22 638 | cprint(pt,'magenta') 639 | print() 640 | # print(compiler) 641 | ccp = compiler['python'] 642 | # print(ccp) 643 | cprint(" Current Run Command : ",'yellow',end='') 644 | cprint(str(ccp),'cyan') 645 | print() 646 | 647 | cprint(' 1) Change command.','blue') 648 | cprint(' 0) Back.','red') 649 | print() 650 | 651 | ok = True 652 | while ok: 653 | ok = False 654 | cprint(' Enter the index number : ','cyan',end='') 655 | no = int(input()) 656 | if no == 0: 657 | cprint(" Going back.",'red') 658 | self.competitve_programming() 659 | elif no == 1: 660 | print() 661 | cprint(" Enter new command(wrong command might broke running python file) : ",'cyan',end='') 662 | command = input() 663 | # ccp = port 664 | section = 'compiler' 665 | x = self.obj.read(conf_path,section) 666 | x['python'] = str(command) 667 | self.obj.update(conf_path,x,section) 668 | compiler['python'] = command 669 | update_compiler(compiler) 670 | cprint(' Python running command updated succussfully.','green') 671 | self.python_compiler() 672 | else: 673 | cprint(" You have choosen wrong index.",'red') 674 | ok = True 675 | except Exception as e: 676 | cprint(e,'red') 677 | 678 | def compiler_option(self): 679 | try : 680 | optinos = [ 681 | 'C++', 682 | 'C++ Debug', 683 | 'python' 684 | ] 685 | 686 | pt = '-'*22 + "Compiler" +'-'*22 687 | cprint(pt,'magenta') 688 | print() 689 | cprint(" All the available settings are given below,",'yellow') 690 | 691 | print() 692 | # print(bt) 693 | for i,w in enumerate(optinos): 694 | cprint(f' {i+1}) {w}','blue') 695 | cprint(' 0) Cancel','red') 696 | print() 697 | ok = True 698 | 699 | while ok: 700 | ok = False 701 | cprint(" Enter the index number : ",'cyan',end='') 702 | no = int(input()) 703 | if no == 0: 704 | cprint(" Operation cancelled.",'red') 705 | return 706 | elif no == 1: 707 | cprint(f' You have selected {optinos[no-1]} .','yellow') 708 | self.cpp_compiler() 709 | elif no == 2: 710 | cprint(f' You have selected {optinos[no-1]} .','yellow') 711 | self.cpp_debug_compiler() 712 | elif no == 3: 713 | cprint(f' You have selected {optinos[no-1]} .','yellow') 714 | self.python_compiler() 715 | else : 716 | ok = True 717 | cprint(" You have selected wrong index. Please try again.",'red') 718 | 719 | except Exception as e: 720 | cprint(e,'red') 721 | 722 | 723 | def cf_tool_function(self) : 724 | Nb =""" N.B: If you use cf tool, then enable this option.It will help you to use cf tool options and also your codeforces submit and other options will execute by cf tool.If you don't have cf tool and enable this option, it might break your submit system. """ 725 | 726 | try : 727 | from settings.compiler import cf_tool_mode , update_cf_mode 728 | pt = '-'*22 + 'Cf tool mode' +'-'*22 729 | cprint(pt,'magenta') 730 | print() 731 | 732 | cprint(" Cf tool mode : " + str(cf_tool_mode),'yellow') 733 | print() 734 | 735 | cprint(' 1) Toggle Mode.','blue') 736 | cprint(' 0) Back.','red') 737 | print() 738 | 739 | print() 740 | cprint(Nb,'magenta') 741 | print() 742 | 743 | ok = True 744 | while ok: 745 | ok = False 746 | cprint(' Enter the index number : ','cyan',end='') 747 | no = int(input()) 748 | if no == 0: 749 | cprint(" Going back.",'red') 750 | return 751 | elif no == 1: 752 | print() 753 | changeto = 'False' 754 | if cf_tool_mode == 'False' : 755 | changeto = 'True' 756 | section = 'cp' 757 | x = self.obj.read(conf_path,section) 758 | cf_tool_mode = changeto 759 | x['cf_tool_mode'] = changeto 760 | self.obj.update(conf_path,x,section) 761 | update_cf_mode(changeto) 762 | 763 | cprint(f' Cf tool mode change to {changeto}','green') 764 | self.cf_tool_function() 765 | else: 766 | cprint(" You have choosen wrong index.",'red') 767 | ok = True 768 | except Exception as e: 769 | cprint(e,'red') 770 | 771 | def after_parsing_open_with_and_editor(self): 772 | 773 | 774 | try : 775 | from settings.compiler import editor , editor_name 776 | pt = '-'*22 + 'Preferred Editor' +'-'*22 777 | cprint(pt,'magenta') 778 | print() 779 | 780 | cprint(" Current Editor : " + editor_name ,'yellow') 781 | print() 782 | 783 | cprint(' 1) Update Editor.','blue') 784 | cprint(' 0) Back.','red') 785 | print() 786 | 787 | ok = True 788 | while ok: 789 | ok = False 790 | cprint(' Enter the index number : ','cyan',end='') 791 | no = int(input()) 792 | if no == 0: 793 | cprint(" Going back.",'red') 794 | return 795 | elif no == 1: 796 | print() 797 | editors = { 798 | "Vs Code" : 'code', 799 | "Subline" : 'subl', 800 | "Neo Vim" : 'nvim', 801 | "Vim" : 'vim', 802 | "Others" : "", 803 | "NONE" : "$NONE" 804 | } 805 | 806 | i = 0 807 | 808 | options = [] 809 | 810 | for w in editors: 811 | cprint(f' {i+1}) {w}','blue') 812 | i += 1 813 | options.append(w) 814 | cprint(' 0) Cancel','red') 815 | print() 816 | ko = True 817 | 818 | 819 | while ko: 820 | ko = False 821 | cprint(" Enter the index number : ",'cyan',end='') 822 | no = int(input()) 823 | if no == 0: 824 | cprint(" Operation cancelled.",'red') 825 | return 826 | elif no == 1: 827 | cprint(f' You have selected {options[no-1]} .','yellow') 828 | editor_name = options[no-1] 829 | editor = editors[editor_name] 830 | elif no == 2: 831 | cprint(f' You have selected {options[no-1]} .','yellow') 832 | editor_name = options[no-1] 833 | editor = editors[editor_name] 834 | elif no == 3: 835 | cprint(f' You have selected {options[no-1]} .','yellow') 836 | editor_name = options[no-1] 837 | editor = editors[editor_name] 838 | elif no == 4: 839 | cprint(f' You have selected {options[no-1]} .','yellow') 840 | editor_name = options[no-1] 841 | editor = editors[editor_name] 842 | elif no == 5: 843 | cprint(f' You have selected {options[no-1]} .','yellow') 844 | cprint(" Enter your preferred editor name : ",'cyan',end='') 845 | editor_name = input() 846 | cprint(" Enter your editor run command : ",'cyan',end='') 847 | editor = input() 848 | elif no == 6: 849 | cprint(f' You have selected {options[no-1]} .','yellow') 850 | editor_name = options[no-1] 851 | editor = editors[editor_name] 852 | else : 853 | ko = True 854 | cprint(" You have selected wrong index. Please try again.",'red') 855 | # print(editor_name, editor) 856 | section = 'cp' 857 | obx= CM() 858 | data = obx.read(conf_path,section = section) 859 | data['editor'] = editor 860 | data['editor_name'] = editor_name 861 | obx.update(conf_path,data,section=section) 862 | cprint(' Editor updated successfully.','green') 863 | 864 | return 865 | else: 866 | cprint(" You have choosen wrong index.",'red') 867 | ok = True 868 | except Exception as e: 869 | cprint(e,'red') 870 | 871 | def competitve_programming(self,no=2): 872 | 873 | optinos = [ 874 | 'Competitive Companion.', 875 | 'Template Path.', 876 | 'Compiler', 877 | 'Cf Tool Mode', 878 | 'After parsing open with an editor' 879 | ] 880 | 881 | pt = '-'*22 + self.lt[no] +'-'*22 882 | cprint(pt,'magenta') 883 | print() 884 | cprint(" All the available settings are given below,",'yellow') 885 | 886 | print() 887 | # print(bt) 888 | for i,w in enumerate(optinos): 889 | cprint(f' {i+1}) {w}','blue') 890 | cprint(' 0) Cancel','red') 891 | print() 892 | ok = True 893 | 894 | while ok: 895 | ok = False 896 | cprint(" Enter the index number : ",'cyan',end='') 897 | no = int(input()) 898 | if no == 0: 899 | cprint(" Operation cancelled.",'red') 900 | return 901 | elif no == 1: 902 | cprint(f' You have selected {optinos[no-1]} .','yellow') 903 | self.competitive_companion() 904 | elif no == 2: 905 | cprint(f' You have selected {optinos[no-1]} .','yellow') 906 | self.temp_path() 907 | elif no == 3: 908 | cprint(f' You have selected {optinos[no-1]} .','yellow') 909 | self.compiler_option() 910 | elif no == 4: 911 | cprint(f' You have selected {optinos[no-1]} .','yellow') 912 | self.cf_tool_function() 913 | elif no == 5: 914 | cprint(f' You have selected {optinos[no-1]} .','yellow') 915 | self.after_parsing_open_with_and_editor() 916 | else : 917 | ok = True 918 | cprint(" You have selected wrong index. Please try again.",'red') 919 | 920 | 921 | def features(self,no): 922 | from system.features_installation import speed_up, install_speaking_system , install_command_system 923 | options = [ 924 | 'Speed Up', 925 | 'Speaking Capability', 926 | 'Voice Command' 927 | ] 928 | pt = '-'*22 + "Features Installaion" + '-'*22 929 | cprint(pt,'magenta') 930 | print() 931 | cprint(" All the available options are given below : ",'yellow') 932 | 933 | print() 934 | # print(bt) 935 | for i,w in enumerate(options): 936 | cprint(f' {i+1}) {w}','blue') 937 | cprint(' 0) Cancel','red') 938 | print() 939 | ok = True 940 | 941 | while ok: 942 | ok = False 943 | cprint(" Enter the index number : ",'cyan',end='') 944 | no = int(input()) 945 | if no == 0: 946 | cprint(" Operation cancelled.",'red') 947 | return 948 | elif no == 1: 949 | cprint(f' You have selected {options[no-1]} .','yellow') 950 | speed_up() 951 | elif no == 2: 952 | cprint(f' You have selected {options[no-1]} .','yellow') 953 | install_speaking_system() 954 | elif no == 3: 955 | cprint(f' You have selected {options[no-1]} .','yellow') 956 | install_command_system() 957 | else : 958 | ok = True 959 | cprint(" You have selected wrong index. Please try again.",'red') 960 | 961 | def train_answer(self): 962 | 963 | ok = True 964 | while ok : 965 | ok = False 966 | print() 967 | cprint(" Enter the question : ",'cyan',end='') 968 | question = input() 969 | cprint(" Enter the answer : ",'cyan',end='') 970 | answer = input() 971 | print() 972 | pt = '-'*18+"Question-Answer"+'-'*18 973 | cprint(pt,"magenta") 974 | print() 975 | cprint(" Q. "+question,'yellow') 976 | cprint(" Answer : "+answer,'green') 977 | print() 978 | cprint(len(pt)*'-','magenta') 979 | 980 | cprint(" Do you want to learn it ?(y/n) : ",'cyan',end='') 981 | confirm = input() 982 | 983 | if confirm.lower() in self.confirm_keys : 984 | try : 985 | dic = JM.json_read(train_path) 986 | dic[question] = answer 987 | JM.json_write(train_path,dic) 988 | cprint(" Learned successfully.",'green') 989 | except Exception as e: 990 | cprint(e) 991 | else : 992 | cprint(" Ok, sir cancelled.",'red') 993 | 994 | cprint(len(pt)*'-','magenta') 995 | cprint(" Do you want to learn more ?(y/n) : ",'cyan',end='') 996 | confirm = input() 997 | 998 | if confirm.lower() in self.confirm_keys : 999 | ok = True 1000 | else : 1001 | cprint(" Cancelled." , 'red') 1002 | 1003 | 1004 | 1005 | def training_mode(self,no) : 1006 | pt = 22*'-'+self.lt[no] + 22*'-' 1007 | cprint(pt,'magenta') 1008 | print() 1009 | cprint(" All the available settings are given below,",'yellow') 1010 | print() 1011 | options = [ 1012 | 'Train Answer', 1013 | ] 1014 | for i,w in enumerate(options): 1015 | cprint(f' {i+1}) {w}','blue') 1016 | cprint(' 0) Cancel','red') 1017 | print() 1018 | ok = True 1019 | 1020 | while ok: 1021 | ok = False 1022 | cprint(" Enter the index number : ",'cyan',end='') 1023 | no = int(input()) 1024 | if no == 0: 1025 | cprint(" Operation cancelled.",'red') 1026 | return 1027 | elif no == 1: 1028 | cprint(f' You have selected {options[no-1]} .','yellow') 1029 | self.train_answer() 1030 | else : 1031 | ok = True 1032 | cprint(" You have selected wrong index. Please try again.",'red') 1033 | 1034 | def export_settings(self): 1035 | try : 1036 | with open(conf_path,'r') as f : 1037 | value = f.read() 1038 | with open(self.export_file_name,'w') as f: 1039 | f.write(value) 1040 | cprint(" File exported successfully.",'green') 1041 | except Exception as e : 1042 | cprint(f' Got error : {e}','red') 1043 | pass 1044 | 1045 | def import_settings(self): 1046 | if not os.path.exists(self.export_file_name): 1047 | cprint(" Sorry sir, export file not exists. Can't import.",'red') 1048 | else : 1049 | cprint(' Export file exists. Do you want import(y/n) : ','cyan',end='') 1050 | confirm = input() 1051 | positive = ['y', 'yes', 'ok', 'okay'] 1052 | if confirm.lower() in positive : 1053 | from settings.settings import all_sections 1054 | # print(all_sections) 1055 | try : 1056 | obj = CM() 1057 | for section in all_sections : 1058 | data = obj.read(self.export_file_name,section = section) 1059 | # cprint(data,'yellow') 1060 | conf_data = obj.read(conf_path,section = section) 1061 | # cprint(conf_data,'cyan') 1062 | 1063 | for key in conf_data: 1064 | try : 1065 | x = data[key] 1066 | conf_data[key] = x 1067 | # cprint(key+' '+x , 'blue') 1068 | except: 1069 | pass 1070 | # cprint(conf_data,'magenta') 1071 | obj.update(conf_path,conf_data,section = section) 1072 | 1073 | cprint(" Configs are successfully imported.",'green') 1074 | cprint(" You need to restart to see the new changes.",'yellow') 1075 | 1076 | except Exception as e: 1077 | cprint(f" Sorry sir can't import. Error : {e}",'red') 1078 | # return 1079 | # cprint(" Okay sir updating configs.",'green') 1080 | # try : 1081 | # with open(self.export_file_name,'r') as f : 1082 | # value = f.read() 1083 | # with open(conf_path,'w') as f : 1084 | # f.write(value) 1085 | # except Exception as e: 1086 | # cprint(f" Sorry sir can't import. Error : {e}",'red') 1087 | else : 1088 | cprint(" Okay sir operation cancelled.",'red') 1089 | pass 1090 | 1091 | def export_import_settings(self,no) : 1092 | pt = 22*'-'+self.lt[no] + 22*'-' 1093 | cprint(pt,'magenta') 1094 | print() 1095 | cprint(" All the available settings are given below,",'yellow') 1096 | print() 1097 | options = [ 1098 | 'Export Settings', 1099 | 'Import Settings' 1100 | ] 1101 | for i,w in enumerate(options): 1102 | cprint(f' {i+1}) {w}','blue') 1103 | cprint(' 0) Cancel','red') 1104 | print() 1105 | ok = True 1106 | 1107 | while ok: 1108 | ok = False 1109 | cprint(" Enter the index number : ",'cyan',end='') 1110 | no = int(input()) 1111 | if no == 0: 1112 | cprint(" Operation cancelled.",'red') 1113 | return 1114 | elif no == 1: 1115 | cprint(f' You have selected {options[no-1]} .','yellow') 1116 | self.export_settings() 1117 | elif no == 2: 1118 | cprint(f' You have selected {options[no-1]} .','yellow') 1119 | self.import_settings() 1120 | else : 1121 | ok = True 1122 | cprint(" You have selected wrong index. Please try again.",'red') 1123 | 1124 | 1125 | 1126 | def config_list(self): 1127 | not_done = True 1128 | while not_done: 1129 | 1130 | pt = '-'*22 + 'Config'+'-'*22 1131 | cprint(pt,'magenta') 1132 | print() 1133 | cprint(" All the available settings are given below,",'yellow') 1134 | print() 1135 | for i,w in enumerate(self.lt): 1136 | cprint(f' {i+1}) {w}','blue') 1137 | cprint(' 0) Exit','red') 1138 | print() 1139 | ok = True 1140 | while ok: 1141 | ok = False 1142 | cprint(" Enter the index number : ",'cyan',end='') 1143 | no = int(input()) 1144 | if no == 0: 1145 | cprint(" Exiting.",'red') 1146 | cprint(" For some setting you might need to restart me.",'yellow') 1147 | not_done = False 1148 | elif no == 1: 1149 | cprint(f' You have selected {self.lt[no-1]} .','yellow') 1150 | self.bot(no-1) 1151 | elif no == 2: 1152 | cprint(f' You have selected {self.lt[no-1]} .','yellow') 1153 | self.Interaction(no-1) 1154 | elif no == 3: 1155 | cprint(f' You have selected {self.lt[no-1]} .','yellow') 1156 | self.competitve_programming(no-1) 1157 | elif no == 4 : 1158 | cprint(f' You have selected {self.lt[no-1]} .','yellow') 1159 | self.features(no-1) 1160 | elif no == 5 : 1161 | cprint(f' You have selected {self.lt[no-1]} .','yellow') 1162 | self.training_mode(no-1) 1163 | elif no == 6 : 1164 | cprint(f" You have selected {self.lt[no-1]} .",'yellow') 1165 | self.export_import_settings(no-1) 1166 | elif no == 75: 1167 | self.dev_mode() 1168 | else : 1169 | ok = True 1170 | cprint(" You have selected wrong index. Please try again.",'red') 1171 | 1172 | 1173 | 1174 | 1175 | def if_config_type(msg): 1176 | if msg in config_keys: 1177 | obj = Config() 1178 | obj.config_list() 1179 | return True 1180 | else: 1181 | return False 1182 | -------------------------------------------------------------------------------- /settings/default.conf: -------------------------------------------------------------------------------- 1 | [bot] 2 | name = Jarvis 3 | gender = Male 4 | boss = Saurav Paul 5 | voice_engine = robotic 6 | voice_reply = True 7 | 8 | [default] 9 | name = Saurav 10 | age = 22 11 | 12 | [interaction_setting] 13 | voice_reply = False 14 | text_reply = True 15 | voice_read_voice_reply = False 16 | text_read = True 17 | 18 | [cp] 19 | coder_name = ${boss} 20 | competitive_companion_port = 10043 21 | parse_problem_with_template = True 22 | cf_tool_mode = False 23 | editor = $NONE 24 | editor_name = NONE 25 | 26 | [template_path] 27 | cpp = $DEFAULT 28 | python = $DEFAULT 29 | 30 | [compiler] 31 | cpp = g++ -O2 -Wshift-overflow=2 -Wshadow '{filename}' -o '{executable}' && ./'{executable}' 32 | cpp_debug = g++ -std=c++17 -Wshadow -Wconversion -Wall -DPAUL -DLOCAL -Wshift-overflow=2 -Wshadow -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -g '{filename}' -o '{executable}' && ./'{executable}' 33 | python = python3 '{filename}' 34 | 35 | [developer] 36 | debug = False 37 | learn = True 38 | 39 | [start_time] 40 | first_start = True 41 | 42 | -------------------------------------------------------------------------------- /settings/logs.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from settings.settings import DEBUG 3 | 4 | logging.basicConfig( 5 | level=logging.ERROR, 6 | format="%(asctime)s [%(levelname)s] %(message)s", 7 | handlers=[ 8 | logging.FileHandler(".log",'w'), 9 | logging.StreamHandler() 10 | ] 11 | ) 12 | logger=logging.getLogger() 13 | 14 | if DEBUG: 15 | logger.setLevel(20) -------------------------------------------------------------------------------- /settings/settings.conf: -------------------------------------------------------------------------------- 1 | [bot] 2 | name = Jarvis 3 | gender = Male 4 | boss = Saurav-Paul 5 | voice_engine = robotic 6 | voice_reply = True 7 | 8 | [default] 9 | name = Saurav 10 | age = 22 11 | 12 | [interaction_setting] 13 | voice_reply = False 14 | text_reply = True 15 | voice_read_voice_reply = False 16 | text_read = True 17 | 18 | [cp] 19 | coder_name = ${boss} 20 | competitive_companion_port = 10043 21 | parse_problem_with_template = True 22 | cf_tool_mode = False 23 | editor = $NONE 24 | editor_name = NONE 25 | 26 | [template_path] 27 | cpp = $DEFAULT 28 | python = $DEFAULT 29 | 30 | [compiler] 31 | cpp = g++ -O2 -Wshift-overflow=2 -Wshadow '{filename}' -o '{executable}' && ./'{executable}' 32 | cpp_debug = g++ -std=c++17 -Wshadow -Wconversion -Wall -DPAUL -DLOCAL -Wshift-overflow=2 -Wshadow -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -g '{filename}' -o '{executable}' && ./'{executable}' 33 | python = python3 '{filename}' 34 | 35 | [developer] 36 | debug = False 37 | learn = True 38 | 39 | [start_time] 40 | first_start = True 41 | 42 | -------------------------------------------------------------------------------- /settings/settings.py: -------------------------------------------------------------------------------- 1 | # Written By Saurav Paul 2 | from tools.json_manager import JsonManager as JM 3 | from tools.ConfigParser import ConfigParser_manager as CM 4 | from system.path import getpath 5 | import os 6 | from termcolor import cprint 7 | 8 | all_sections = [ 9 | 'bot', 10 | 'default', 11 | 'interaction_setting', 12 | 'cp', 13 | 'template_path', 14 | 'compiler', 15 | 'developer', 16 | 'start_time' 17 | 18 | ] 19 | 20 | positive = ['yes','1','true'] 21 | 22 | interaction_setting = { 23 | 'voice_reply' : True, 24 | 'text_reply' : True , 25 | 'voice_read_voice_reply' : False , 26 | 'text_read' : True, 27 | } 28 | bot = { 29 | 'name' : 'Jarvis', # You can change bot name from here 30 | 'gender' : 'male', #Whatever you want ;p 31 | 'boss' : 'Saurav Paul', # you can put your name her ;p 32 | 'voice_engine' : 'robotic' , # you can change it to 'gTTS' for more natural voice (online) 33 | 34 | } 35 | 36 | DEBUG = True 37 | LEARN = True 38 | conf_path = os.path.join(getpath(__file__),'settings.conf') 39 | 40 | try : 41 | 42 | section = 'bot' 43 | obj = CM() 44 | bot = obj.read(conf_path,section = section) 45 | section = 'interaction_setting' 46 | x = obj.read(conf_path,section=section) 47 | for i in interaction_setting: 48 | if x[i].lower() in positive: 49 | interaction_setting[i] = True 50 | else : 51 | interaction_setting[i] = False 52 | section = 'developer' 53 | x = obj.read(conf_path,section=section) 54 | 55 | if x['debug'].lower() in positive: 56 | DEBUG = True 57 | else : 58 | DEBUG = False 59 | 60 | if x['learn'].lower() in positive: 61 | LEARN = True 62 | else : 63 | LEARN = False 64 | 65 | 66 | except Exception as e: 67 | cprint(e,'red') 68 | cprint("Settings error.",'red') 69 | 70 | START_SCREEN_NAME = bot['name'] # Enter a string to make start screen banner 71 | 72 | def update_bot(orginal_path): 73 | f = orginal_path + '/settings/bot.json' 74 | JM.json_write(f,bot) 75 | 76 | def read_bot(orginal_path): 77 | f = orginal_path + '/settings/bot.json' 78 | bot = JM.json_read(f) 79 | print(bot) 80 | # return bot 81 | 82 | def update_bot(x): 83 | global bot 84 | global START_SCREEN_NAME 85 | bot = x 86 | START_SCREEN_NAME = bot['name'] 87 | 88 | def update_dev(x): 89 | global DEBUG 90 | 91 | if x['debug'].lower() in positive: 92 | DEBUG = True 93 | else : 94 | DEBUG = False 95 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | import system.__about__ as version 3 | 4 | from os import path 5 | 6 | here = path.abspath(path.dirname(__file__)) 7 | 8 | # Get the long description from the README file 9 | with open(path.join(here, 'README.md'), encoding='utf-8') as f: 10 | long_description = f.read() 11 | 12 | setup( 13 | name=version.__package_name__, 14 | version=version.__version__, 15 | author=version.__author__, 16 | author_email=version.__email__, 17 | url=version.__url__, 18 | license=version.__license__, 19 | description=version.__description__, 20 | long_description=long_description, 21 | long_description_content_type='text/markdown', 22 | classifiers=[ # Optional 23 | # How mature is this project? Common values are 24 | # 3 - Alpha 25 | # 4 - Beta 26 | # 5 - Production/Stable 27 | # 'Development Status :: 4 - Beta', 28 | "Development Status :: 5 - Production/Stable", 29 | 'Environment :: Console', 30 | # Indicate who your project is intended for 31 | 'Intended Audience :: End Users/Desktop', 32 | 'Operating System :: POSIX :: Linux', 33 | 'Operating System :: MacOS :: MacOS X', 34 | # Pick your license as you wish 35 | 'License :: OSI Approved :: MIT License', 36 | ], 37 | keywords='ai virtual assitant', 38 | packages=find_packages(), 39 | include_package_data=True, 40 | package_data={ 41 | # If any package contains *.txt or *.rst files, include them: 42 | '': ['*.conf', '*.json', '*.txt', '.learnt', '.trained'], 43 | }, 44 | python_requires='>=3.5', 45 | install_requires=[ 46 | 'beautifulsoup4', 47 | 'fuzzywuzzy', 48 | 'google', 49 | 'lxml', 50 | 'online-judge-api-client', 51 | 'online-judge-tools', 52 | 'plyer', 53 | 'pyfiglet', 54 | 'requests', 55 | 'tcgen', 56 | 'termcolor', 57 | 'tqdm', 58 | 'wget', 59 | 'wikipedia-api', 60 | 'wolframalpha', 61 | 'selenium' 62 | ], 63 | entry_points={ 64 | 'console_scripts': [ 65 | 'ai = run.run:start', 66 | 'jarvis = run.run:start', 67 | 'Cp = run.cp_run:cp_start', 68 | 'CP = run.cp_run:cp_start', 69 | ], 70 | }, 71 | ) 72 | -------------------------------------------------------------------------------- /setup.py.bc4d43a15726dde0ae1be748c656face.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | import system.__about__ as version 3 | 4 | from os import path 5 | 6 | here = path.abspath(path.dirname(__file__)) 7 | 8 | # Get the long description from the README file 9 | with open(path.join(here, 'README.md'), encoding='utf-8') as f: 10 | long_description = f.read() 11 | 12 | setup( 13 | name=version.__package_name__, 14 | version=version.__version__, 15 | author=version.__author__, 16 | author_email=version.__email__, 17 | url=version.__url__, 18 | license=version.__license__, 19 | description=version.__description__, 20 | long_description=long_description, 21 | long_description_content_type='text/markdown', 22 | classifiers=[ # Optional 23 | # How mature is this project? Common values are 24 | # 3 - Alpha 25 | # 4 - Beta 26 | # 5 - Production/Stable 27 | 'Development Status :: 4 - Beta', 28 | 'Environment :: Console', 29 | # Indicate who your project is intended for 30 | 'Intended Audience :: End Users/Desktop', 31 | 'Operating System :: POSIX :: Linux', 32 | 'Operating System :: MacOS :: MacOS X', 33 | # Pick your license as you wish 34 | 'License :: OSI Approved :: MIT License', 35 | ], 36 | keywords='ai virtual assitant', 37 | packages=find_packages(), 38 | include_package_data=True, 39 | package_data={ 40 | # If any package contains *.txt or *.rst files, include them: 41 | '': ['*.conf', '*.json', '*.txt', '.learnt', '.trained'], 42 | }, 43 | python_requires='>=3.5', 44 | install_requires=[ 45 | 'beautifulsoup4', 46 | 'fuzzywuzzy', 47 | 'google', 48 | 'lxml', 49 | 'online-judge-api-client', 50 | 'online-judge-tools', 51 | 'plyer', 52 | 'pyfiglet', 53 | 'requests', 54 | 'tcgen', 55 | 'termcolor', 56 | 'tqdm', 57 | 'wget', 58 | 'wikipedia-api', 59 | 'wolframalpha', 60 | ], 61 | entry_points={ 62 | 'console_scripts': [ 63 | 'ai = run.run:start', 64 | 'jarvis = run.run:start', 65 | 'Cp = run.cp_run:cp_start', 66 | 'CP = run.cp_run:cp_start', 67 | ], 68 | }, 69 | ) 70 | -------------------------------------------------------------------------------- /system/__about__.py: -------------------------------------------------------------------------------- 1 | # Python Version: 3.x 2 | __package_name__ = 'ai-virtual-assistant' 3 | __author__ = 'Saurav Paul' 4 | __email__ = 'sauravpaul.sunny@gmail.com' 5 | __license__ = 'MIT License' 6 | __url__ = 'https://github.com/Saurav-Paul/AI-virtual-assistant-python' 7 | __version_info__ = (1, 0, 4, 'alpha', 1) 8 | __version__ = '.'.join(map(str, __version_info__[:3])) 9 | __description__ = 'CLI virtual assitant for competitive programming' 10 | 11 | if __name__ == "__main__": 12 | print(__version__) 13 | -------------------------------------------------------------------------------- /system/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/system/__init__.py -------------------------------------------------------------------------------- /system/features_installation.py: -------------------------------------------------------------------------------- 1 | try : 2 | from sys import platform 3 | from termcolor import cprint 4 | import os 5 | except: 6 | pass 7 | 8 | # pip3 install SpeechRecognition 9 | 10 | def install_command_system(): 11 | x = platform.lower() 12 | pt = '-'*17 + "Installing voice command system" + '-'*17 13 | cprint(pt,'magenta') 14 | print() 15 | s = """ Packages are need to install,\n\n\t1)SpeechRecognition\n\t2)Py_Audio\n\n If you face any problem, install them manually.\n""" 16 | cprint(s,'yellow') 17 | if 'linux' in x: 18 | cprint("System : Linux",'green') 19 | os.system('pip3 install SpeechRecognition') 20 | os.system('sudo apt-get install python3-pyaudio') 21 | elif 'darwin' in x: 22 | cprint("System : Mac Os",'green') 23 | os.system('pip3 install SpeechRecognition') 24 | os.system('brew install portaudio') 25 | os.system('python3 -m pip install pyaudio') 26 | os.system('python3 -m pip install numpy') 27 | 28 | elif 'win' in x : 29 | cprint("System : Windows",'green') 30 | os.system('pip install SpeechRecognition') 31 | os.system('python -m pip install pyaudio') 32 | os.system('python -m pip install numpy') 33 | else: 34 | cprint("Can't determine the system. Sorry sir.",'red') 35 | 36 | print() 37 | cprint('-'*len(pt),'magenta') 38 | 39 | def install_speaking_system(): 40 | x = platform.lower() 41 | pt = '-'*17 + "Installing speaking system" + '-'*17 42 | cprint(pt,'magenta') 43 | print() 44 | s = """ Packages are need to install,\n\n\t1)pyttsx3\n\n\t2)espeak/gespeaker\n\n If you face any problem, install them manually.\n""" 45 | cprint(s,'yellow') 46 | 47 | if 'linux' in x: 48 | cprint("System : Linux",'green') 49 | os.system('pip3 install pyttsx3') 50 | cprint('\nWhich linux distribution are you using ? ','cyan') 51 | cprint('\n 1)debian-based\n 2)Arch-based\n 3)Other') 52 | cprint('\nEnter the index number : ','cyan',end='') 53 | index = int(input()) 54 | if index == 2 : 55 | cprint(' Installing Gespeaker ...','green') 56 | os.system('yay -S gespeaker') 57 | elif index == 1: 58 | cprint(' Installing espeak ...','green') 59 | os.system('sudo apt-get install espeak') 60 | else : 61 | cprint(" If your voice reply don't work you need install espeak/gespeaker manually",'red') 62 | 63 | elif 'darwin' in x: 64 | cprint("System : Mac Os",'green') 65 | os.system('pip3 install pyttsx3') 66 | elif 'win' in x : 67 | cprint("System : Windows",'green') 68 | os.system('pip install pypiwin32') 69 | else: 70 | cprint("Can't determine the system. Sorry sir.",'red') 71 | 72 | print() 73 | cprint('-'*len(pt),'magenta') 74 | 75 | 76 | 77 | 78 | def speed_up(): 79 | 80 | pt = '-'*17 + "Speeding up system" + '-'*17 81 | cprint(pt,'magenta') 82 | print() 83 | s = """ Packages are need to install,\n\n\t1)python-Levenshtein-wheels\n\t2)python-Levenshtein\n\n If you face any problem, install them manually.\n""" 84 | cprint(s,'yellow') 85 | 86 | os.system("pip3 install python-Levenshtein-wheels") 87 | os.system("pip3 install python-Levenshtein") 88 | 89 | print() 90 | cprint('-'*len(pt),'magenta') 91 | 92 | 93 | 94 | if __name__ == "__main__": 95 | speed_up() 96 | -------------------------------------------------------------------------------- /system/get_time.py: -------------------------------------------------------------------------------- 1 | 2 | from datetime import datetime 3 | import time 4 | 5 | def get_time(): 6 | return datetime.now().strftime("%d/%m/%Y %H:%M:%S") 7 | def digital_time(): 8 | return time.strftime("%B %d, %Y %-I:%M %p") 9 | 10 | if __name__ == "__main__": 11 | print(get_time()) 12 | print(digital_time()) -------------------------------------------------------------------------------- /system/install.py: -------------------------------------------------------------------------------- 1 | import os , subprocess 2 | try : 3 | from system.screen_text import command_sep 4 | except: 5 | pass 6 | 7 | def encode_to_bin(msg): 8 | return msg.encode('ascii') 9 | 10 | def decode_to_normal(msg): 11 | return msg.decode('ascii') 12 | 13 | def command(msg,no = 1): 14 | if no == 1 : 15 | os.system(msg) 16 | else : 17 | result = subprocess.run(list(msg.split()), stdout=subprocess.PIPE) 18 | out = decode_to_normal(result.communicate) 19 | print('printed:',out,sep='\n') 20 | 21 | def install(msg,no = 1): 22 | command_sep() 23 | lt = list(msg.split()) 24 | ans = 'Successfully installed:' 25 | for word in lt: 26 | try : 27 | cmd = 'pip install ' 28 | command(cmd+word,no) 29 | ans += ' '+word 30 | except: 31 | pass 32 | 33 | if ans == 'Successfully installed:': 34 | ans = "Can't install anything, sorry sir" 35 | 36 | ans = 'Done, sir.' 37 | command_sep() 38 | return ans 39 | 40 | -------------------------------------------------------------------------------- /system/internet.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def check_internet(): 4 | try : 5 | requests.get('https://www.google.com/').status_code 6 | return True 7 | except: 8 | return False 9 | 10 | 11 | 12 | if __name__ == "__main__": 13 | print(check_internet()) -------------------------------------------------------------------------------- /system/notifications.py: -------------------------------------------------------------------------------- 1 | from plyer import notification 2 | 3 | def notify(title='',msg='',t='5'): 4 | """Just give {title} {msg} {t} it will give the notification 5 | written by Saurav Paul """ 6 | try : 7 | notification.notify( 8 | title = title, 9 | message = msg, 10 | timeout = t, 11 | ) 12 | except Exception as e: 13 | pass 14 | if __name__ == "__main__": 15 | notify('NotiFiCaTioN','Hi how are you',t=5) -------------------------------------------------------------------------------- /system/path.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def getpath(file): 4 | x = os.path.dirname(os.path.abspath(file)) 5 | return os.path.join(x,'') -------------------------------------------------------------------------------- /system/screen_text.py: -------------------------------------------------------------------------------- 1 | import pyfiglet 2 | from os import system , name 3 | from random import choice 4 | 5 | try : 6 | from termcolor import colored, cprint 7 | except Exception as e: 8 | print(e) 9 | 10 | 11 | color = ['blue','yellow','green'] 12 | 13 | def line_sep(t=1): 14 | for i in range(t): 15 | cprint('-'*50,'magenta') 16 | 17 | def asci_banner(msg): 18 | banner = pyfiglet.figlet_format(msg) 19 | line_sep(2) 20 | cprint(banner,choice(color),attrs=['bold']) 21 | line_sep(2) 22 | 23 | def thoughts_processing(msg): 24 | x = ('.'*10 + msg + '.'*10) 25 | cprint(x,'magenta') 26 | 27 | def command_sep(): 28 | x = ('-'*23+'X-X-X'+'-'*22) 29 | cprint(x,'magenta') 30 | 31 | 32 | def clear_screen(start = True): 33 | from settings.settings import START_SCREEN_NAME 34 | # for windows 35 | if name == 'nt': 36 | _ = system('cls') 37 | 38 | # for mac and linux(here, os.name is 'posix') 39 | else: 40 | _ = system('clear') 41 | if start: 42 | asci_banner(START_SCREEN_NAME) 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tools/AI/.learnt: -------------------------------------------------------------------------------- 1 | {"Who is sushant singh?": "An indian actor.", "tell me about sushant singh": "Sushant Singh Rajput (21 January 1986 \u2013 14 June 2020) was an Indian actor. Rajput started his career with television serials.", "tell me about kk": "Krishnakumar Kunnath (popularly known as KK, K.K.", "star wars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "tell me about bighero": "Big Hero 6 is a 2014 American 3D computer animated superhero film produced by Walt Disney Animation Studios and released by Walt Disney Pictures. Loosely based on the superhero team of the same name by Marvel Comics, the film is the 54th Disney animated feature film.", "tell me about starwars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "tell me about superman": "Superman is a fictional superhero. The character was created by writer Jerry Siegel and artist Joe Shuster, and first appeared in Action Comics #1, a comic book published on April 18, 1938.", "what is a umbrella": "An umbrella or parasol is a folding canopy supported by wooden or metal ribs that is usually mounted on a wooden, metal, or plastic pole. It is designed to protect a person against rain or sunlight.", "starwars": "Star Wars is an American epic space-opera media franchise created by George Lucas, which began with the eponymous 1977 film and quickly became a worldwide pop-culture phenomenon. The franchise has been expanded into various films and other media, including television series, video games, novels, comic books, theme park attractions, and themed areas, comprising an all-encompassing fictional universe.", "Who is me ?": "You are my boss. ", "botany": "Botany, also called plant science(s), plant biology or phytology, is the science of plant life and a branch of biology. A botanist, plant scientist or phytologist is a scientist who specialises in this field.", "tell me about sunlight": "Sunlight is a portion of the electromagnetic radiation given off by the Sun, in particular infrared, visible, and ultraviolet light. On Earth, sunlight is scattered and filtered through Earth's atmosphere, and is obvious as daylight when the Sun is above the horizon.", "I am bored": "Talk to your friend sir.", "who is spiderman": "Spider-Man is a fictional superhero created by writer-editor Stan Lee and writer-artist Steve Ditko. He first appeared in the anthology comic book Amazing Fantasy #15 (August 1962) in the Silver Age of Comic Books."} -------------------------------------------------------------------------------- /tools/AI/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/tools/AI/__init__.py -------------------------------------------------------------------------------- /tools/AI/ai.py: -------------------------------------------------------------------------------- 1 | try : 2 | from tools.assistant import ask_question 3 | from tools.AI.data import data , youtube , wiki , google , youtube_play , goto_keys 4 | from tools.AI.data import install_keys , calc_keys , should_not_learn , version_keys 5 | from tools.wiki_search import wiki_search 6 | from settings.logs import * 7 | from tools.browser.search import * 8 | from tools.browser.goto import find_goto_address 9 | from system.install import install , command 10 | from system.screen_text import command_sep 11 | from tools.string_processing import is_matched 12 | from tools.json_manager import JsonManager 13 | from tools.calculation import google_calculation 14 | from tools.run_program import if_run_type 15 | from system.notifications import notify 16 | from settings.settings import bot , DEBUG , LEARN 17 | from tools.shell import if_shell_type 18 | from tools.OJ.cp import if_cp_type 19 | from termcolor import cprint 20 | from tools.downloader import wget_downloader 21 | from settings.config import if_config_type 22 | from tools.credits import if_credit_type 23 | from system.path import getpath 24 | from settings.config import train_path 25 | import os 26 | import time 27 | except Exception as e: 28 | print(e) 29 | 30 | def check(msg,mp,need = 90): 31 | logger.debug('check->' + msg) 32 | for word in mp : 33 | if is_matched(word,msg,need): 34 | return True 35 | return False 36 | 37 | 38 | def version_type(msg) : 39 | try : 40 | if msg in version_keys : 41 | from system.__about__ import __version__ 42 | x = "Current version is : "+ __version__ 43 | return (True,x) 44 | return (False,'') 45 | except: 46 | return (False,'') 47 | 48 | def rep(msg,mp): 49 | msg = msg.lower() 50 | # for key in mp : 51 | # for word in key: 52 | # for w in msg: 53 | # if w == word: 54 | # w = word 55 | # return msg.strip().capitalize() 56 | for word in mp : 57 | if word in msg: 58 | return msg.replace(word,'',1).strip() 59 | return msg.strip() 60 | 61 | def ai(msg,orginal_path) : 62 | """ Little ai for reacting to the msg. 63 | Written by Saurav-Paul""" 64 | logger.debug('Processing with ai') 65 | msg = msg.replace(' ',' ') 66 | msg = msg.replace(bot['name'],'') 67 | msg = msg.replace(bot['name'].lower(),'') 68 | msg = msg.replace(bot['name'].capitalize(),'') 69 | reply = "I don't know what to do, sir ." 70 | # print('you said ' , msg, bot['name']) 71 | is_type = version_type(msg) 72 | if is_type[0]: 73 | return is_type[1] 74 | if if_cp_type(msg): 75 | return 'Good luck sir.' 76 | if if_config_type(msg): 77 | return 'Good luck sir.' 78 | if if_shell_type(msg): 79 | return 'Good luck sir.' 80 | if if_run_type(msg): 81 | return 'Good luck sir.' 82 | if if_credit_type(msg): 83 | return 'Good luck sir.' 84 | else : 85 | try : 86 | msg = msg.strip().lower() 87 | for line in data : 88 | if is_matched(msg,line,95): 89 | reply = data[line] 90 | return reply 91 | # logger.info('Not found in common data') 92 | # from history 93 | if(check(msg,['change dir','change directory','chdir','-cd'],100)): 94 | # print(os.getcwd()) 95 | cprint('Enter the path: ','cyan',end='') 96 | path = input() 97 | os.chdir(path) 98 | return 'Directory changed.' 99 | if check(msg,youtube_play): 100 | msg = rep(msg,youtube_play) 101 | logger.info(msg) 102 | find_goto_address(msg) 103 | reply = 'Enjoy sir. :D' 104 | elif check(msg,goto_keys): 105 | msg = rep(msg,goto_keys) 106 | find_goto_address(msg) 107 | reply = 'check browser' 108 | notify('Check Browser',':D',t=5) 109 | elif check(msg,youtube): 110 | msg = rep(msg,youtube) 111 | search_youtube(msg) 112 | reply = 'check browser.' 113 | notify('Check Browser',':D',t=5) 114 | elif check(msg,wiki): 115 | msg = rep(msg,wiki) 116 | # search_wiki(msg) 117 | msg = 'en.wikipedia.org '+msg 118 | find_goto_address(msg) 119 | reply = 'check browser.' 120 | notify('Check Browser',':D',t=5) 121 | elif msg == 'download': 122 | cprint('Enter the url : ','cyan',end='') 123 | url = input() 124 | wget_downloader(url) 125 | reply = 'Done.' 126 | elif check(msg,google): 127 | msg = rep(msg,google) 128 | # print('here = ',msg) 129 | search_google(msg) 130 | reply = 'check browser.' 131 | notify('Check Browser',':D',t=5) 132 | elif check(msg,install_keys): 133 | msg = rep(msg,install_keys) 134 | reply = install(msg) 135 | elif check(msg,calc_keys): 136 | msg = rep(msg,calc_keys) 137 | reply = google_calculation(msg) 138 | if reply == "sorry": 139 | search_google(msg) 140 | reply = "check browser" 141 | notify('Check Browser',':D',t=5) 142 | else : 143 | if 0 and 'cmd:' in msg or '-s' in msg: 144 | msg = rep(msg,{'cmd:'}) 145 | msg = rep(msg,{'-s'}) 146 | command_sep() 147 | command(msg.lower()) 148 | command_sep() 149 | reply = 'done sir' 150 | else : 151 | try : 152 | f = getpath(__file__)+'.learnt' 153 | history = JsonManager.json_read(f) 154 | for line in history: 155 | if is_matched(msg,line,95): 156 | logging.info('Learnt this before') 157 | return history[line] 158 | 159 | except : 160 | logging.error("Can't read history file") 161 | 162 | try : 163 | ft = train_path 164 | history = JsonManager.json_read(ft) 165 | for line in history: 166 | if is_matched(msg,line,95): 167 | logging.info('You have trained this before.') 168 | return history[line] 169 | 170 | except : 171 | logger.info("Can't read trained data") 172 | 173 | t = time.time() 174 | reply = ask_question(msg) 175 | t = time.time()-t 176 | logger.info(str(t)+' sec') 177 | # cprint(t,'red') 178 | ok = True 179 | for word in should_not_learn: 180 | if word in msg.lower() or word in reply.lower(): 181 | ok = False 182 | break 183 | 184 | if ok: 185 | logger.info('reply -> ' + reply) 186 | if LEARN == False: 187 | cprint("(Automatically LEARN MODE is disable)Enter y to learn : ",'red',attrs=['bold'],end='') 188 | learn = input('') 189 | else : 190 | learn = 'y' 191 | if learn.lower() == 'y': 192 | try : 193 | history.update({msg:reply}) 194 | JsonManager.json_write(f,history) 195 | logger.info('Learnt') 196 | except Exception as e: 197 | logger.info("Exception while writing learnt : "+e) 198 | return reply 199 | except Exception as e: 200 | logger.info('Getting some error in ai') 201 | logger.info(e) 202 | return reply 203 | 204 | -------------------------------------------------------------------------------- /tools/AI/conversations.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "Greetings":{ 4 | "Questions" : ["hello" ,"Hi","What's up" , "whats up","$NAME"] , 5 | "Answer" : ["hi" , "Hello"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tools/AI/data.py: -------------------------------------------------------------------------------- 1 | from settings.settings import bot 2 | from datetime import datetime 3 | import time 4 | 5 | def get_time() : 6 | """This function will return current time 7 | written by Saurav Paul""" 8 | now = datetime.now() 9 | current_time = now.strftime("%H:%M:%S") 10 | tm = current_time.split(sep=':') 11 | apm = 'pm' 12 | if int(tm[0]) < 12 : 13 | apm = 'am' 14 | if int(tm[0]) == 0 : 15 | tm[0] = '12' 16 | 17 | elif int(tm[0]) > 12 : 18 | tm[0] = str( int(tm[0]) - 12 ) 19 | current_time = 'Sir, now is {hour} : {min} '.format(hour=tm[0],min=tm[1]) + apm +'.' 20 | 21 | return current_time 22 | 23 | def digital_time(): 24 | return 'Sir now is '+time.strftime("%-I:%M %p") 25 | 26 | data = { 27 | 'who are you' : 'I am '+ bot['name'] +'.', 28 | 'how are you' : 'I am fine, thank you sir.', 29 | 'good morning' : 'Good morning to you sir.' , 30 | 'good night' : 'Good night to you sir.' , 31 | 'what is the time' : digital_time(), 32 | 'tell me the time' : digital_time() , 33 | 'what is your name' : ('my name is ' + bot['name'] + '.'), 34 | 'who am i' : 'You are '+bot['boss'] + '.', 35 | 'tell me my name' : 'Your name is '+bot['boss']+'.', 36 | "what's up" : 'I am fine, thank you sir.', 37 | "who is your boss" : "My boss is "+bot['boss']+'.', 38 | "hello" :"hey", 39 | "ok" :"okay", 40 | "okay" :"ok", 41 | "thank you" : "welcome", 42 | "hey" : "hello", 43 | "what about you" : "I am fine sir.", 44 | "how about you" : "I am fine sir.", 45 | 46 | } 47 | 48 | 49 | wiki = [ 'search wikipedia','find wikipedia','wikipedia find' ,'wikipedia it','wikipedia', 'search wiki','wiki it','find wiki','wiki find','wiki' ] 50 | youtube = ['search youtube','youtube search', 'youtube it','find youtube' ,'youtube find' , 'youtube'] 51 | google = ['search google', 'google search','find google','google find','google it' , 'google','search it' ,'search','find it', 'find','how to'] 52 | youtube_play = ['play youtube', 'youtube play'] 53 | goto_keys = ['goto','go to'] 54 | install_keys = ['pip install','install pip','install'] 55 | calc_keys = ['calculator' , 'calculate' , 'calculations' , 'calculations', 'calc', 'solve it' , 'solve'] 56 | 57 | should_not_learn = ['date','today','check browser','no data available'] 58 | version_keys = ['-v','-version','--version'] -------------------------------------------------------------------------------- /tools/ConfigParser.py: -------------------------------------------------------------------------------- 1 | import configparser 2 | 3 | class ConfigParser_manager: 4 | 5 | def read(self,file_name,section=''): 6 | try : 7 | config = configparser.ConfigParser() 8 | config.read(file_name) 9 | if section != '': 10 | return dict(config[section]) 11 | 12 | return config 13 | except : 14 | return '' 15 | 16 | def update(self,file_name,value,section='user'): 17 | config = configparser.ConfigParser() 18 | config = self.read(file_name) 19 | 20 | config[section] = value 21 | 22 | with open(file_name , 'w') as f: 23 | config.write(f) 24 | 25 | 26 | if __name__ == "__main__": 27 | obj = ConfigParser_manager() 28 | # obj.update('Test.conf') 29 | 30 | section = 'demo' 31 | dic = obj.read('Test.conf',section=section) 32 | print(dic) 33 | dic[section] = 'Saurav' 34 | obj.update('Test.conf',dic,section=section) 35 | # print(getpath(__file__)) 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tools/OJ/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/tools/OJ/__init__.py -------------------------------------------------------------------------------- /tools/OJ/client.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | HOST = '127.0.0.1' # The server's hostname or IP address 4 | PORT = 9999 # The port used by the server 5 | 6 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 7 | s.connect((HOST, PORT)) 8 | s.sendall(b'Hello, world') 9 | data = s.recv(1024) 10 | 11 | print('Received', repr(data)) 12 | 13 | -------------------------------------------------------------------------------- /tools/OJ/socket_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import socket 4 | import json 5 | from termcolor import cprint 6 | import threading 7 | import os 8 | 9 | 10 | # HOST = '127.0.0.1' # Standard loopback interface address (localhost) 11 | # PORT = 9999 # Port to listen on (non-privileged ports are > 1023) 12 | 13 | # with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 14 | # s.bind((HOST, PORT)) 15 | # s.listen() 16 | # conn, addr = s.accept() 17 | # with conn: 18 | # print('Connected by', addr) 19 | # while True: 20 | # data = conn.recv(1024) 21 | # result = (data.decode('utf-8')) 22 | # print('result : ',result) 23 | 24 | # if not data: 25 | # print('breaked') 26 | # break 27 | # conn.sendall(data) 28 | # # print(data.decode('utf-8')) 29 | 30 | 31 | 32 | class cp_extension: 33 | 34 | HOST = '127.0.0.1' 35 | PORT = 9999 36 | 37 | def rectify(self,s): 38 | try: 39 | i = s.find('{') 40 | s = s[i:] 41 | return s 42 | except Exception as e: 43 | return '' 44 | 45 | def fetch_problem(self,url = ''): 46 | try : 47 | # cprint(' '*17+'...Parsing Problem...'+' '*17,'blue') 48 | # if url == '': 49 | # cprint('Enter the url : ','cyan',end='') 50 | # url = input() 51 | # cprint('-'*55,'magenta') 52 | # # os.system(cmd) 53 | # cmd = 'oj-api get-problem ' + url 54 | # cmd = list(cmd.split()) 55 | 56 | # cp = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 57 | # problem = json.loads(cp.stdout) 58 | # # with open('problem.json','w') as f: 59 | # # f.write(cp.stdout) 60 | 61 | 62 | 63 | if problem['status'] == 'ok': 64 | # print('ok') 65 | try : 66 | alphabet = problem['result']['context']['alphabet'] 67 | except : 68 | alphabet = '' 69 | problem_name = problem['result']['name'] 70 | problem_name = alphabet + '-'+problem_name 71 | # print(problem_name) 72 | if not os.path.isdir(problem_name): 73 | os.mkdir(problem_name) 74 | try: 75 | result = f"\tFetched '{problem_name}' Successfully" 76 | testcases = problem['result']['tests'] 77 | # print(testcases) 78 | # if not os.path.isdir(problem_name): 79 | # os.mkdir("'"+problem_name+"'"+'/test') 80 | base = os.getcwd() 81 | path = os.path.join(base,problem_name,"") 82 | 83 | info = '{"name" : "$NAME" , "url" : "$URL" }' 84 | 85 | info = info.replace('$NAME',problem_name) 86 | info = info.replace('$URL',url) 87 | 88 | with open(path+'.info','w') as f: 89 | f.write(info) 90 | 91 | # print(path) 92 | if not os.path.isdir(path+"test"): 93 | os.mkdir(path+"test") 94 | path = os.path.join(path,'test') 95 | no = 1 96 | for case in testcases: 97 | # print(case) 98 | fileName_in = 'Sample-'+str(no).zfill(2)+'.in' 99 | fileName_out = 'Sample-'+str(no).zfill(2)+'.out' 100 | # print(fileName_in) 101 | no += 1 102 | with open(os.path.join(path,fileName_in),'w') as fin: 103 | fin.write(case['input']) 104 | with open(os.path.join(path,fileName_out) ,'w') as fout: 105 | fout.write(case['output']) 106 | cprint(result,'green') 107 | 108 | except Exception as e: 109 | print(e) 110 | 111 | else : 112 | result = "Wrong url." 113 | cprint(result,'result') 114 | 115 | cprint('-'*55,'magenta') 116 | 117 | except Exception as e: 118 | print('-'*55) 119 | # print(e) 120 | cprint("Sorry Can't Fetch.",'red') 121 | 122 | def create(self,problem): 123 | # print("here") 124 | try : 125 | problem = self.rectify(problem) 126 | dic = json.loads(problem) 127 | # cprint(dic,'yellow') 128 | 129 | problem_name = dic['name'] 130 | contest_name = dic['group'] 131 | url = dic['url'] 132 | # cprint(f'{problem_name} : {contest_name} : {url} ','cyan') 133 | base = os.getcwd() 134 | base_name = os.path.basename(base) 135 | # cprint(f'{base_name}','cyan') 136 | if base_name != contest_name: 137 | if not os.path.isdir(contest_name): 138 | os.mkdir(contest_name) 139 | # print("directory created") 140 | os.chdir(os.path.join(base,contest_name)) 141 | 142 | # print(os.getcwd()) 143 | if not os.path.isdir(problem_name): 144 | os.mkdir(problem_name) 145 | # print("problem created") 146 | 147 | info = '{"name" : "$NAME" , "url" : "$URL" }' 148 | 149 | info = info.replace('$NAME',problem_name) 150 | info = info.replace('$URL',url) 151 | 152 | path = os.path.join(os.getcwd(),problem_name,"") 153 | # print(path) 154 | with open(path+'.info','w') as f: 155 | f.write(info) 156 | 157 | testcases = dic['tests'] 158 | # print(testcases) 159 | # return 160 | no = 1 161 | if not os.path.isdir(path+"testcases"): 162 | os.mkdir(path+"testcases") 163 | path = os.path.join(path,'testcases') 164 | 165 | for case in testcases: 166 | # print(case) 167 | fileName_in = 'Sample-'+str(no).zfill(2)+'.in' 168 | fileName_out = 'Sample-'+str(no).zfill(2)+'.out' 169 | # print(fileName_in) 170 | no += 1 171 | with open(os.path.join(path,fileName_in),'w') as fin: 172 | fin.write(case['input']) 173 | with open(os.path.join(path,fileName_out) ,'w') as fout: 174 | fout.write(case['output']) 175 | # cprint(result,'green') 176 | # print(info) 177 | cprint(f'{problem_name} fetched successfully.','green') 178 | os.chdir(base) 179 | 180 | except Exception as e: 181 | cprint("Can't fetch.",'red') 182 | 183 | 184 | def listen(self): 185 | 186 | x = '' 187 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: 188 | s.bind((self.HOST,self.PORT)) 189 | cprint("Listening....",'yellow') 190 | timeout = 20 191 | cnt = 0 192 | ok = True 193 | while ok: 194 | try : 195 | s.listen() 196 | s.settimeout(timeout) 197 | timeout = 2 198 | conn , addr = s.accept() 199 | with conn: 200 | # cprint("Connected...",'green') 201 | while True: 202 | data = conn.recv(1024) 203 | result = (data.decode('utf-8')) 204 | # result = self.rectify(result) 205 | 206 | # cprint(result,'cyan') 207 | 208 | if not data : 209 | cnt += 1 210 | break 211 | else: 212 | t = threading.Thread(target=self.create,args=(result,)) 213 | t.start() 214 | x = result 215 | except : 216 | ok = False 217 | cprint(f'Total {cnt} problems fetched.','blue') 218 | x = self.rectify(x) 219 | # print(x) 220 | # p = threading.Thread(target=self.create,args=(x,)) 221 | # p.start() 222 | # p.join() 223 | 224 | 225 | if __name__ == "__main__": 226 | obj = cp_extension() 227 | obj.listen() 228 | 229 | # import socket 230 | # c = socket.socket() 231 | 232 | # c.bind((HOST,PORT)) 233 | # print(c.recv(1024).decode()) 234 | 235 | 236 | 237 | # An example script to connect to Google using socket 238 | # programming in Python 239 | # import socket # for socket 240 | # import sys 241 | 242 | # try: 243 | # s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 244 | # print ("Socket successfully created") 245 | # except socket.error as err: 246 | # print ("socket creation failed with error %s" %(err) ) 247 | 248 | # # default port for socket 249 | # port = 9998 250 | 251 | # try: 252 | # host_ip = socket.gethostbyname('www.google.com') 253 | # except socket.gaierror: 254 | 255 | # # this means could not resolve the host 256 | # print ("there was an error resolving the host") 257 | # sys.exit() 258 | 259 | # # connecting to the server 260 | # s.bind((HOST, PORT)) 261 | 262 | # print ("the socket has successfully connected to google.") 263 | 264 | 265 | # import socket 266 | 267 | # s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 268 | # s.connect(('',9000)) 269 | # reuslt = '' 270 | 271 | # while True: 272 | # data = s.recv(8) 273 | # if len(msg) <= 0 : 274 | # break 275 | # reuslt += data.decode('utf-8') 276 | 277 | # print(reuslt) -------------------------------------------------------------------------------- /tools/OJ/test.cpp: -------------------------------------------------------------------------------- 1 | /*Saurav Paul*/ 2 | #include 3 | using namespace std; 4 | 5 | void solve() { 6 | 7 | string s; 8 | cin >> s; 9 | 10 | int a , b, c ; 11 | a = b = c = -1 ; 12 | int mn = INT_MAX ; 13 | bool ok = false ; 14 | for(int i = 0 ; i < s.size() ; i++){ 15 | if(s[i] == '1') a = i ; 16 | else if(s[i] == '2') b = i ; 17 | else if(s[i] == '3') c = i ; 18 | else assert(false) ; 19 | 20 | if(a != -1 && b != -1 && c != -1){ 21 | mn = min( mn , max({a,b,c}) - min({a,b,c})+1) ; 22 | ok = true ; 23 | } 24 | } 25 | if(!ok) mn = 0 ; 26 | cout << mn << endl ; 27 | } 28 | 29 | int main(){ 30 | 31 | ios_base::sync_with_stdio(false); 32 | cin.tie(0); 33 | 34 | int testcase; 35 | cin >> testcase; 36 | for (int t = 1; t <= testcase; t++){ 37 | solve(); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tools/OJ/testing.py: -------------------------------------------------------------------------------- 1 | from termcolor import cprint 2 | import subprocess 3 | import json 4 | import os 5 | import time 6 | 7 | class Cp_Problem: 8 | 9 | def fetch_problem(self,url = ''): 10 | try : 11 | cprint(' '*17+'...Parsing Problem...'+' '*17,'blue') 12 | if url == '': 13 | cprint('Enter the url : ','cyan',end='') 14 | url = input() 15 | cprint('-'*55,'magenta') 16 | # os.system(cmd) 17 | cmd = 'oj-api get-problem ' + url 18 | cmd = list(cmd.split()) 19 | 20 | cp = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 21 | problem = json.loads(cp.stdout) 22 | # with open('problem.json','w') as f: 23 | # f.write(cp.stdout) 24 | 25 | result = "Fetched problem Successfully" 26 | 27 | if problem['status'] == 'ok': 28 | # print('ok') 29 | alphabet = problem['result']['context']['alphabet'] 30 | problem_name = problem['result']['name'] 31 | problem_name = alphabet + '-'+problem_name 32 | # print(problem_name) 33 | if not os.path.isdir(problem_name): 34 | os.mkdir(problem_name) 35 | try: 36 | 37 | testcases = problem['result']['tests'] 38 | # print(testcases) 39 | # if not os.path.isdir(problem_name): 40 | # os.mkdir("'"+problem_name+"'"+'/test') 41 | base = os.getcwd() 42 | path = os.path.join(base,problem_name,"") 43 | 44 | info = '{"name" : "$NAME" , "url" : "$URL" }' 45 | 46 | info = info.replace('$NAME',problem_name) 47 | info = info.replace('$URL',url) 48 | 49 | with open(path+'.info','w') as f: 50 | f.write(info) 51 | 52 | # print(path) 53 | if not os.path.isdir(path+"test"): 54 | os.mkdir(path+"test") 55 | path = os.path.join(path,'test') 56 | no = 1 57 | for case in testcases: 58 | # print(case) 59 | fileName_in = 'Sample-'+str(no).zfill(2)+'.in' 60 | fileName_out = 'Sample-'+str(no).zfill(2)+'.out' 61 | # print(fileName_in) 62 | no += 1 63 | with open(os.path.join(path,fileName_in),'w') as fin: 64 | fin.write(case['input']) 65 | with open(os.path.join(path,fileName_out) ,'w') as fout: 66 | fout.write(case['output']) 67 | cprint(result,'green') 68 | 69 | except Exception as e: 70 | print(e) 71 | 72 | else : 73 | result = "Wrong url." 74 | cprint(result,'result') 75 | 76 | cprint('-'*55,'magenta') 77 | 78 | except Exception as e: 79 | print('-'*55) 80 | # print(e) 81 | cprint("Sorry Can't Fetch.",'red') 82 | 83 | 84 | 85 | class Cp_contest(): 86 | 87 | 88 | 89 | def fetch_problem(self,url = ''): 90 | try : 91 | cmd = 'oj-api get-problem ' + url 92 | cmd = list(cmd.split()) 93 | 94 | cp = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 95 | problem = json.loads(cp.stdout) 96 | # with open('problem.json','w') as f: 97 | # f.write(cp.stdout) 98 | 99 | 100 | 101 | if problem['status'] == 'ok': 102 | # print('ok') 103 | try : 104 | alphabet = problem['result']['context']['alphabet'] 105 | except: 106 | alphabet = '' 107 | problem_name = problem['result']['name'] 108 | problem_name = alphabet + '-'+problem_name 109 | # print(problem_name) 110 | if not os.path.isdir(problem_name): 111 | os.mkdir(problem_name) 112 | try: 113 | result = f" * Fetched '{problem_name}'' Successfully" 114 | testcases = problem['result']['tests'] 115 | # print(testcases) 116 | # if not os.path.isdir(problem_name): 117 | # os.mkdir("'"+problem_name+"'"+'/test') 118 | base = os.getcwd() 119 | path = os.path.join(base,problem_name,"") 120 | 121 | info = '{"name" : "$NAME" , "url" : "$URL" }' 122 | 123 | info = info.replace('$NAME',problem_name) 124 | info = info.replace('$URL',url) 125 | 126 | with open(path+'.info','w') as f: 127 | f.write(info) 128 | 129 | # print(path) 130 | if not os.path.isdir(path+"test"): 131 | os.mkdir(path+"test") 132 | path = os.path.join(path,'test') 133 | no = 1 134 | for case in testcases: 135 | # print(case) 136 | fileName_in = 'Sample-'+str(no).zfill(2)+'.in' 137 | fileName_out = 'Sample-'+str(no).zfill(2)+'.out' 138 | # print(fileName_in) 139 | no += 1 140 | with open(os.path.join(path,fileName_in),'w') as fin: 141 | fin.write(case['input']) 142 | with open(os.path.join(path,fileName_out) ,'w') as fout: 143 | fout.write(case['output']) 144 | cprint(result,'green') 145 | 146 | except Exception as e: 147 | print(e) 148 | 149 | else : 150 | result = "Wrong url." 151 | cprint(result,'result') 152 | 153 | 154 | 155 | except Exception as e: 156 | print('-'*55) 157 | # print(e) 158 | cprint("Sorry Can't Fetch.",'red') 159 | 160 | def parse_contest(self,url=''): 161 | try : 162 | 163 | url = 'https://codeforces.com/contest/1343' 164 | # url = 'https://atcoder.jp/contests/abc167/tasks/abc167_a' 165 | cprint(' '*17+'...Parsing Contest...'+' '*17,'blue') 166 | if url == '': 167 | cprint('Enter the url : ','cyan',end='') 168 | url = input() 169 | cprint('-'*55,'magenta') 170 | # os.system(cmd) 171 | t = time.time() 172 | cmd = 'oj-api get-contest ' + url 173 | cmd = list(cmd.split()) 174 | 175 | cp = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 176 | contest = json.loads(cp.stdout) 177 | # with open('problem.json','w') as f: 178 | # f.write(cp.stdout) 179 | 180 | result = "\tFetched Contest info." 181 | if contest['status'] == 'ok': 182 | cprint(result,'green') 183 | else : 184 | cprint("Sorry contest can't be fetched. Sorry sir. :( ",'red') 185 | return 186 | # print(contest) 187 | path = os.getcwd() 188 | # print(path) 189 | contest_name = contest['result']['name'] 190 | cprint(f' # Contest name : {contest_name}','green') 191 | 192 | if not os.path.isdir(contest_name): 193 | os.mkdir(contest_name) 194 | # cprint('Contest folder created.','green') 195 | 196 | 197 | print() 198 | os.chdir(os.path.join(path,contest_name)) 199 | # print(os.getcwd()) 200 | problem = contest['result']['problems'] 201 | with open('t.json','w') as f: 202 | f.write(str(contest)) 203 | 204 | for key in problem: 205 | url = key['url'] 206 | # print(url) 207 | # Cp_Problem.fetch_problem(url) 208 | self.fetch_problem(url=url) 209 | 210 | os.chdir(path) 211 | # print(os.getcwd()) 212 | print() 213 | cprint(" # Done. :D",'green') 214 | cprint(f" # Time taken {time.time()-t:.4f} sec.",'blue') 215 | cprint('-'*55,'magenta') 216 | 217 | except Exception as e: 218 | cprint(e,'red') 219 | 220 | 221 | 222 | 223 | 224 | if __name__ == "__main__": 225 | obj = Cp_contest() 226 | obj.parse_contest() -------------------------------------------------------------------------------- /tools/TODO_management.py: -------------------------------------------------------------------------------- 1 | import os 2 | from system.path import getpath 3 | 4 | todo_file_path = os.path.join(getpath(__file__),'todolist.todo') 5 | 6 | class TODO : 7 | 8 | def list(self): 9 | pass 10 | 11 | 12 | 13 | if __name__ == "__main__": 14 | print(todo_file_path) 15 | 16 | -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/tools/__init__.py -------------------------------------------------------------------------------- /tools/assistant.py: -------------------------------------------------------------------------------- 1 | import wolframalpha 2 | from settings.logs import * 3 | from tools.wiki_search import wiki_search , wiki_summary 4 | from tools.browser.search import search_google 5 | from settings.settings import bot 6 | from termcolor import cprint 7 | from time import time , sleep 8 | from threading import Thread 9 | import multiprocessing 10 | from tqdm import tqdm 11 | 12 | 13 | 14 | not_found = ['no data available'] 15 | 16 | wiki_result = 'no data available' 17 | 18 | qus = '' 19 | 20 | def wiki(msg): 21 | try : 22 | global wiki_result 23 | t = time() 24 | # print("Calling") 25 | wiki_result = wiki_search(msg,1) 26 | # cprint(time()-t,'blue') 27 | # print(wiki_result) 28 | logger.info('wiki time : '+time()-t +' sec') 29 | except Exception as e: 30 | # cprint(e,'red') 31 | pass 32 | 33 | ans = 'x' 34 | def wiki_multi(): 35 | try : 36 | global wiki_result 37 | global ans 38 | t = time() 39 | # print("Calling") 40 | wiki_result = wiki_search(qus,1) 41 | # cprint(time()-t,'blue') 42 | cprint(wiki_result,'yellow') 43 | share['ans'] = wiki_result 44 | logger.info('wiki time : '+time()-t +' sec') 45 | 46 | except Exception as e: 47 | # cprint(e,'red') 48 | pass 49 | 50 | 51 | 52 | 53 | 54 | 55 | def worker(procnum, return_dict): 56 | '''worker function''' 57 | st_time = time() 58 | return_dict[procnum] = wiki_summary(procnum,2) 59 | logger.info(time()-st_time) 60 | 61 | 62 | def ask_question(question): 63 | global wiki_result 64 | answer = 'no data available' 65 | cprint('\t\t(Thinking)','yellow') 66 | manager = multiprocessing.Manager() 67 | return_dict = manager.dict() 68 | p = multiprocessing.Process(target=worker, args=(question,return_dict)) 69 | p.start() 70 | sleep_time = 1/10 71 | for i in tqdm(range(100),desc='Thinking',unit='it'): 72 | sleep(sleep_time) 73 | if not p.is_alive(): 74 | sleep_time = 0 75 | if p.is_alive(): 76 | p.terminate() 77 | p.join() 78 | # jobs = [] 79 | # for i in range(1): 80 | # p = multiprocessing.Process(target=worker, args=(question,return_dict)) 81 | # jobs.append(p) 82 | # p.start() 83 | 84 | # for proc in jobs: 85 | # proc.join() 86 | 87 | 88 | if len(return_dict) > 0 : 89 | answer = return_dict.values()[0] 90 | 91 | if answer in not_found: 92 | answer = 'Check browser' 93 | search_google(question) 94 | 95 | return answer 96 | 97 | 98 | def ask_question2(question) : 99 | global wiki_result 100 | global qus 101 | qus = question 102 | print("here") 103 | manager = multiprocessing.Manager() 104 | share = manager.dict() 105 | p = multiprocessing.Process(target=wiki_multi,args=(share)) 106 | p.start() 107 | 108 | cnt = 0 109 | tot = 15 110 | # try : 111 | # with tqdm(total=tot,desc='Thinking',initial=0) as pbar: 112 | # for i in range(tot): 113 | # sleep(1) 114 | # pbar.update(1) 115 | # cnt += 1 116 | # # if not p.is_alive(): 117 | # # break 118 | 119 | # pbar.update(cnt-tot) 120 | # except : 121 | # pass 122 | for i in tqdm(range(15)): 123 | sleep(1) 124 | p.join(15) 125 | if p.is_alive(): 126 | print("Sorry Can't find answer") 127 | p.terminate() 128 | 129 | # p.join() 130 | cprint(share.values(),'green') 131 | return wiki_result 132 | 133 | 134 | def ask_question1(question) : 135 | """Ask me anything, I will use give my reply using wolframalpha api.if I don't find the answer 136 | I will search google. 137 | Don't worry I have alternative ;p 138 | Written by Saurav Paul.""" 139 | logger.info('Asking wolframalpha.') 140 | global wiki_result 141 | p = Thread(target=wiki,args=(question,) ) 142 | p.start() 143 | # xt = time() 144 | try : 145 | raise Exception 146 | answer = 'no data available' 147 | # cprint('Hmm..Thinking....','yellow') 148 | # t = time() 149 | api_key = 'GLHKQ7-R5V9E6GU3Y' 150 | client = wolframalpha.Client(api_key) 151 | res = client.query(question) 152 | answer = next(res.results).text 153 | # cprint(time()-t,'cyan') 154 | if 'Wolfram|Alpha' in answer: 155 | answer = answer.replace('Wolfram|Alpha',bot['name']) 156 | if 'no data available' in answer: 157 | # answer = wiki_search(question,1) 158 | # print("waiting") 159 | p.join() 160 | # print("waiting done") 161 | answer = wiki_result 162 | # search_google(question) 163 | return answer 164 | except : 165 | logger.info('Wolframalpha do not know the answer.') 166 | # answer = wiki_search(question,1) 167 | # t = time() 168 | # cprint(t-xt,'magenta') 169 | p.join() 170 | # cprint(time()-t,'red') 171 | answer = wiki_result 172 | logger.info(answer) 173 | # search_google(question) 174 | # answer = 'check browser.' 175 | return answer 176 | 177 | # def ask_question(question) : 178 | # """Ask me anything, I will use give my reply using wolframalpha api.if I don't find the answer 179 | # I will search google. 180 | # Don't worry I have alternative ;p 181 | # Written by Saurav Paul.""" 182 | # logger.info('Asking wolframalpha.') 183 | # try : 184 | # answer = 'no data available' 185 | # cprint('Hmm..Thinking....','yellow') 186 | # api_key = 'GLHKQ7-R5V9E6GU3Y' 187 | # client = wolframalpha.Client(api_key) 188 | # res = client.query(question) 189 | # answer = next(res.results).text 190 | # if 'Wolfram|Alpha' in answer: 191 | # answer = answer.replace('Wolfram|Alpha',bot['name']) 192 | # if 'no data available' in answer: 193 | # answer = wiki_search(question,1) 194 | # # search_google(question) 195 | # return answer 196 | # except : 197 | # logger.info('Wolframalpha do not know the answer.') 198 | # answer = wiki_search(question,1) 199 | # logger.info(answer) 200 | # # search_google(question) 201 | # # answer = 'check browser.' 202 | # return answer 203 | 204 | -------------------------------------------------------------------------------- /tools/browser/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/tools/browser/__init__.py -------------------------------------------------------------------------------- /tools/browser/goto.py: -------------------------------------------------------------------------------- 1 | try : 2 | import requests 3 | from googlesearch import search 4 | from settings.logs import * 5 | import webbrowser 6 | from tools.interaction.speak import speak 7 | except Exception as e : 8 | print(e) 9 | 10 | def goto(link): 11 | webbrowser.open(link) 12 | 13 | def find_goto_address(msg): 14 | logger.debug('finding addresses') 15 | try : 16 | search_result_list = list(search(msg,tld='co.in',num = 3,stop=1 , pause =1)) 17 | logger.debug('Found : ' + search_result_list[0]) 18 | # print(search_result_list) 19 | goto(search_result_list[0]) 20 | except: 21 | speak("Sorry sir, haven't found any.") 22 | 23 | def find_address(msg): 24 | try : 25 | search_result_list = list(search(msg,tld='co.in',num = 3,stop=1 , pause =1)) 26 | logger.info('Found : ' + search_result_list[0]) 27 | # print(search_result_list) 28 | return search_result_list[0] 29 | except: 30 | return '' -------------------------------------------------------------------------------- /tools/browser/search.py: -------------------------------------------------------------------------------- 1 | 2 | import webbrowser 3 | 4 | def make_query(msg): 5 | q = '' 6 | lt = msg.split() 7 | i = 0 8 | for word in lt: 9 | if i : 10 | q += '+' 11 | if word == '+': 12 | word = '%2B' 13 | q += word 14 | i += 1 15 | return q 16 | 17 | def search_google(msg): 18 | q = "https://www.google.com/search?q=" 19 | webbrowser.open(q+make_query(msg)) 20 | 21 | def search_wiki(msg): 22 | q = "https://en.wikipedia.org/w/index.php?cirrusUserTesting=control&search=" 23 | webbrowser.open(q + make_query(msg)) 24 | 25 | def search_youtube(msg): 26 | q = 'https://www.youtube.com/results?search_query=' 27 | webbrowser.open(q+make_query(msg)) 28 | 29 | -------------------------------------------------------------------------------- /tools/calculation.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import requests 4 | from bs4 import BeautifulSoup 5 | from settings.logs import logger 6 | except Exception as identifier: 7 | pass 8 | 9 | try : 10 | from settings.settings import bot 11 | except Exception as e: 12 | logger.info(e) 13 | 14 | def rep(msg): 15 | msg = msg.replace(bot['name'],'') 16 | msg = msg.replace("'","") 17 | msg = msg.replace('"','') 18 | msg = msg.replace('+' , '%2B') 19 | return str(msg) 20 | 21 | def api_math(msg): 22 | # https://api.mathjs.org/v4/?expr=2%2B3*sqrt(4) 23 | pass 24 | 25 | def make_ans(ans) : 26 | try : 27 | start = ans 28 | ext ='' 29 | if '×' in ans : 30 | msg = ans.rsplit(sep='×',maxsplit=1) 31 | start = msg[0] 32 | start = start.strip() 33 | msg[1] = str(msg[1]) 34 | msg[1] = msg[1][:3] + '^' + msg[1][3:] 35 | ext = ' x' + msg[1] 36 | 37 | start = start.split('\xa0') 38 | ans = ','.join(start) + ext 39 | return ans 40 | except Exception as e: 41 | print(e) 42 | return ans 43 | 44 | def google_calculation(msg): 45 | try : 46 | headers = { 47 | 'user-agent' : 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0' 48 | } 49 | # headers = { 50 | # 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', 51 | # } 52 | # print(headers) 53 | url = 'https://www.google.com/search?q=' 54 | msg = rep(msg) 55 | lt = msg.split() 56 | for word in lt : 57 | url += word + '+' 58 | logger.info('Got url : ' + url) 59 | source = requests.get(url,headers).text 60 | bs = BeautifulSoup(source,'lxml') 61 | # print(bs) 62 | key = 'BNeawe iBp4i AP7Wnd' 63 | ans = bs.find(class_= key).div.text 64 | return 'Solution is ' + make_ans(ans) 65 | except Exception as e : 66 | logger.info(str(e)) 67 | return "sorry" 68 | 69 | 70 | if __name__ == "__main__": 71 | x = input('IN-> ') 72 | google_calculation(x) 73 | 74 | -------------------------------------------------------------------------------- /tools/credits.py: -------------------------------------------------------------------------------- 1 | from termcolor import cprint 2 | 3 | credit_keys = ['about','credit','credits'] 4 | 5 | 6 | 7 | 8 | def credits(): 9 | pt = '-'*22+'Credits'+'-'*22 10 | cprint(pt,'magenta') 11 | print() 12 | s = """\tThis is a command line virtual assitant for competitive programming. 13 | \tThis software is written by Saurav Paul. 14 | 15 | \tBiography: 16 | \tName = Saurav Paul 17 | \tEmail = sauravpaul.sunny@gmail.com 18 | \tWebsite = https://saurav-paul.github.io/ 19 | """ 20 | cprint(s,'green') 21 | print() 22 | cprint('-'*len(pt),'magenta') 23 | 24 | def if_credit_type(msg): 25 | lt = msg 26 | 27 | for key in credit_keys: 28 | if key == lt: 29 | credits() 30 | return True 31 | return False 32 | 33 | -------------------------------------------------------------------------------- /tools/downloader.py: -------------------------------------------------------------------------------- 1 | import wget, os , requests 2 | from termcolor import cprint 3 | def wget_downloader(url,path=''): 4 | try : 5 | wget.download(url,path) 6 | except : 7 | cprint('link error...','red') 8 | 9 | # def downloader(url): 10 | # chunk_size = 1024 11 | # r = requests.get(url, stream = True) 12 | # total_size = int(r.headers['content.length']) 13 | # print(total_size) 14 | # with open ("python.pdf","wb") as f: 15 | # for data in tqdm(iterable = r.iter_content(chunk_size=chunk_size),total_size/chunk_size,unit = 'KB'): 16 | # f.write(data) 17 | 18 | if __name__ == "__main__": 19 | url = input("ENter the url") 20 | wget_downloader(url) -------------------------------------------------------------------------------- /tools/google_answer.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | import requests 4 | from bs4 import BeautifulSoup 5 | # from settings.logs import logger 6 | except Exception as e: 7 | pass 8 | 9 | try : 10 | from settings.settings import bot 11 | except Exception as e: 12 | # logger.info(e) 13 | pass 14 | 15 | def rep(msg): 16 | msg = msg.replace(bot['name'],'') 17 | msg = msg.replace("'","") 18 | msg = msg.replace('"','') 19 | msg = msg.replace('+' , 'plus') 20 | return str(msg) 21 | 22 | def google_answer(msg): 23 | try : 24 | url = 'https://www.google.com/search?q=' 25 | url ='https://www.wolframalpha.com/input/?i=125+-+375' 26 | msg = rep(msg) 27 | lt = msg.split() 28 | for word in lt : 29 | url += word + '+' 30 | # logger.info('Got url : ' + url) 31 | source = requests.get(url).text 32 | bs = BeautifulSoup(source,'lxml') 33 | print(bs) 34 | # key = 'BNeawe iBp4i AP7Wnd' 35 | # ans = bs.find(class_= key).div.text 36 | return 'Solution is ' + ans 37 | except Exception as e : 38 | # logger.info(str(e)) 39 | print(e) 40 | return "sorry" 41 | 42 | 43 | if __name__ == "__main__": 44 | # x = input('IN-> ') 45 | x='' 46 | x = google_answer(x) 47 | print(x) 48 | 49 | -------------------------------------------------------------------------------- /tools/interaction/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Saurav-Paul/AI-virtual-assistant-python/e2e0378dfe93f2b233e4d15e06ba036fa78dd21e/tools/interaction/__init__.py -------------------------------------------------------------------------------- /tools/interaction/get_audio.py: -------------------------------------------------------------------------------- 1 | 2 | from settings.settings import interaction_setting as it 3 | from settings.logs import * 4 | from system.screen_text import thoughts_processing 5 | from tools.interaction import speak 6 | 7 | 8 | try : 9 | from termcolor import colored, cprint 10 | except Exception as e: 11 | logger.info(str(e)) 12 | 13 | 14 | 15 | def get_audio_text(): 16 | cprint("(Write something) -> ",'cyan',attrs=['bold'],end='') 17 | msg = input() 18 | return msg 19 | 20 | 21 | def get_audio_microphone(): 22 | try : 23 | import speech_recognition as sr 24 | r = sr.Recognizer() 25 | logger.info("Ready to listen") 26 | cprint('(Press enter to give voice commands...)','green',attrs=['bold','blink'],end='') 27 | input() 28 | with sr.Microphone() as source: 29 | r.adjust_for_ambient_noise(source) 30 | logger.info('adjusted ambient noise') 31 | cprint("(Say something) -> ",'cyan',attrs=['bold']) 32 | audio = r.listen(source,timeout=8, phrase_time_limit=20) 33 | said = "" 34 | logger.info('audio listened') 35 | thoughts_processing('voice heared, trying to recognize') 36 | try : 37 | said = r.recognize_google(audio) 38 | if said == '': 39 | thoughts_processing("Haven't got it sir, please try again") 40 | said = get_audio_microphone() 41 | logger.info(said) 42 | except Exception as e: 43 | logger.info("Exception occured "+str(e)) 44 | thoughts_processing("Haven't got it sir, please try again") 45 | said = get_audio_microphone() 46 | return said 47 | except Exception as e: 48 | logger.info(e) 49 | return get_audio_text() 50 | 51 | 52 | def get_audio(): 53 | if it['voice_read_voice_reply']: 54 | return get_audio_microphone() 55 | elif it['text_read']: 56 | return get_audio_text() 57 | else: 58 | logger.error('Your mircrophone audio and read text both are disabled, enable them from settings') 59 | cprint('Your BOT do not have any listing power, give him the power from settings -_-','red',attrs=['bold']) 60 | return 'NONE' 61 | 62 | 63 | 64 | # def get_audio_microphone(): 65 | # prit('Here') 66 | # try : 67 | # import speech_recognition as sr 68 | # r = sr.Recognizer() 69 | # r.adjust_for_ambient_noise(source) 70 | # with sr.Microphone() as source: 71 | # while True : 72 | # audio = r.listen(source) 73 | # try : 74 | # said = r.recognize_google(audio) 75 | # logger.info(said) 76 | # if 'jarvis' in said: 77 | # speak('Listening sir.') 78 | # try : 79 | # audio = r.listen(source) 80 | # said = r.recognize_google(audio) 81 | # return said 82 | # break 83 | # except : 84 | # said = 'Have not got it sir, please try again' 85 | # else : 86 | # continue 87 | # except Exception as e: 88 | # logger.info(str(e)) 89 | # return said 90 | # except : 91 | # return get_audio_text() 92 | -------------------------------------------------------------------------------- /tools/interaction/speak.py: -------------------------------------------------------------------------------- 1 | 2 | from settings.settings import interaction_setting as it 3 | from settings.logs import * 4 | from system.screen_text import thoughts_processing 5 | from settings.settings import bot 6 | 7 | import random 8 | 9 | try : 10 | from termcolor import colored, cprint 11 | except Exception as e: 12 | logger.info(str(e)) 13 | 14 | 15 | try: 16 | import pyttsx3 17 | except Exception as e: 18 | logger.info(str(e)) 19 | 20 | color = ['blue','yellow','green'] 21 | 22 | def speak_voice_pyttsx3(msg): 23 | try: 24 | engine = pyttsx3.init() 25 | engine.setProperty('rate',130) 26 | engine.setProperty('volume',1) 27 | engine.say(msg) 28 | engine.runAndWait() 29 | except Exception as e: 30 | logger.info(str(e)) 31 | 32 | def speak_voice_gtts(sentence): 33 | """" This function takes a text sentence and in return it will speak that sentence. 34 | written by saurav paul""" 35 | logger.info('attempting to speak') 36 | try : 37 | from gtts import gTTS 38 | import os , playsound 39 | thoughts_processing('voice is loading, Sir') 40 | Gtts = gTTS(text=sentence,lang='en') 41 | logger.debug('Gtts setted') 42 | filename = 'voice.mp3' 43 | Gtts.save(filename) 44 | logger.debug('Gtts saved now will play the sound') 45 | playsound.playsound(filename) 46 | logger.debug('removeing file') 47 | os.remove(filename) 48 | except Exception as e: 49 | logger.critical(str(e)) 50 | speak_voice_pyttsx3(sentence) 51 | 52 | def speak_voice_manager(msg): 53 | try : 54 | if bot['voice_engine'] == 'gTTS': 55 | logger.info('Calling gTTS') 56 | speak_voice_gtts(msg) 57 | else: 58 | logger.info('Calling pyttsx3') 59 | speak_voice_pyttsx3(msg) 60 | except Exception as e: 61 | logger.info(str(e)) 62 | 63 | def speak_text(sentence): 64 | """ It will takes a text sentence and reply as bot""" 65 | print() 66 | bot = '(^-^)-> ' 67 | cl = random.choice(color) 68 | cprint(bot,cl,attrs=['bold'],end=' ') 69 | # cprint(cl,cl) 70 | x = sentence.capitalize() 71 | cprint(x,cl) 72 | 73 | 74 | 75 | def speak(sentence): 76 | """This functin will determine if bot will speak or only reply""" 77 | not_ok = True 78 | if it['text_reply']: 79 | speak_text(sentence) 80 | not_ok = False 81 | if it['voice_reply'] or it['voice_read_voice_reply']: 82 | speak_voice_manager(sentence) 83 | not_ok = False 84 | if not_ok : 85 | cprint('Sir your speaking and writing cabapity is disibled. Please enbale it from settings.','red') 86 | 87 | -------------------------------------------------------------------------------- /tools/json_manager.py: -------------------------------------------------------------------------------- 1 | try : 2 | import json 3 | except Exception as e: 4 | pass 5 | 6 | 7 | class JsonManager: 8 | """ It will loads data and dumps data into json. Written By Saurav Paul""" 9 | 10 | def json_read(json_file): 11 | try : 12 | with open(json_file, "r") as read_file: 13 | data = json.load(read_file) 14 | return data 15 | except Exception as e: 16 | print(e) 17 | def json_write(json_file,data={}): 18 | try : 19 | with open(json_file, "w") as write_file: 20 | json.dump(data, write_file) 21 | 22 | json_string = json.dumps(data) 23 | except Exception as e: 24 | print(e) 25 | 26 | if __name__ == "__main__": 27 | x = JsonManager.json_read('tools/AI/conversations.json') 28 | print(x) 29 | for i in x: 30 | print(i) 31 | print(x[i]) 32 | for j in x[i]: 33 | print(x[i][j]) -------------------------------------------------------------------------------- /tools/run_program.py: -------------------------------------------------------------------------------- 1 | try: 2 | import os 3 | from settings.compiler import compiler 4 | from tqdm import tqdm 5 | except Exception as e: 6 | pass 7 | 8 | try: 9 | from termcolor import colored, cprint 10 | except Exception as e: 11 | pass 12 | 13 | run_keys = ['-r', '-run'] 14 | files_ext = ['cpp', 'py'] 15 | 16 | 17 | def run_prog(file_name, debug=False, com=False, no=1): 18 | try: 19 | # print(os.getcwd()) 20 | pt = ("Running the " + file_name + '......') 21 | cprint(pt, 'yellow') 22 | ext = file_name.rsplit(sep='.', maxsplit=1) 23 | ext[0] += '.out' 24 | if ext[1] == 'cpp': 25 | if debug: 26 | cmd = compiler['c++ debug'] 27 | else: 28 | cmd = compiler['c++'] 29 | 30 | cmd = cmd.replace('{filename}', file_name) 31 | cmd = cmd.replace('{executable}', ext[0]) 32 | cmd_part = cmd.split(sep='&&') 33 | with tqdm(total=1.0, desc='Compilation', initial=.25) as pbar: 34 | okk = os.system(cmd_part[0]) 35 | pbar.update(.75) 36 | if okk != 0: 37 | cprint("Compilation Error.", 'red') 38 | return 39 | pt = ('-' * 23 + file_name + '-' * 22 + '\n') 40 | x = ('\n' + '-' * 23 + '-' * len(file_name) + '-' * 22) 41 | if not os.path.isfile(ext[0]): 42 | return 43 | # donot_want = ['no', 'n', 'cancel', '0'] 44 | try: 45 | for i in range(no): 46 | cprint(pt, 'magenta') 47 | okk = os.system(cmd_part[1]) 48 | cprint(x, 'magenta') 49 | if okk: 50 | cprint("Cancelled.", 'red') 51 | cprint(x, 'magenta') 52 | break 53 | if no - i > 1: 54 | text = "Press enter to run again..." 55 | cprint(text, 'yellow', end='') 56 | confirm = input() 57 | cprint(x, 'magenta') 58 | 59 | if com == False: 60 | os.remove(ext[0]) 61 | except: 62 | cprint("Sorry sir can't run.", 'red') 63 | 64 | elif ext[1] == 'py': 65 | cmd = compiler['python'] 66 | cmd = cmd.replace('{filename}', file_name) 67 | x = ('-' * 23 + file_name + '-' * 22) 68 | pt = ('-' * 23 + '-' * len(file_name) + '-' * 22) 69 | try: 70 | for i in range(no): 71 | cprint(x, 'magenta') 72 | okk = os.system(cmd) 73 | cprint(pt, 'magenta') 74 | if okk: 75 | cprint("Cancelled.", 'red') 76 | cprint(x, 'magenta') 77 | break 78 | 79 | if no - i > 1: 80 | text = "Press enter to run again..." 81 | cprint(text, 'yellow', end='') 82 | confirm = input() 83 | 84 | except: 85 | cprint("Sorry sir can't run.", 'red') 86 | else: 87 | cprint('Unknown file format.', 'red') 88 | except Exception as e: 89 | cprint("Compilation Error", 'red') 90 | 91 | 92 | def find_files(lt): 93 | # print(lt) 94 | debug = False 95 | com = False 96 | tm = 1 97 | if '-d' in lt: 98 | debug = True 99 | try: 100 | lt.remove('-d') 101 | except: 102 | pass 103 | if '-c' in lt: 104 | com = True 105 | try: 106 | lt.remove('-c') 107 | except: 108 | pass 109 | if '-dc' in lt: 110 | com = True 111 | debug = True 112 | try: 113 | lt.remove('-dc') 114 | except: 115 | pass 116 | if '-cd' in lt: 117 | com = True 118 | debug = True 119 | try: 120 | lt.remove('-cd') 121 | except: 122 | pass 123 | 124 | # print(lt) 125 | for w in lt: 126 | if '-' in w: 127 | temp = w.replace('-', '') 128 | if temp.isnumeric(): 129 | tm = int(temp) 130 | lt.remove(w) 131 | 132 | # print(tm,lt) 133 | num = len(lt) 134 | file_list = [] 135 | if num == 1: 136 | for file in os.listdir(os.getcwd()): 137 | try: 138 | ext = file.rsplit(sep='.', maxsplit=1) 139 | if ext[1] in files_ext: 140 | file_list.append(file) 141 | except: 142 | pass 143 | else: 144 | arg = lt[1:] 145 | # print(arg) 146 | for w in arg: 147 | for file in os.listdir(os.getcwd()): 148 | if w.lower() in file.lower(): 149 | try: 150 | ext = file.rsplit(sep='.', maxsplit=1) 151 | if ext[1] in files_ext: 152 | file_list.append(file) 153 | except: 154 | pass 155 | no = len(file_list) 156 | if no > 1: 157 | cprint('All the available files...\n', 'yellow') 158 | no = 1 159 | for i in file_list: 160 | x = ' ' * 5 + str(no) + ") " + i 161 | cprint(x, 'blue') 162 | no += 1 163 | x = (' ' * 5 + '0) stop operation') 164 | cprint(x, 'red') 165 | print() 166 | try: 167 | while True: 168 | cprint('Enter the file number : ', 'cyan', end='') 169 | index = int(input()) 170 | if index == 0: 171 | cprint('Operation Cancelled.', 'red') 172 | break 173 | elif index > 0 and index < no: 174 | run_prog(file_list[index - 1], debug, com, tm) 175 | break 176 | else: 177 | cprint('Wrong file index. Please try again.', 'red') 178 | except: 179 | cprint("Some error happended.", 'red', attrs=['bold']) 180 | elif no == 1: 181 | run_prog(file_list[0], debug, com, tm) 182 | else: 183 | cprint('There is not any python or c++ file available.', 'yellow') 184 | 185 | 186 | def if_run_type(msg): 187 | lt = msg.split() 188 | 189 | for key in run_keys: 190 | if key in lt: 191 | find_files(lt) 192 | return True 193 | return False 194 | 195 | 196 | if __name__ == "__main__": 197 | msg = input('int->') 198 | # if_run_type(msg) 199 | -------------------------------------------------------------------------------- /tools/shell.py: -------------------------------------------------------------------------------- 1 | import os 2 | from system.screen_text import command_sep 3 | 4 | shell_keys = ['-shell','-Shell','-s','-S','cmd:'] 5 | 6 | def execute(msg): 7 | command_sep() 8 | os.system(msg) 9 | command_sep() 10 | 11 | 12 | def if_shell_type(msg): 13 | for key in shell_keys: 14 | if key in msg : 15 | msg = msg.replace(key,'',1) 16 | execute(msg) 17 | return True 18 | return False -------------------------------------------------------------------------------- /tools/string_processing.py: -------------------------------------------------------------------------------- 1 | 2 | from fuzzywuzzy import fuzz 3 | from settings.logs import logger 4 | 5 | def match_string(msg,orginal,no = 1): 6 | if no == 1: 7 | return max(fuzz.WRatio(msg,orginal),fuzz.token_sort_ratio(msg,orginal)) 8 | elif no == 2: 9 | return fuzz.WRatio(msg,orginal) 10 | elif no == 3: 11 | return fuzz.ratio(msg,orginal) 12 | else: 13 | return fuzz.token_sort_ratio(msg,orginal) 14 | 15 | def is_matched(msg,orginal,need = 90, no = 1): 16 | percentage = match_string(msg,orginal,no) 17 | # logger.debug(msg + ' '+orginal+' ' +str(percentage) ) 18 | return (True if percentage >= need else False) 19 | 20 | def string_process(msg): 21 | lt = list(msg.split()) 22 | msg = "" 23 | i = 0 24 | for word in lt: 25 | if i : 26 | msg += ' ' 27 | i += 1 28 | msg += word 29 | return msg.lower() 30 | 31 | def wiki_string(msg): 32 | data = ['wiki' , 'wikipedia' , 'what' , 'is' ,'tell' , 'me', 'about' , 'information' ,'give' ,'who'] 33 | msg = msg.split() 34 | key = '' 35 | for w in msg: 36 | if w not in data: 37 | key += w+' ' 38 | 39 | return key.strip() 40 | # def wiki_string(msg): 41 | # data = ['wiki' , 'wikipedia' , 'what' , 'is' ,'tell' , 'me', 'about' , 'information' ,'give' ,'who'] 42 | # for word in data : 43 | # msg = msg.replace(word,'') 44 | 45 | # return msg.strip() -------------------------------------------------------------------------------- /tools/wiki_search.py: -------------------------------------------------------------------------------- 1 | from settings.logs import * 2 | from tools.string_processing import wiki_string , is_matched 3 | from tools.browser.search import search_google 4 | from tools.browser.goto import find_address 5 | from termcolor import cprint 6 | 7 | 8 | 9 | def make_wiki_key(msg): 10 | try : 11 | msg = 'en.wikipedia.org '+msg 12 | msg = find_address(msg) 13 | msg = msg.rsplit(sep='/',maxsplit=1) 14 | return msg[1] 15 | except: 16 | return msg 17 | 18 | def get_summary(msg , no): 19 | msg = msg.split(sep='.') 20 | ans = '' 21 | cnt = 0 22 | for i in msg: 23 | if cnt == no: 24 | break 25 | ans += i+'.' 26 | cnt += 1 27 | 28 | return ans 29 | 30 | def wiki_summary(msg,no = 2): 31 | """ This function will reply the summary of the given text""" 32 | 33 | # print("wiki_summary") 34 | got_error = 'no data available' 35 | try : 36 | import wikipediaapi 37 | except Exception as e: 38 | logger.info(e) 39 | return got_error 40 | 41 | key_msg = wiki_string(msg) 42 | logger.info("After string process : "+key_msg) 43 | msg = make_wiki_key(key_msg) 44 | 45 | logger.info("Wiki key : "+str(msg)) 46 | 47 | key_msg = str(key_msg) 48 | msg = str(msg) 49 | 50 | matched = is_matched(key_msg,msg, need = 75) 51 | logger.info("Matched : " + str(matched)) 52 | if not matched: 53 | return got_error 54 | wiki_wiki = wikipediaapi.Wikipedia('en') 55 | 56 | page_py = wiki_wiki.page(msg) 57 | logger.info(page_py.exists()) 58 | summary = get_summary(page_py.summary,no) 59 | 60 | # cprint(summary,'yellow') 61 | 62 | return summary 63 | 64 | 65 | def wiki_search(msg,no =2): 66 | return wiki_summary(msg,no) 67 | 68 | # def wiki_search(msg, no = 2) : 69 | # """ This function will search through wikipedia and will reply information 70 | # Written by Saurav Paul. 71 | # """ 72 | # try : 73 | # import wikipedia 74 | # except Exception as e: 75 | # logger.inf(str(e)) 76 | # return wiki_summary(msg,no) 77 | 78 | # logger.info('Searching to wikipedia.') 79 | # cprint('\t\t(Thinking)','yellow') 80 | # rem = msg 81 | # msg = wiki_string(msg.lower()) 82 | # msg = make_wiki_key(msg) 83 | # logger.info('after processing the string is : ' + msg) 84 | # try : 85 | # results = wikipedia.summary(msg,sentences=no) 86 | # return results 87 | # except : 88 | # logger.info("Haven't found anything relevant in wikipedia") 89 | # # search_google(rem) 90 | # return 'no data available' 91 | 92 | --------------------------------------------------------------------------------