Spaces:
Build error
Build error
Beracles commited on
Commit ·
aa290c6
1
Parent(s): 5828bef
initialize
Browse files- .gitignore +160 -0
- Dockerfile +14 -0
- app/__init__.py +0 -0
- app/bodys.py +39 -0
- app/voc.py +53 -0
- app/watermelon.py +413 -0
- main.py +16 -0
- requirements.txt +7 -0
.gitignore
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# poetry
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 102 |
+
#poetry.lock
|
| 103 |
+
|
| 104 |
+
# pdm
|
| 105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 106 |
+
#pdm.lock
|
| 107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 108 |
+
# in version control.
|
| 109 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 110 |
+
.pdm.toml
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
# PyCharm
|
| 156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
+
#.idea/
|
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.10.5
|
| 5 |
+
|
| 6 |
+
WORKDIR /code
|
| 7 |
+
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/__init__.py
ADDED
|
File without changes
|
app/bodys.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
class FeatureNoArg(BaseModel):
|
| 5 |
+
command: str
|
| 6 |
+
|
| 7 |
+
class Config:
|
| 8 |
+
frome_attributes = True
|
| 9 |
+
|
| 10 |
+
class FeatureOneIntegerArg(BaseModel):
|
| 11 |
+
command: str
|
| 12 |
+
integer: int
|
| 13 |
+
|
| 14 |
+
class Config:
|
| 15 |
+
frome_attributes = True
|
| 16 |
+
|
| 17 |
+
class FeatureOneStringArg(BaseModel):
|
| 18 |
+
command: str
|
| 19 |
+
string: str
|
| 20 |
+
|
| 21 |
+
class Config:
|
| 22 |
+
frome_attributes = True
|
| 23 |
+
|
| 24 |
+
class FeatureStringAndIntegerArg(BaseModel):
|
| 25 |
+
command: str
|
| 26 |
+
string: str
|
| 27 |
+
integer: int
|
| 28 |
+
|
| 29 |
+
class Config:
|
| 30 |
+
frome_attributes = True
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class FeatureStringAndDecimalArg(BaseModel):
|
| 34 |
+
command: str
|
| 35 |
+
string: str
|
| 36 |
+
decimal: float
|
| 37 |
+
|
| 38 |
+
class Config:
|
| 39 |
+
frome_attributes = True
|
app/voc.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#######################
|
| 2 |
+
# voc
|
| 3 |
+
#######################
|
| 4 |
+
|
| 5 |
+
# singleton (one word)
|
| 6 |
+
x_help = "help"
|
| 7 |
+
|
| 8 |
+
# verb
|
| 9 |
+
x_list = "list"
|
| 10 |
+
x_reset = "reset"
|
| 11 |
+
x_set = "set"
|
| 12 |
+
x_add = "add"
|
| 13 |
+
x_delete = "delete"
|
| 14 |
+
x_enable = "enable" # switch-on and off
|
| 15 |
+
x_disable = "disable" # switch-on and off
|
| 16 |
+
x_increase = "increase"
|
| 17 |
+
x_decrease = "decrease"
|
| 18 |
+
x_change = "change"
|
| 19 |
+
x_drop = "drop" # spawn/drop
|
| 20 |
+
x_custmize = "custmize"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# noun
|
| 24 |
+
x_mode = "mode" # game mode, not modes, in voc, we prefer single over plurs
|
| 25 |
+
x_fruit = "fruit" # objects/items/elements/fruits
|
| 26 |
+
x_background = "background"
|
| 27 |
+
x_music = "music"
|
| 28 |
+
x_image = "image"
|
| 29 |
+
x_game = "game"
|
| 30 |
+
x_winning_condition = "winning condition"
|
| 31 |
+
x_rule = "rule" # means formula or blueprint, etc
|
| 32 |
+
x_prop = "prop" # powerups/buffs/boosts
|
| 33 |
+
x_death_line = "death line" # "game over line"/ceiling
|
| 34 |
+
x_bomb = "bomb"
|
| 35 |
+
x_freeze = "freeze"
|
| 36 |
+
x_lightning = "lightning"
|
| 37 |
+
x_swap_card = "swap card"
|
| 38 |
+
# x_object = "object"
|
| 39 |
+
x_timer = "timer"
|
| 40 |
+
|
| 41 |
+
# properties
|
| 42 |
+
x_skin = "skin" # images/sprites/skin/pictures/art
|
| 43 |
+
# x_quantity = "quantity"
|
| 44 |
+
x_color = "color"
|
| 45 |
+
x_odd = "odd"
|
| 46 |
+
x_value = "value"
|
| 47 |
+
# x_type = 'type'
|
| 48 |
+
x_size = "size"
|
| 49 |
+
x_args = "args"
|
| 50 |
+
x_power = "power"
|
| 51 |
+
# x_unit = "unit"
|
| 52 |
+
x_multiplier = "multiplier"
|
| 53 |
+
x_muliple = "multiple"
|
app/watermelon.py
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from fastapi import APIRouter, Response
|
| 3 |
+
from fastapi import status
|
| 4 |
+
from .bodys import *
|
| 5 |
+
from .voc import *
|
| 6 |
+
from pgsoft.pgdate.date_utils import beijing
|
| 7 |
+
from huggingface_hub import HfApi
|
| 8 |
+
import os
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
router = APIRouter(
|
| 12 |
+
prefix="/watermelon",
|
| 13 |
+
tags=["watermelon"],
|
| 14 |
+
)
|
| 15 |
+
hfapi = HfApi()
|
| 16 |
+
train_generated = {}
|
| 17 |
+
game = "watermelon"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@router.get("/")
|
| 21 |
+
def root():
|
| 22 |
+
return {"detail": "AI Command Patcher",
|
| 23 |
+
"game": "watermelon"}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@router.post("/submit")
|
| 27 |
+
def submit(response: Response):
|
| 28 |
+
global train_generated
|
| 29 |
+
if not train_generated:
|
| 30 |
+
response.status_code = status.HTTP_404_NOT_FOUND
|
| 31 |
+
return {
|
| 32 |
+
"result": "Failure",
|
| 33 |
+
"detail": "No data to submit",
|
| 34 |
+
}
|
| 35 |
+
timestamp = beijing().strftime("%Y%m%d_%H%M%S_%f")
|
| 36 |
+
filename = timestamp+".jsonl"
|
| 37 |
+
marker = timestamp+".submit"
|
| 38 |
+
filepath = "/".join([game, filename])
|
| 39 |
+
markerpath = "/".join([game, marker])
|
| 40 |
+
if not os.path.exists(game):
|
| 41 |
+
os.mkdir(game)
|
| 42 |
+
with open(filepath, "w") as f:
|
| 43 |
+
for key in train_generated:
|
| 44 |
+
myobj = {
|
| 45 |
+
"command": key,
|
| 46 |
+
"result": train_generated[key]["result"],
|
| 47 |
+
"desc": train_generated[key]["desc"],
|
| 48 |
+
}
|
| 49 |
+
json.dump(myobj, f, indent=None)
|
| 50 |
+
f.write("\n")
|
| 51 |
+
open(markerpath, "w").close()
|
| 52 |
+
db_token = os.environ.get("db_token")
|
| 53 |
+
try:
|
| 54 |
+
hfapi.upload_file(
|
| 55 |
+
path_or_fileobj=filepath,
|
| 56 |
+
path_in_repo=filepath,
|
| 57 |
+
repo_id="pgsoft/features",
|
| 58 |
+
repo_type="dataset",
|
| 59 |
+
token=db_token)
|
| 60 |
+
hfapi.upload_file(
|
| 61 |
+
path_or_fileobj=markerpath,
|
| 62 |
+
path_in_repo=markerpath,
|
| 63 |
+
repo_id="pgsoft/features",
|
| 64 |
+
repo_type="dataset",
|
| 65 |
+
token=db_token)
|
| 66 |
+
train_generated.clear()
|
| 67 |
+
response.status_code = status.HTTP_200_OK
|
| 68 |
+
return {
|
| 69 |
+
"result": "OK",
|
| 70 |
+
"detail": f"submitted successfully",
|
| 71 |
+
"filename": filename,
|
| 72 |
+
}
|
| 73 |
+
except Exception as e:
|
| 74 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 75 |
+
return {
|
| 76 |
+
"result": "Failure",
|
| 77 |
+
"detail": f"failed to upload file to huggingface hub, {e}"
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@router.post("/help")
|
| 82 |
+
def help(feature: FeatureNoArg, response: Response):
|
| 83 |
+
global train_generated
|
| 84 |
+
command = feature.command.strip()
|
| 85 |
+
if command in train_generated:
|
| 86 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 87 |
+
return {
|
| 88 |
+
"result": "Failure",
|
| 89 |
+
"detail": "command already exists in memory",
|
| 90 |
+
"count": train_generated.__len__(),
|
| 91 |
+
}
|
| 92 |
+
tmp = {
|
| 93 |
+
command: {
|
| 94 |
+
"result": [
|
| 95 |
+
x_help,
|
| 96 |
+
{},
|
| 97 |
+
],
|
| 98 |
+
"desc": [
|
| 99 |
+
"help",
|
| 100 |
+
],
|
| 101 |
+
},
|
| 102 |
+
}
|
| 103 |
+
train_generated |= tmp
|
| 104 |
+
response.status_code = status.HTTP_200_OK
|
| 105 |
+
return {
|
| 106 |
+
"result": "OK",
|
| 107 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 108 |
+
"please execute submit after adding all",
|
| 109 |
+
"count": train_generated.__len__(),
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
@router.post("/reset_game")
|
| 114 |
+
def reset_game(feature: FeatureNoArg, response: Response):
|
| 115 |
+
global train_generated
|
| 116 |
+
command = feature.command.strip()
|
| 117 |
+
if command in train_generated:
|
| 118 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 119 |
+
return {
|
| 120 |
+
"result": "Failure",
|
| 121 |
+
"detail": "command already exists in memory",
|
| 122 |
+
"count": train_generated.__len__(),
|
| 123 |
+
}
|
| 124 |
+
tmp = {
|
| 125 |
+
command: {
|
| 126 |
+
"result": [
|
| 127 |
+
x_reset,
|
| 128 |
+
x_game,
|
| 129 |
+
{},
|
| 130 |
+
],
|
| 131 |
+
"desc": [
|
| 132 |
+
"reset game",
|
| 133 |
+
],
|
| 134 |
+
},
|
| 135 |
+
}
|
| 136 |
+
train_generated |= tmp
|
| 137 |
+
response.status_code = status.HTTP_200_OK
|
| 138 |
+
return {
|
| 139 |
+
"result": "OK",
|
| 140 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 141 |
+
"please execute submit after adding all",
|
| 142 |
+
"count": train_generated.__len__(),
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
@router.post(
|
| 147 |
+
path="/set_number_of_sth",
|
| 148 |
+
description="""
|
| 149 |
+
set number of something, string arg could be "fruit", "prop",
|
| 150 |
+
"swap card", "lightning", "bomb", "freeze"
|
| 151 |
+
""")
|
| 152 |
+
def set_number_of_something(feature: FeatureStringAndIntegerArg, response: Response):
|
| 153 |
+
global train_generated
|
| 154 |
+
command = feature.command.strip()
|
| 155 |
+
if command in train_generated:
|
| 156 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 157 |
+
return {
|
| 158 |
+
"result": "Failure",
|
| 159 |
+
"detail": "command already exists in memory",
|
| 160 |
+
"count": train_generated.__len__(),
|
| 161 |
+
}
|
| 162 |
+
target=feature.string.strip()
|
| 163 |
+
if target not in [x_fruit, x_prop, x_swap_card, x_lightning, x_bomb, x_freeze]:
|
| 164 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 165 |
+
return {
|
| 166 |
+
"result": "Failure",
|
| 167 |
+
"detail": "arg is not valid",
|
| 168 |
+
"count": train_generated.__len__(),
|
| 169 |
+
}
|
| 170 |
+
tmp = {
|
| 171 |
+
command: {
|
| 172 |
+
"result": [
|
| 173 |
+
x_set,
|
| 174 |
+
target,
|
| 175 |
+
{x_args: feature.integer},
|
| 176 |
+
],
|
| 177 |
+
"desc": [
|
| 178 |
+
f"set number of {target}",
|
| 179 |
+
],
|
| 180 |
+
},
|
| 181 |
+
}
|
| 182 |
+
train_generated |= tmp
|
| 183 |
+
response.status_code = status.HTTP_200_OK
|
| 184 |
+
return {
|
| 185 |
+
"result": "OK",
|
| 186 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 187 |
+
"please execute submit after adding all",
|
| 188 |
+
"count": train_generated.__len__(),
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
@router.post("/delete_all_of_sth",
|
| 193 |
+
description="""
|
| 194 |
+
delete all of something, arg could be "fruit",
|
| 195 |
+
"prop", "swap card", "lightning", "bomb", "freeze"
|
| 196 |
+
""")
|
| 197 |
+
def delete_all_of_something(feature: FeatureOneStringArg, response: Response):
|
| 198 |
+
global train_generated
|
| 199 |
+
command = feature.command.strip()
|
| 200 |
+
if command in train_generated:
|
| 201 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 202 |
+
return {
|
| 203 |
+
"result": "Failure",
|
| 204 |
+
"detail": "command already exists in memory",
|
| 205 |
+
"count": train_generated.__len__(),
|
| 206 |
+
}
|
| 207 |
+
target=feature.string.strip()
|
| 208 |
+
if target not in [x_fruit, x_prop, x_swap_card, x_lightning, x_bomb, x_freeze]:
|
| 209 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 210 |
+
return {
|
| 211 |
+
"result": "Failure",
|
| 212 |
+
"detail": "arg is not valid",
|
| 213 |
+
"count": train_generated.__len__(),
|
| 214 |
+
}
|
| 215 |
+
tmp = {
|
| 216 |
+
command: {
|
| 217 |
+
"result": [
|
| 218 |
+
x_delete,
|
| 219 |
+
target,
|
| 220 |
+
{x_args: "all"},
|
| 221 |
+
],
|
| 222 |
+
"desc": [
|
| 223 |
+
f"delete all of {target}",
|
| 224 |
+
],
|
| 225 |
+
},
|
| 226 |
+
}
|
| 227 |
+
train_generated |= tmp
|
| 228 |
+
response.status_code = status.HTTP_200_OK
|
| 229 |
+
return {
|
| 230 |
+
"result": "OK",
|
| 231 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 232 |
+
"please execute submit after adding all",
|
| 233 |
+
"count": train_generated.__len__(),
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
@router.post("/delete_sth",
|
| 239 |
+
description="""
|
| 240 |
+
delete some number of something, string arg could be "fruit",
|
| 241 |
+
"prop", "swap card", "lightning", "bomb", "freeze"
|
| 242 |
+
""")
|
| 243 |
+
def delete_something(feature: FeatureStringAndIntegerArg, response: Response):
|
| 244 |
+
global train_generated
|
| 245 |
+
command = feature.command.strip()
|
| 246 |
+
if command in train_generated:
|
| 247 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 248 |
+
return {
|
| 249 |
+
"result": "Failure",
|
| 250 |
+
"detail": "command already exists in memory",
|
| 251 |
+
"count": train_generated.__len__(),
|
| 252 |
+
}
|
| 253 |
+
target=feature.string.strip()
|
| 254 |
+
if target not in [x_fruit, x_prop, x_swap_card, x_lightning, x_bomb, x_freeze]:
|
| 255 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 256 |
+
return {
|
| 257 |
+
"result": "Failure",
|
| 258 |
+
"detail": "arg is not valid",
|
| 259 |
+
"count": train_generated.__len__(),
|
| 260 |
+
}
|
| 261 |
+
tmp = {
|
| 262 |
+
command: {
|
| 263 |
+
"result": [
|
| 264 |
+
x_delete,
|
| 265 |
+
target,
|
| 266 |
+
{x_args: feature.integer},
|
| 267 |
+
],
|
| 268 |
+
"desc": [
|
| 269 |
+
f"delete some number of {target}",
|
| 270 |
+
],
|
| 271 |
+
},
|
| 272 |
+
}
|
| 273 |
+
train_generated |= tmp
|
| 274 |
+
response.status_code = status.HTTP_200_OK
|
| 275 |
+
return {
|
| 276 |
+
"result": "OK",
|
| 277 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 278 |
+
"please execute submit after adding all",
|
| 279 |
+
"count": train_generated.__len__(),
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
@router.post("/add_fruit_type",
|
| 285 |
+
description="""add a type of fruit, arg should be a letter""")
|
| 286 |
+
def add_fruit_type(feature: FeatureOneStringArg, response: Response):
|
| 287 |
+
global train_generated
|
| 288 |
+
command = feature.command.strip()
|
| 289 |
+
if command in train_generated:
|
| 290 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 291 |
+
return {
|
| 292 |
+
"result": "Failure",
|
| 293 |
+
"detail": "command already exists in memory",
|
| 294 |
+
"count": train_generated.__len__(),
|
| 295 |
+
}
|
| 296 |
+
fruit_type=feature.string.strip().upper()
|
| 297 |
+
if len(fruit_type) != 1 or fruit_type>"Z" or fruit_type < "A":
|
| 298 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 299 |
+
return {
|
| 300 |
+
"result": "Failure",
|
| 301 |
+
"detail": "fruit type is not valid",
|
| 302 |
+
"count": train_generated.__len__(),
|
| 303 |
+
}
|
| 304 |
+
tmp = {
|
| 305 |
+
command: {
|
| 306 |
+
"result": [
|
| 307 |
+
x_delete,
|
| 308 |
+
x_fruit,
|
| 309 |
+
{x_args: fruit_type},
|
| 310 |
+
],
|
| 311 |
+
"desc": [
|
| 312 |
+
"add a type of fruit",
|
| 313 |
+
],
|
| 314 |
+
},
|
| 315 |
+
}
|
| 316 |
+
train_generated |= tmp
|
| 317 |
+
response.status_code = status.HTTP_200_OK
|
| 318 |
+
return {
|
| 319 |
+
"result": "OK",
|
| 320 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 321 |
+
"please execute submit after adding all",
|
| 322 |
+
"count": train_generated.__len__(),
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
@router.post("/set_fruit_odds",
|
| 328 |
+
description="""
|
| 329 |
+
set the odds of a type of fruit, fruit type should be a letter,
|
| 330 |
+
and odds should be a decimal number between 0 and 1""")
|
| 331 |
+
def set_fruit_odds(feature: FeatureStringAndDecimalArg, response: Response):
|
| 332 |
+
global train_generated
|
| 333 |
+
command = feature.command.strip()
|
| 334 |
+
if command in train_generated:
|
| 335 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 336 |
+
return {
|
| 337 |
+
"result": "Failure",
|
| 338 |
+
"detail": "command already exists in memory",
|
| 339 |
+
"count": train_generated.__len__(),
|
| 340 |
+
}
|
| 341 |
+
fruit_type=feature.string.strip().upper()
|
| 342 |
+
if len(fruit_type) != 1 or fruit_type>"Z" or fruit_type < "A":
|
| 343 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 344 |
+
return {
|
| 345 |
+
"result": "Failure",
|
| 346 |
+
"detail": "fruit type is not valid",
|
| 347 |
+
"count": train_generated.__len__(),
|
| 348 |
+
}
|
| 349 |
+
fruit_odds=feature.decimal
|
| 350 |
+
if fruit_odds < 0 or fruit_odds > 1:
|
| 351 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 352 |
+
return {
|
| 353 |
+
"result": "Failure",
|
| 354 |
+
"detail": "odds is not valid",
|
| 355 |
+
"count": train_generated.__len__(),
|
| 356 |
+
}
|
| 357 |
+
tmp = {
|
| 358 |
+
command: {
|
| 359 |
+
"result": [
|
| 360 |
+
x_add,
|
| 361 |
+
x_fruit,
|
| 362 |
+
x_odd,
|
| 363 |
+
{x_fruit: fruit_type, x_args: fruit_odds},
|
| 364 |
+
],
|
| 365 |
+
"desc": [
|
| 366 |
+
f"set the odds of some type of fruit",
|
| 367 |
+
],
|
| 368 |
+
},
|
| 369 |
+
}
|
| 370 |
+
train_generated |= tmp
|
| 371 |
+
response.status_code = status.HTTP_200_OK
|
| 372 |
+
return {
|
| 373 |
+
"result": "OK",
|
| 374 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 375 |
+
"please execute submit after adding all",
|
| 376 |
+
"count": train_generated.__len__(),
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
@router.post("/set_timer",
|
| 383 |
+
description="""set duration of timer, unit is second""")
|
| 384 |
+
def set_timer_duration(feature: FeatureOneIntegerArg, response: Response):
|
| 385 |
+
global train_generated
|
| 386 |
+
command = feature.command.strip()
|
| 387 |
+
if command in train_generated:
|
| 388 |
+
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
| 389 |
+
return {
|
| 390 |
+
"result": "Failure",
|
| 391 |
+
"detail": "command already exists in memory",
|
| 392 |
+
"count": train_generated.__len__(),
|
| 393 |
+
}
|
| 394 |
+
tmp = {
|
| 395 |
+
command: {
|
| 396 |
+
"result": [
|
| 397 |
+
x_set,
|
| 398 |
+
x_timer,
|
| 399 |
+
{x_args: feature.integer},
|
| 400 |
+
],
|
| 401 |
+
"desc": [
|
| 402 |
+
"set duration of timer",
|
| 403 |
+
],
|
| 404 |
+
},
|
| 405 |
+
}
|
| 406 |
+
train_generated |= tmp
|
| 407 |
+
response.status_code = status.HTTP_200_OK
|
| 408 |
+
return {
|
| 409 |
+
"result": "OK",
|
| 410 |
+
"detail": f"command [{command}] has been added to memory, " +
|
| 411 |
+
"please execute submit after adding all",
|
| 412 |
+
"count": train_generated.__len__(),
|
| 413 |
+
}
|
main.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
import uvicorn
|
| 3 |
+
from app import watermelon
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
app.include_router(watermelon.router)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
def root():
|
| 12 |
+
return {"detail": "AI Command Patcher"}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if __name__ == "__main__":
|
| 16 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
huggingface_hub
|
| 3 |
+
uvicorn[standard]
|
| 4 |
+
passlib
|
| 5 |
+
bcrypt
|
| 6 |
+
python-jose
|
| 7 |
+
git+ssh://github.com/east-and-west-magic/pgsoft.git@tag-2024-01-11-a
|