# you need to install websockets before you use this print('\n'*50) import asyncio import websockets from auto_everything.base import IO io = IO() import json from opencv import MyOpencv myopencv = MyOpencv() async def hello(websocket, path): global one_frame_of_data while 1: data = await websocket.recv() if isinstance(data, str): json_data = json.loads(data) print(json_data) print('\n'*2) elif isinstance(data, bytes): myopencv.show(data) start_server = websockets.serve(hello, 'localhost', 8000) asyncio.get_event_loop().run_until_complete(start_server)
#!/usr/bin/env /usr/bin/python3 from auto_everything.terminal import Terminal from auto_everything.disk import Disk from auto_everything.base import IO from auto_everything.base import Python import json t = Terminal() disk = Disk() io = IO() py = Python() def seperate(): print() print("-------") print() DEVICE = "/dev/ttyUSB0" PRE_COMMAND = f"ampy -p {DEVICE} " LS = PRE_COMMAND + "ls" DELETE = PRE_COMMAND + "rm " PUT = PRE_COMMAND + "put " micropython_files = [ name.strip("/") for name in t.run_command(LS).split("\n") if name.strip() != "" and name[-3:] == ".py" ] print(micropython_files) if len(micropython_files) == 0: exit()
from model import generate_model import tensorflow as tf import os import numpy as np from random import randint from nes_py.wrappers import JoypadSpace import gym_super_mario_bros from gym_super_mario_bros.actions import SIMPLE_MOVEMENT import time import random from auto_everything.base import IO io = IO() env = gym_super_mario_bros.make('SuperMarioBros-v2') env = JoypadSpace(env, SIMPLE_MOVEMENT) model_file_path = './nn_model.HDF5' final_model_file_path = './final_nn_model.HDF5' if os.path.exists(model_file_path): model = tf.keras.models.load_model(model_file_path) else: model = generate_model() # env.action_space.sample() = numbers, for example, 0,1,2,3... # state = RGB of raw picture; is a numpy array with shape (240, 256, 3) # reward = int; for example, 0, 1 ,2, ... # done = False or True # info = {'coins': 0, 'flag_get': False, 'life': 3, 'score': 0, 'stage': 1, 'status': 'small', 'time': 400, 'world': 1, 'x_pos': 40} done = True last_state = None
from auto_everything.base import IO io = IO() import os import json files = os.listdir("../data") files = [file for file in files if '.json' in file] item_list = [] for index, file in enumerate(files): file = file.replace(".json", "") item_list.append({'index': index, 'label_name': file}) print(index, file) start = """ export const motion_classes = { """ end = "}" final_js = start for item in item_list: final_js += '{index}: "{name}",'.format(index=item['index'], name=item['label_name']) + '\n' final_js += end io.write('../js/motion_classes.js', final_js)
from model import generate_model import tensorflow as tf import os import numpy as np import time from random import randint from nes_py.wrappers import JoypadSpace import gym_super_mario_bros from gym_super_mario_bros.actions import COMPLEX_MOVEMENT from auto_everything.base import IO io = IO() env = gym_super_mario_bros.make('SuperMarioBros-v2') env = JoypadSpace(env, COMPLEX_MOVEMENT) model_file_path = './nn_model.HDF5' final_model_file_path = './final_nn_model.HDF5' if os.path.exists(model_file_path): model = tf.keras.models.load_model(model_file_path) else: model = generate_model() # env.action_space.sample() = numbers, for example, 0,1,2,3... # state = RGB of raw picture; is a numpy array with shape (240, 256, 3) # reward = int; for example, 0, 1 ,2, ... # done = False or True # info = {'coins': 0, 'flag_get': False, 'life': 3, 'score': 0, 'stage': 1, 'status': 'small', 'time': 400, 'world': 1, 'x_pos': 40} identity = np.identity(
#!/usr/bin/env /usr/bin/python3 #!/usr/bin/env /usr/bin/python3 from auto_everything.base import Python, Terminal, IO py = Python() t = Terminal() io_ = IO() class Tools(): def build(self): t.run('yarn build') content = io_.read("./build/index.html") content = content.replace( "<title>React App</title>", """ <title>yingshaoxo | 技术宅</title> <meta name="author" content="yingshaoxo" /> <meta name="description" content="yingshaoxo, born in 1998, love IT. Want to find out all those mysteries in this universe, especially how human thinks. So I embrace AI." /> <meta name="keywords" content="yingshaoxo, Python, Javascript, C++" /> """.replace("\n", "")) io_.write("./build/index.html", content) py.make_it_runnable() py.fire(Tools)
import eventlet eventlet.monkey_patch() from king_chat import Server server = Server(ip="0.0.0.0", port=5920) import json import os from auto_everything.base import IO io = IO() from flask import Flask, render_template,redirect from flask_socketio import SocketIO, emit # make sure static folder is the react build folder, and static path is the root, so static_url_path = '' app = Flask(__name__, template_folder='../front-end_app/build', static_url_path='', static_folder='../front-end_app/build') app.config['SECRET_KEY'] = 'yingshaoxo is the king' socketio = SocketIO(app) msgs = [] temp_json_file = "msgs.json" if not os.path.exists(temp_json_file): io.write(temp_json_file, json.dumps([])) @server.on_received def handle(protocol, text): #protocol.send_to_all_except_sender(text)
from auto_everything.base import IO io = IO() import os import json files = os.listdir("../data") files = [file for file in files if '.json' in file] item_list = [] for index, file in enumerate(files): file = file.replace(".json", "") item_list.append({'index': index, 'label_name': file}) print(index, file) start = """ export const looking_classes = { """ end = "}" final_js = start for item in item_list: final_js += '{index}: "{name}",'.format(index=item['index'], name=item['label_name']) + '\n' final_js += end io.write('../js/looking_classes.js', final_js)
import os from auto_everything.base import IO io = IO() import json from pprint import pprint import numpy as np files = os.listdir("../data") files = [file for file in files if '.json' in file] global x, y for index, file in enumerate(files): # get x xx = json.loads(io.read("../data/{name}".format(name=file))) xx = np.array(xx) print(xx.shape) # get y #yy = np.zeros(xx.shape[0]) yy = np.full(xx.shape[0], index) if index == 0: x = xx y = yy else: x = np.append(x, xx, axis=0) y = np.append(y, yy, axis=0)
from auto_everything.base import IO io = IO() import os import json files = os.listdir("../data") files = [file for file in files if '.json' in file] item_list = [] for index, file in enumerate(files): file = file.replace(".json", "") item_list.append({'index': index, 'label_name': file}) print(index, file) start = """ export const pose_classes = { """ end = "}" final_js = start for item in item_list: final_js += '{index}: "{name}",'.format(index=item['index'], name=item['label_name']) + '\n' final_js += end io.write('../js/pose_classes.js', final_js)