Spaces:
Build error
Build error
Kim Adams commited on
Commit ·
53b3fd3
1
Parent(s): 3cb704e
reverting draw to smaller
Browse files- create_games/data/game_ideas.json +5 -5
- home_view/__pycache__/ui_home.cpython-311.pyc +0 -0
- home_view/ui_home.py +5 -7
- pytorch_model.bin +3 -0
- requirements.txt +3 -1
- sketch/__pycache__/sketch.cpython-311.pyc +0 -0
- sketch/sketch.py +29 -6
create_games/data/game_ideas.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
[
|
| 2 |
{
|
| 3 |
-
"Name": "
|
| 4 |
-
"Description": "A drawing-based game to
|
| 5 |
-
"Rules": "1. Each player takes turns
|
| 6 |
-
"Tips": "Can you draw a
|
| 7 |
-
"InitialQuestion": "Draw a
|
| 8 |
}
|
| 9 |
]
|
|
|
|
| 1 |
[
|
| 2 |
{
|
| 3 |
+
"Name": "Blazing Sunburn",
|
| 4 |
+
"Description": "A drawing-based game where players try to draw a humorous sunburn-related scenario.",
|
| 5 |
+
"Rules": "1. Each player takes turns to draw a sunburn-related scene or situation.\n2. Players have limited time to complete their drawing.\n3. The drawings should aim to be creative and humorous.",
|
| 6 |
+
"Tips": "Can you draw a person with funny shaped sunburns? How about an unconventional object getting sunburnt?",
|
| 7 |
+
"InitialQuestion": "Draw a person with a sunburn that resembles something else."
|
| 8 |
}
|
| 9 |
]
|
home_view/__pycache__/ui_home.cpython-311.pyc
CHANGED
|
Binary files a/home_view/__pycache__/ui_home.cpython-311.pyc and b/home_view/__pycache__/ui_home.cpython-311.pyc differ
|
|
|
home_view/ui_home.py
CHANGED
|
@@ -144,20 +144,17 @@ with gr.Blocks() as ui:
|
|
| 144 |
buildPlayLabel= gr.Markdown(constants.BUILDPLAY_LABEL, container=False)
|
| 145 |
with gr.Column():
|
| 146 |
directionsLabel= gr.Markdown(constants.DIRECTIONS_LABEL, container=False)
|
| 147 |
-
directions= gr.Markdown(constants.DIRECTIONS, container=False)
|
| 148 |
-
|
| 149 |
playersCB = gr.CheckboxGroup ([], label=constants.PLAYERS, info=constants.PLAYERS_INFO )
|
| 150 |
gamePlay=gr.Radio(["Draw", "Chat"], label=constants.GAME_TYPE, value="Chat")
|
| 151 |
createBtn = gr.Button(value=constants.CREATE_GAME, variant="primary")
|
| 152 |
-
|
| 153 |
with gr.Column(visible=False) as pGame:
|
| 154 |
with gr.Row():
|
| 155 |
with gr.Column():
|
| 156 |
chatTitle= gr.Markdown ()
|
| 157 |
chatDesc= gr.Markdown ()
|
| 158 |
gameTopic=gr.Markdown()
|
| 159 |
-
players=gr.Markdown()
|
| 160 |
-
|
| 161 |
with gr.Column():
|
| 162 |
rules=gr.Markdown(constants.RULES_LABEL)
|
| 163 |
chatRules=gr.Markdown(constants.GAME_DESC)
|
|
@@ -168,8 +165,9 @@ with gr.Blocks() as ui:
|
|
| 168 |
drawMD=gr.Markdown()
|
| 169 |
with gr.Column(visible=False) as drawGame:
|
| 170 |
with gr.Row():
|
| 171 |
-
sketch=gr.Image(image_mode="L", source="canvas",
|
| 172 |
-
|
|
|
|
| 173 |
label=gr.Label(label="Guesses", show_label=True)
|
| 174 |
resetDrwBtn=gr.Button(value="Reset")
|
| 175 |
with gr.Column(visible=False) as chatGame:
|
|
|
|
| 144 |
buildPlayLabel= gr.Markdown(constants.BUILDPLAY_LABEL, container=False)
|
| 145 |
with gr.Column():
|
| 146 |
directionsLabel= gr.Markdown(constants.DIRECTIONS_LABEL, container=False)
|
| 147 |
+
directions= gr.Markdown(constants.DIRECTIONS, container=False)
|
|
|
|
| 148 |
playersCB = gr.CheckboxGroup ([], label=constants.PLAYERS, info=constants.PLAYERS_INFO )
|
| 149 |
gamePlay=gr.Radio(["Draw", "Chat"], label=constants.GAME_TYPE, value="Chat")
|
| 150 |
createBtn = gr.Button(value=constants.CREATE_GAME, variant="primary")
|
|
|
|
| 151 |
with gr.Column(visible=False) as pGame:
|
| 152 |
with gr.Row():
|
| 153 |
with gr.Column():
|
| 154 |
chatTitle= gr.Markdown ()
|
| 155 |
chatDesc= gr.Markdown ()
|
| 156 |
gameTopic=gr.Markdown()
|
| 157 |
+
players=gr.Markdown()
|
|
|
|
| 158 |
with gr.Column():
|
| 159 |
rules=gr.Markdown(constants.RULES_LABEL)
|
| 160 |
chatRules=gr.Markdown(constants.GAME_DESC)
|
|
|
|
| 165 |
drawMD=gr.Markdown()
|
| 166 |
with gr.Column(visible=False) as drawGame:
|
| 167 |
with gr.Row():
|
| 168 |
+
sketch=gr.Image(image_mode="L", source="canvas",brush_radius=5, type="pil", shape=(120, 120),
|
| 169 |
+
invert_colors=True, interactive=True, label="Sketch",
|
| 170 |
+
show_label=True, show_download_button=False)
|
| 171 |
label=gr.Label(label="Guesses", show_label=True)
|
| 172 |
resetDrwBtn=gr.Button(value="Reset")
|
| 173 |
with gr.Column(visible=False) as chatGame:
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:effb6ea6f1593c09e8247944028ed9c309b5ff1cef82ba38b822bee2ca4d0f3c
|
| 3 |
+
size 1656903
|
requirements.txt
CHANGED
|
@@ -22,4 +22,6 @@ tiktoken==0.4.0
|
|
| 22 |
torch==2.0.1
|
| 23 |
inflect==7.0.0
|
| 24 |
Pillow==10.1.0
|
| 25 |
-
streamlit==1.28.0
|
|
|
|
|
|
|
|
|
| 22 |
torch==2.0.1
|
| 23 |
inflect==7.0.0
|
| 24 |
Pillow==10.1.0
|
| 25 |
+
streamlit==1.28.0
|
| 26 |
+
gdown==4.7.1
|
| 27 |
+
PySocks==1.7.1
|
sketch/__pycache__/sketch.cpython-311.pyc
CHANGED
|
Binary files a/sketch/__pycache__/sketch.cpython-311.pyc and b/sketch/__pycache__/sketch.cpython-311.pyc differ
|
|
|
sketch/sketch.py
CHANGED
|
@@ -3,9 +3,16 @@ from PIL import Image
|
|
| 3 |
import numpy as np
|
| 4 |
from torch import nn
|
| 5 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
model = nn.Sequential(
|
| 11 |
nn.Conv2d(1, 32, 3, padding='same'),
|
|
@@ -22,11 +29,11 @@ model = nn.Sequential(
|
|
| 22 |
nn.ReLU(),
|
| 23 |
nn.Linear(256, len(LABELS)),
|
| 24 |
)
|
| 25 |
-
state_dict = torch.load('sketch/pytorch_model.bin',
|
| 26 |
model.load_state_dict(state_dict, strict=False)
|
| 27 |
model.eval()
|
| 28 |
|
| 29 |
-
def Predict(img):
|
| 30 |
if img is None or not img.any():
|
| 31 |
print("img is None or empty")
|
| 32 |
# Handle the error appropriately
|
|
@@ -40,7 +47,6 @@ def Predict(img):
|
|
| 40 |
img_pil = Image.fromarray(img.astype('uint8'))
|
| 41 |
|
| 42 |
# Resize the image
|
| 43 |
-
#img_resized = img_pil.resize((28, 28), Image.ANTIALIAS)
|
| 44 |
img_resized = img_pil.resize((28, 28), Image.LANCZOS)
|
| 45 |
|
| 46 |
# Convert the PIL image back to a NumPy array
|
|
@@ -57,5 +63,22 @@ def Predict(img):
|
|
| 57 |
values, indices = torch.topk(probabilities, 5)
|
| 58 |
confidences = {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
| 59 |
|
| 60 |
-
return confidences
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from torch import nn
|
| 5 |
from pathlib import Path
|
| 6 |
+
import gdown
|
| 7 |
+
#PATH="sketch/class_names.txt"
|
| 8 |
+
#LABELS = Path(PATH).read_text().splitlines()
|
| 9 |
|
| 10 |
+
|
| 11 |
+
url = 'https://drive.google.com/uc?id=1dsk2JNZLRDjC-0J4wIQX_FcVurPaXaAZ'
|
| 12 |
+
output = 'pytorch_model.bin'
|
| 13 |
+
gdown.download(url, output, quiet=False)
|
| 14 |
+
|
| 15 |
+
LABELS = Path('sketch/class_names.txt').read_text().splitlines()
|
| 16 |
|
| 17 |
model = nn.Sequential(
|
| 18 |
nn.Conv2d(1, 32, 3, padding='same'),
|
|
|
|
| 29 |
nn.ReLU(),
|
| 30 |
nn.Linear(256, len(LABELS)),
|
| 31 |
)
|
| 32 |
+
state_dict = torch.load('sketch/pytorch_model.bin',map_location='cpu')
|
| 33 |
model.load_state_dict(state_dict, strict=False)
|
| 34 |
model.eval()
|
| 35 |
|
| 36 |
+
'''def Predict(img):
|
| 37 |
if img is None or not img.any():
|
| 38 |
print("img is None or empty")
|
| 39 |
# Handle the error appropriately
|
|
|
|
| 47 |
img_pil = Image.fromarray(img.astype('uint8'))
|
| 48 |
|
| 49 |
# Resize the image
|
|
|
|
| 50 |
img_resized = img_pil.resize((28, 28), Image.LANCZOS)
|
| 51 |
|
| 52 |
# Convert the PIL image back to a NumPy array
|
|
|
|
| 63 |
values, indices = torch.topk(probabilities, 5)
|
| 64 |
confidences = {LABELS[i]: v.item() for i, v in zip(indices, values)}
|
| 65 |
|
| 66 |
+
return confidences'''
|
| 67 |
+
|
| 68 |
+
def Predict(im):
|
| 69 |
+
if im is None:
|
| 70 |
+
print("img is None or empty")
|
| 71 |
+
# Handle the error appropriately
|
| 72 |
+
return
|
| 73 |
+
im = np.asarray(im.resize((28, 28)))
|
| 74 |
+
|
| 75 |
+
x = torch.tensor(im, dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255.
|
| 76 |
+
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
out = model(x)
|
| 79 |
+
|
| 80 |
+
probabilities = torch.nn.functional.softmax(out[0], dim=0)
|
| 81 |
+
|
| 82 |
+
values, indices = torch.topk(probabilities, 5)
|
| 83 |
|
| 84 |
+
return {LABELS[i]: v.item() for i, v in zip(indices, values)}
|