Skip to content

Commit

Permalink
Serval App MVP (#192)
Browse files Browse the repository at this point in the history
* Serval app initial commit
* Update app to use Serval creds.
* Add footnote about IETF tags, link to swagger for more on language codes
* Serval App working MVP compatible with streamlit deployment method
* Also now capable of handling paratext projects and multiple files as well as no target file(s).
* Make fields configurable and move delete to end of updates
* Formatting, gitignore, and poetry
  • Loading branch information
Enkidu93 authored Oct 24, 2023
1 parent 675b42b commit 3ac210c
Show file tree
Hide file tree
Showing 11 changed files with 5,894 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ lib/
.vs
appsettings.user.json
artifacts

.db
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
}
],
"dotnet.defaultSolution": "Serval.sln",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
5 changes: 5 additions & 0 deletions samples/ServalApp/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 120
per-file-ignores = serval_app.py:F821,W605
exclude =
serval_client_module.py
13 changes: 13 additions & 0 deletions samples/ServalApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Running the Serval APP
Before running the app, verify that both `SERVAL_APP_EMAIL_PASSWORD` and `SERVAL_APP_PASSCODE` are appropriately populated.
Then, run:
```
streamlit run serval_app.py
```

### Regenerating the Python Client
When the Serval API is updated, download the "swagger.json" from the swagger endpoint and use the tool [swagger-to](https://pypi.org/project/swagger-to/) to generate a new `serval_client_module.py` using the following command in this directory:
```
swagger_to_py_client.py --swagger_path path/to/swagger.json --outpath serval_client_module.py
```
Note: You may need to delete the authorization-related elements of the "swagger.json" before generating.
43 changes: 43 additions & 0 deletions samples/ServalApp/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import enum

from sqlalchemy import Column, Enum, MetaData, String, create_engine
from sqlalchemy.orm import declarative_base


class State(enum.Enum):
Pending = 0
Active = 1
Completed = 2
Faulted = 3


metadata = MetaData()
Base = declarative_base(metadata=metadata)


class Build(Base):
__tablename__ = "builds"

__mapper_args__ = {"confirm_deleted_rows": False}

build_id = Column("build_id", String, primary_key=True)
engine_id = Column("engine_id", String, primary_key=True)
name = Column("name", String)
email = Column("email", String, nullable=False)
state = Column("state", Enum(State), nullable=False)
corpus_id = Column("corpus_id", String, nullable=False)
client_id = Column("client_id", String, nullable=False)
source_files = Column("source_files", String)
target_files = Column("target_files", String)

def __str__(self):
return f"Build name: {self.name}\nBuild id: {self.build_id}\nClient ID: {self.client_id}\nSource files: \
{self.source_files}\nTarget files: {self.target_files}"

def __repr__(self):
return self.__str__()


def create_db_if_not_exists():
engine = create_engine("sqlite:///builds.db")
metadata.create_all(bind=engine)
1,498 changes: 1,498 additions & 0 deletions samples/ServalApp/poetry.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions samples/ServalApp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "servalapp"
version = "0.1.0"
description = ""
authors = ["Eli Lowry <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.8.1,<3.9.7 || >3.9.7,<4.0"
streamlit = "^1.27.2"
requests = "^2.31.0"
SQLAlchemy = "^2.0.22"

[tool.poetry.group.dev.dependencies]
black = "^23.10.1"
flake8 = "^6.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading

0 comments on commit 3ac210c

Please sign in to comment.