A Inteligência Artificial que escreve programas
Neste artigo veremos um projeto de software livre subsidiado pela Google e militares criado para escrever programas, mais precisamente trechos de um sistema. Este documento demonstra que no futuro, a inteligência artificial atuará similar a função do corretor de texto para escritores, porém com um propósito de encontrar a melhor sintaxe para o contexto lógico.
Parte 2: Mão na Massa
Aqui veremos o que será necessário para executar o projeto BAYOU, desde os seus requisitos até a instalação e execução.
Requisitos:
Para o texto tornar extenso, assumirei que o ambiente Linux com Java, Python e Maven está devidamente instalado e configurado.
# pip install tensorflow
# pip install scikit-learn
Para testar o funcionamento adequado do tensorflow, utilize as instruções a seguir. Se o resultado for similar, significa que o ambiente python está devidamente configurado.
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
Agora efetue o download a partir do código fonte.
git clone https://github.com/capergroup/bayou.git
Após o download, siga o exemplo a seguir para resolver as dependências java:
cd bayou/tool_files/build_scripts
$ sudo ./install_dependencies.sh
A compilação é efetuada com o comando build:
./build.sh
Agora para executar o motor principal, entre na pasta out e execute o comando start_bayou.sh:
cd out/
$ ./start_bayou.sh
2018-09-08 20:53:52.604:INFO::main: Logging initialized @2482ms to org.eclipse.jetty.util.log.StdErrLog
2018-09-08 20:53:52.896:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-09-08 20:53:52.992:INFO:oejs.AbstractConnector:main: Started ServerConnector@2cbb3d47{HTTP/1.1,[http/1.1]}{0.0.0.0:8081}
2018-09-08 20:53:52.993:INFO:oejs.Server:main: Started @2871ms
2018-09-08 20:53:52.994:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-09-08 20:53:52.995:INFO:oejs.AbstractConnector:main: Started ServerConnector@7ea37dbf{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2018-09-08 20:53:52.995:INFO:oejs.Server:main: Started @2873ms
===================================
Loading Model. Please Wait.
===================================
INFO:tensorflow:Restoring parameters from model49.ckpt
===================================
Bayou Ready
===================================
* Serving Flask app "ast_server" (lazy loading)
* Environment: production
Use a production WSGI server instead.
* Debug mode: off
Agora crie um arquivo .java onde desejamos que a inteligência artificial atue, coloque a TAG FILEWRITE para escrita de arquivo utilizando BUFFER.
Agora utilize o comando synthesize para o sistema devolver o resultado do problema proposto:
./synthesize.sh exemplo/Test.java
Veja o resultado:
A seguir um vídeo demonstrativo da implementação do Bayou no meu projeto Modoki de código aberto.
Autor: Alessandro de Oliveira Faria (cabelo@opensuse.org)
Requisitos:
- Linux (CLARO!)
- Maven
- Mavn-jansi
- Tensorflow
- Scikit-learn
Para o texto tornar extenso, assumirei que o ambiente Linux com Java, Python e Maven está devidamente instalado e configurado.
Instalando os pacotes Tensorflow e Scikit-learn
Com o ambiente python funcionando corretamente, utilize os comandos abaixo como super-usuário para resolver as dependências python do projeto Bayou:# pip install tensorflow
# pip install scikit-learn
Para testar o funcionamento adequado do tensorflow, utilize as instruções a seguir. Se o resultado for similar, significa que o ambiente python está devidamente configurado.
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
Agora efetue o download a partir do código fonte.
git clone https://github.com/capergroup/bayou.git
Após o download, siga o exemplo a seguir para resolver as dependências java:
cd bayou/tool_files/build_scripts
$ sudo ./install_dependencies.sh
A compilação é efetuada com o comando build:
./build.sh
Agora para executar o motor principal, entre na pasta out e execute o comando start_bayou.sh:
cd out/
$ ./start_bayou.sh
2018-09-08 20:53:52.604:INFO::main: Logging initialized @2482ms to org.eclipse.jetty.util.log.StdErrLog
2018-09-08 20:53:52.896:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-09-08 20:53:52.992:INFO:oejs.AbstractConnector:main: Started ServerConnector@2cbb3d47{HTTP/1.1,[http/1.1]}{0.0.0.0:8081}
2018-09-08 20:53:52.993:INFO:oejs.Server:main: Started @2871ms
2018-09-08 20:53:52.994:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT
2018-09-08 20:53:52.995:INFO:oejs.AbstractConnector:main: Started ServerConnector@7ea37dbf{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2018-09-08 20:53:52.995:INFO:oejs.Server:main: Started @2873ms
===================================
Loading Model. Please Wait.
===================================
INFO:tensorflow:Restoring parameters from model49.ckpt
===================================
Bayou Ready
===================================
* Serving Flask app "ast_server" (lazy loading)
* Environment: production
Use a production WSGI server instead.
* Debug mode: off
Agora crie um arquivo .java onde desejamos que a inteligência artificial atue, coloque a TAG FILEWRITE para escrita de arquivo utilizando BUFFER.
import java.io.*;
import java.util.*;
public class Test {
void write(File file, String toWrite) {
{
/// call:write type:FileWriter type:BufferedWriter
}
}
}
Agora utilize o comando synthesize para o sistema devolver o resultado do problema proposto:
./synthesize.sh exemplo/Test.java
Veja o resultado:
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(toWrite);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.newLine();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
try {
fw1 = new FileWriter(toWrite);
fw1.write(toWrite);
fw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite) {
{
FileWriter fw1;
try {
fw1 = new FileWriter(file);
fw1.write(toWrite);
fw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite, boolean _arg11) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(toWrite, _arg11);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.newLine();
bw1.flush();
bw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite, boolean _arg11) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file, _arg11);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite, boolean _arg11) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file, _arg11);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.newLine();
bw1.flush();
bw1.close();
} catch (IOException _e) {
}
return;
}
}
}
---------- BEGIN PROGRAM ----------
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
void write(File file, String toWrite, boolean _arg11) {
{
FileWriter fw1;
BufferedWriter bw1;
try {
fw1 = new FileWriter(file, _arg11);
bw1 = new BufferedWriter(fw1);
bw1.write(toWrite);
bw1.newLine();
} catch (IOException _e) {
}
return;
}
}
}
Resumidamente, recebemos diversos exemplos de como escrever um método para escrever um arquivo! Genial...
A seguir um vídeo demonstrativo da implementação do Bayou no meu projeto Modoki de código aberto.

Embaixador openSUSE Linux America Latina Membro openSUSE http://pt.opensuse.org/Utilizador:Cabelo Membro Mozillians https://mozillians.org/pt-BR/u/cabelo/ Membro Owasp http://tinyurl.com/owasp-member Membro Area31 HackerSpacehttp://tinyurl.com/HackerSpace-Member Membro FOCA Linux http://tinyurl.com/guia-foca-linux Membro Educatux https://www.educatux.com.br/pessoas Membro Intel Innovator https://tinyurl.com/intel-innovator Membro OpenCV https://tinyurl.com/membro-opencv Membro Viva O Linux https://www.vivaolinux.com.br/~cabelo