Spaces:
Runtime error
Runtime error
Benjamin Bossan
commited on
Commit
·
f4f6aba
1
Parent(s):
7a64f2c
Add more docstrings
Browse files
app.py
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from start import start_input_form
|
|
|
|
| 1 |
+
"""The app.py used with streamlit
|
| 2 |
+
|
| 3 |
+
This ties together the different parts of the app.
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
from start import start_input_form
|
edit.py
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import reprlib
|
|
|
|
| 1 |
+
"""The editing page of the app
|
| 2 |
+
|
| 3 |
+
This is the meat of the application. On the sidebar, the content of the model
|
| 4 |
+
card is displayed in the form of editable fields. On the right side, the
|
| 5 |
+
rendered model card is shown.
|
| 6 |
+
|
| 7 |
+
In the side bar, users can:
|
| 8 |
+
|
| 9 |
+
- edit the title and content of existing sections
|
| 10 |
+
- delete sections
|
| 11 |
+
- add new sections below the current section
|
| 12 |
+
- add new figures below the current section
|
| 13 |
+
|
| 14 |
+
Moreover, each action results in a "task" that is tracked in the task state. A
|
| 15 |
+
task has a "do" and an "undo" method. This allows us to provide "undo" and
|
| 16 |
+
"redo" features to the app, making it easier for users to experiment and deal
|
| 17 |
+
with errors. The "reset" button undoes all the tasks, leading back to the
|
| 18 |
+
initial model card.
|
| 19 |
+
|
| 20 |
+
When the user is finished, there is a "save" button that downloads the model
|
| 21 |
+
card. They can also click "delete" to start over again, leading them to the
|
| 22 |
+
start page.
|
| 23 |
+
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
from __future__ import annotations
|
| 28 |
|
| 29 |
import reprlib
|
start.py
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import glob
|
| 2 |
import io
|
| 3 |
import os
|
|
|
|
| 1 |
+
"""Start page of the app
|
| 2 |
+
|
| 3 |
+
This page is used to initialize a model card that is either:
|
| 4 |
+
|
| 5 |
+
1. based on the skops template
|
| 6 |
+
2. empty
|
| 7 |
+
3. loads an existing model card
|
| 8 |
+
|
| 9 |
+
Optionally, users can add a model file, data, requirements, and choose a task.
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
import glob
|
| 14 |
import io
|
| 15 |
import os
|
tasks.py
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from pathlib import Path
|
|
@@ -9,9 +14,7 @@ from streamlit.runtime.uploaded_file_manager import UploadedFile
|
|
| 9 |
|
| 10 |
|
| 11 |
class Task:
|
| 12 |
-
|
| 13 |
-
self.model_card = model_card
|
| 14 |
-
|
| 15 |
def do(self) -> None:
|
| 16 |
raise NotImplementedError
|
| 17 |
|
|
@@ -20,6 +23,7 @@ class Task:
|
|
| 20 |
|
| 21 |
|
| 22 |
class TaskState:
|
|
|
|
| 23 |
def __init__(self) -> None:
|
| 24 |
self.done_list: list[Task] = []
|
| 25 |
self.undone_list: list[Task] = []
|
|
@@ -51,6 +55,7 @@ class TaskState:
|
|
| 51 |
|
| 52 |
|
| 53 |
class AddSectionTask(Task):
|
|
|
|
| 54 |
def __init__(
|
| 55 |
self,
|
| 56 |
model_card: card.Card,
|
|
@@ -72,6 +77,7 @@ class AddSectionTask(Task):
|
|
| 72 |
|
| 73 |
|
| 74 |
class AddFigureTask(Task):
|
|
|
|
| 75 |
def __init__(
|
| 76 |
self,
|
| 77 |
model_card: card.Card,
|
|
@@ -94,6 +100,12 @@ class AddFigureTask(Task):
|
|
| 94 |
|
| 95 |
|
| 96 |
class DeleteSectionTask(Task):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
def __init__(
|
| 98 |
self,
|
| 99 |
model_card: card.Card,
|
|
@@ -110,6 +122,7 @@ class DeleteSectionTask(Task):
|
|
| 110 |
|
| 111 |
|
| 112 |
class UpdateSectionTask(Task):
|
|
|
|
| 113 |
def __init__(
|
| 114 |
self,
|
| 115 |
model_card: card.Card,
|
|
@@ -140,6 +153,7 @@ class UpdateSectionTask(Task):
|
|
| 140 |
|
| 141 |
|
| 142 |
class UpdateFigureTask(Task):
|
|
|
|
| 143 |
def __init__(
|
| 144 |
self,
|
| 145 |
model_card: card.Card,
|
|
|
|
| 1 |
+
"""Functionality around tasks
|
| 2 |
+
|
| 3 |
+
Tasks are used to implement "undo" and "redo" functionality.
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
from __future__ import annotations
|
| 7 |
|
| 8 |
from pathlib import Path
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class Task:
|
| 17 |
+
"""(Abstract) base class for tasks"""
|
|
|
|
|
|
|
| 18 |
def do(self) -> None:
|
| 19 |
raise NotImplementedError
|
| 20 |
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
class TaskState:
|
| 26 |
+
"""Tracking the state of tasks"""
|
| 27 |
def __init__(self) -> None:
|
| 28 |
self.done_list: list[Task] = []
|
| 29 |
self.undone_list: list[Task] = []
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
class AddSectionTask(Task):
|
| 58 |
+
"""Add a new text section"""
|
| 59 |
def __init__(
|
| 60 |
self,
|
| 61 |
model_card: card.Card,
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
class AddFigureTask(Task):
|
| 80 |
+
"""Add a new figure section"""
|
| 81 |
def __init__(
|
| 82 |
self,
|
| 83 |
model_card: card.Card,
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
class DeleteSectionTask(Task):
|
| 103 |
+
"""Delete a section
|
| 104 |
+
|
| 105 |
+
The section is not completely removed from the underlying data structure,
|
| 106 |
+
but only turned invisible.
|
| 107 |
+
|
| 108 |
+
"""
|
| 109 |
def __init__(
|
| 110 |
self,
|
| 111 |
model_card: card.Card,
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
class UpdateSectionTask(Task):
|
| 125 |
+
"""Change the title or content of a text section"""
|
| 126 |
def __init__(
|
| 127 |
self,
|
| 128 |
model_card: card.Card,
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
class UpdateFigureTask(Task):
|
| 156 |
+
"""Change the title or image of a figure section"""
|
| 157 |
def __init__(
|
| 158 |
self,
|
| 159 |
model_card: card.Card,
|
utils.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import base64
|
|
|
|
| 1 |
+
"""Utility functions for the app"""
|
| 2 |
+
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import base64
|