Spaces:
Build error
Build error
Upload 6 files
Browse files- .gitattributes +1 -0
- ChessImageClassification.ipynb +0 -0
- chess-deploy.py +43 -0
- chess-predict-model_transferlearning.keras +3 -0
- screenshots/VGG16Epoch.png +0 -0
- screenshots/XCeption4Epoch.png +0 -0
- test.ipynb +265 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
chess-predict-model_transferlearning.keras filter=lfs diff=lfs merge=lfs -text
|
ChessImageClassification.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
chess-deploy.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
model_path = "chess-predict-model_transferlearning.keras"
|
| 8 |
+
model = tf.keras.models.load_model(model_path)
|
| 9 |
+
|
| 10 |
+
# Define the core prediction function
|
| 11 |
+
def predict_figure(image):
|
| 12 |
+
# Preprocess image
|
| 13 |
+
print(type(image))
|
| 14 |
+
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
| 15 |
+
image = image.resize((150, 150)) #resize the image to 150x150
|
| 16 |
+
image = np.array(image)
|
| 17 |
+
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
| 18 |
+
|
| 19 |
+
# Predict
|
| 20 |
+
prediction = model.predict(image)
|
| 21 |
+
|
| 22 |
+
# Apply softmax to get probabilities for each class
|
| 23 |
+
prediction = tf.nn.softmax(prediction)
|
| 24 |
+
|
| 25 |
+
# Create a dictionary with the probabilities for each Pokemon
|
| 26 |
+
bishop = np.round(float(prediction[0][0]), 2)
|
| 27 |
+
king = np.round(float(prediction[0][1]), 2)
|
| 28 |
+
knight = np.round(float(prediction[0][2]), 2)
|
| 29 |
+
pawn = np.round(float(prediction[0][3]), 2)
|
| 30 |
+
queen = np.round(float(prediction[0][4]), 2)
|
| 31 |
+
rook = np.round(float(prediction[0][5]), 2)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
return {'Bishop': bishop, 'King': king, 'Knight': knight, 'Pawn': pawn, 'Queen': queen, 'Rook': rook}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
input_image = gr.Image()
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=predict_figure,
|
| 40 |
+
inputs=input_image,
|
| 41 |
+
outputs=gr.Label(),
|
| 42 |
+
description="A simple mlp classification model for image classification using the mnist dataset.")
|
| 43 |
+
iface.launch(share=True)
|
chess-predict-model_transferlearning.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:025a0cd4b778288e110564ad4ff67dd52557e4528c93ea424243219df5529946
|
| 3 |
+
size 176716087
|
screenshots/VGG16Epoch.png
ADDED
|
screenshots/XCeption4Epoch.png
ADDED
|
test.ipynb
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [
|
| 8 |
+
{
|
| 9 |
+
"name": "stdout",
|
| 10 |
+
"output_type": "stream",
|
| 11 |
+
"text": [
|
| 12 |
+
"Requirement already satisfied: gradio in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (4.27.0)\n",
|
| 13 |
+
"Requirement already satisfied: fastapi in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.110.2)\n",
|
| 14 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (10.1.0)\n",
|
| 15 |
+
"Requirement already satisfied: huggingface-hub>=0.19.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.22.2)\n",
|
| 16 |
+
"Requirement already satisfied: matplotlib~=3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (3.7.2)\n",
|
| 17 |
+
"Requirement already satisfied: httpx>=0.24.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.27.0)\n",
|
| 18 |
+
"Requirement already satisfied: jinja2<4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (3.1.2)\n",
|
| 19 |
+
"Requirement already satisfied: ruff>=0.2.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.4.1)\n",
|
| 20 |
+
"Requirement already satisfied: gradio-client==0.15.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.15.1)\n",
|
| 21 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (6.4.0)\n",
|
| 22 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.29.0)\n",
|
| 23 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (4.11.0)\n",
|
| 24 |
+
"Requirement already satisfied: markupsafe~=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (2.1.3)\n",
|
| 25 |
+
"Requirement already satisfied: semantic-version~=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (2.10.0)\n",
|
| 26 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (6.0.1)\n",
|
| 27 |
+
"Requirement already satisfied: urllib3~=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (2.0.7)\n",
|
| 28 |
+
"Requirement already satisfied: altair<6.0,>=4.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (5.3.0)\n",
|
| 29 |
+
"Requirement already satisfied: python-multipart>=0.0.9 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.0.9)\n",
|
| 30 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.12.3)\n",
|
| 31 |
+
"Requirement already satisfied: tomlkit==0.12.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.12.0)\n",
|
| 32 |
+
"Requirement already satisfied: numpy~=1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (1.24.3)\n",
|
| 33 |
+
"Requirement already satisfied: ffmpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.3.2)\n",
|
| 34 |
+
"Requirement already satisfied: orjson~=3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (3.10.1)\n",
|
| 35 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (23.2.1)\n",
|
| 36 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (2.0.3)\n",
|
| 37 |
+
"Requirement already satisfied: pydantic>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (2.7.0)\n",
|
| 38 |
+
"Requirement already satisfied: packaging in /Users/matis/Library/Python/3.10/lib/python/site-packages (from gradio) (23.2)\n",
|
| 39 |
+
"Requirement already satisfied: pydub in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio) (0.25.1)\n",
|
| 40 |
+
"Requirement already satisfied: websockets<12.0,>=10.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio-client==0.15.1->gradio) (11.0.3)\n",
|
| 41 |
+
"Requirement already satisfied: fsspec in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from gradio-client==0.15.1->gradio) (2024.3.1)\n",
|
| 42 |
+
"Requirement already satisfied: jsonschema>=3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from altair<6.0,>=4.2.0->gradio) (4.19.1)\n",
|
| 43 |
+
"Requirement already satisfied: toolz in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n",
|
| 44 |
+
"Requirement already satisfied: httpcore==1.* in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n",
|
| 45 |
+
"Requirement already satisfied: idna in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (3.4)\n",
|
| 46 |
+
"Requirement already satisfied: anyio in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (4.0.0)\n",
|
| 47 |
+
"Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (2023.7.22)\n",
|
| 48 |
+
"Requirement already satisfied: sniffio in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (1.3.0)\n",
|
| 49 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
|
| 50 |
+
"Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
|
| 51 |
+
"Requirement already satisfied: filelock in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (3.13.4)\n",
|
| 52 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.1)\n",
|
| 53 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
| 54 |
+
"Requirement already satisfied: fonttools>=4.22.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (4.43.1)\n",
|
| 55 |
+
"Requirement already satisfied: contourpy>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.1.1)\n",
|
| 56 |
+
"Requirement already satisfied: python-dateutil>=2.7 in /Users/matis/Library/Python/3.10/lib/python/site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
| 57 |
+
"Requirement already satisfied: cycler>=0.10 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
|
| 58 |
+
"Requirement already satisfied: pyparsing<3.1,>=2.3.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (3.0.9)\n",
|
| 59 |
+
"Requirement already satisfied: tzdata>=2022.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2023.3)\n",
|
| 60 |
+
"Requirement already satisfied: pytz>=2020.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
|
| 61 |
+
"Requirement already satisfied: pydantic-core==2.18.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (2.18.1)\n",
|
| 62 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
| 63 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
| 64 |
+
"Requirement already satisfied: rich>=10.11.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
|
| 65 |
+
"Requirement already satisfied: click>=8.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
|
| 66 |
+
"Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from fastapi->gradio) (0.37.2)\n",
|
| 67 |
+
"Requirement already satisfied: referencing>=0.28.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.30.2)\n",
|
| 68 |
+
"Requirement already satisfied: rpds-py>=0.7.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.10.6)\n",
|
| 69 |
+
"Requirement already satisfied: attrs>=22.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.1.0)\n",
|
| 70 |
+
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.7.1)\n",
|
| 71 |
+
"Requirement already satisfied: six>=1.5 in /Users/matis/Library/Python/3.10/lib/python/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
| 72 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/matis/Library/Python/3.10/lib/python/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.16.1)\n",
|
| 73 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
|
| 74 |
+
"Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/matis/Library/Python/3.10/lib/python/site-packages (from anyio->httpx>=0.24.1->gradio) (1.1.3)\n",
|
| 75 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.0)\n",
|
| 76 |
+
"Requirement already satisfied: mdurl~=0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
|
| 77 |
+
"--- Logging error ---\n",
|
| 78 |
+
"Traceback (most recent call last):\n",
|
| 79 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/utils/logging.py\", line 177, in emit\n",
|
| 80 |
+
" self.console.print(renderable, overflow=\"ignore\", crop=False, style=style)\n",
|
| 81 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_vendor/rich/console.py\", line 1673, in print\n",
|
| 82 |
+
" extend(render(renderable, render_options))\n",
|
| 83 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_vendor/rich/console.py\", line 1305, in render\n",
|
| 84 |
+
" for render_output in iter_render:\n",
|
| 85 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/utils/logging.py\", line 134, in __rich_console__\n",
|
| 86 |
+
" for line in lines:\n",
|
| 87 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_vendor/rich/segment.py\", line 249, in split_lines\n",
|
| 88 |
+
" for segment in segments:\n",
|
| 89 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_vendor/rich/console.py\", line 1283, in render\n",
|
| 90 |
+
" renderable = rich_cast(renderable)\n",
|
| 91 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_vendor/rich/protocol.py\", line 36, in rich_cast\n",
|
| 92 |
+
" renderable = cast_method()\n",
|
| 93 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py\", line 130, in __rich__\n",
|
| 94 |
+
" pip_cmd = get_best_invocation_for_this_pip()\n",
|
| 95 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/utils/entrypoints.py\", line 58, in get_best_invocation_for_this_pip\n",
|
| 96 |
+
" if found_executable and os.path.samefile(\n",
|
| 97 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/genericpath.py\", line 101, in samefile\n",
|
| 98 |
+
" s2 = os.stat(f2)\n",
|
| 99 |
+
"FileNotFoundError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/3.10/bin/pip'\n",
|
| 100 |
+
"Call stack:\n",
|
| 101 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 196, in _run_module_as_main\n",
|
| 102 |
+
" return _run_code(code, main_globals, None,\n",
|
| 103 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n",
|
| 104 |
+
" exec(code, run_globals)\n",
|
| 105 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/__main__.py\", line 31, in <module>\n",
|
| 106 |
+
" sys.exit(_main())\n",
|
| 107 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/cli/main.py\", line 70, in main\n",
|
| 108 |
+
" return command.main(cmd_args)\n",
|
| 109 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/cli/base_command.py\", line 101, in main\n",
|
| 110 |
+
" return self._main(args)\n",
|
| 111 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/cli/base_command.py\", line 223, in _main\n",
|
| 112 |
+
" self.handle_pip_version_check(options)\n",
|
| 113 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/cli/req_command.py\", line 190, in handle_pip_version_check\n",
|
| 114 |
+
" pip_self_version_check(session, options)\n",
|
| 115 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py\", line 236, in pip_self_version_check\n",
|
| 116 |
+
" logger.warning(\"[present-rich] %s\", upgrade_prompt)\n",
|
| 117 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py\", line 1489, in warning\n",
|
| 118 |
+
" self._log(WARNING, msg, args, **kwargs)\n",
|
| 119 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py\", line 1624, in _log\n",
|
| 120 |
+
" self.handle(record)\n",
|
| 121 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py\", line 1634, in handle\n",
|
| 122 |
+
" self.callHandlers(record)\n",
|
| 123 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py\", line 1696, in callHandlers\n",
|
| 124 |
+
" hdlr.handle(record)\n",
|
| 125 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/logging/__init__.py\", line 968, in handle\n",
|
| 126 |
+
" self.emit(record)\n",
|
| 127 |
+
" File \"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip/_internal/utils/logging.py\", line 179, in emit\n",
|
| 128 |
+
" self.handleError(record)\n",
|
| 129 |
+
"Message: '[present-rich] %s'\n",
|
| 130 |
+
"Arguments: (UpgradePrompt(old='22.2.2', new='24.0'),)\n",
|
| 131 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
| 132 |
+
]
|
| 133 |
+
}
|
| 134 |
+
],
|
| 135 |
+
"source": [
|
| 136 |
+
"%pip install gradio\n",
|
| 137 |
+
"import gradio as gr\n",
|
| 138 |
+
"import tensorflow as tf\n",
|
| 139 |
+
"import numpy as np\n",
|
| 140 |
+
"from PIL import Image"
|
| 141 |
+
]
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
"cell_type": "code",
|
| 145 |
+
"execution_count": 2,
|
| 146 |
+
"metadata": {},
|
| 147 |
+
"outputs": [],
|
| 148 |
+
"source": [
|
| 149 |
+
"model_path = \"chess-predict-model_transferlearning.keras\"\n",
|
| 150 |
+
"model = tf.keras.models.load_model(model_path)"
|
| 151 |
+
]
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"cell_type": "code",
|
| 155 |
+
"execution_count": 3,
|
| 156 |
+
"metadata": {},
|
| 157 |
+
"outputs": [],
|
| 158 |
+
"source": [
|
| 159 |
+
"# Define the core prediction function\n",
|
| 160 |
+
"def predict_figure(image):\n",
|
| 161 |
+
" # Preprocess image\n",
|
| 162 |
+
" print(type(image))\n",
|
| 163 |
+
" image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image\n",
|
| 164 |
+
" image = image.resize((150, 150)) #resize the image to 150x150\n",
|
| 165 |
+
" image = np.array(image)\n",
|
| 166 |
+
" image = np.expand_dims(image, axis=0) # same as image[None, ...]\n",
|
| 167 |
+
" \n",
|
| 168 |
+
" # Predict\n",
|
| 169 |
+
" prediction = model.predict(image)\n",
|
| 170 |
+
" \n",
|
| 171 |
+
" # Apply softmax to get probabilities for each class\n",
|
| 172 |
+
" prediction = tf.nn.softmax(prediction)\n",
|
| 173 |
+
" \n",
|
| 174 |
+
" # Create a dictionary with the probabilities for each Pokemon\n",
|
| 175 |
+
" bishop = np.round(float(prediction[0][0]), 2)\n",
|
| 176 |
+
" king = np.round(float(prediction[0][1]), 2)\n",
|
| 177 |
+
" knight = np.round(float(prediction[0][2]), 2)\n",
|
| 178 |
+
" pawn = np.round(float(prediction[0][3]), 2)\n",
|
| 179 |
+
" queen = np.round(float(prediction[0][4]), 2)\n",
|
| 180 |
+
" rook = np.round(float(prediction[0][5]), 2)\n",
|
| 181 |
+
"\n",
|
| 182 |
+
" \n",
|
| 183 |
+
" return {'Bishop': bishop, 'King': king, 'Knight': knight, 'Pawn': pawn, 'Queen': queen, 'Rook': rook}"
|
| 184 |
+
]
|
| 185 |
+
},
|
| 186 |
+
{
|
| 187 |
+
"cell_type": "code",
|
| 188 |
+
"execution_count": 4,
|
| 189 |
+
"metadata": {},
|
| 190 |
+
"outputs": [
|
| 191 |
+
{
|
| 192 |
+
"name": "stdout",
|
| 193 |
+
"output_type": "stream",
|
| 194 |
+
"text": [
|
| 195 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 196 |
+
"IMPORTANT: You are using gradio version 4.27.0, however version 4.29.0 is available, please upgrade.\n",
|
| 197 |
+
"--------\n",
|
| 198 |
+
"Running on public URL: https://bec4ecbc6c90453cdb.gradio.live\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
| 201 |
+
]
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"data": {
|
| 205 |
+
"text/html": [
|
| 206 |
+
"<div><iframe src=\"https://bec4ecbc6c90453cdb.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 207 |
+
],
|
| 208 |
+
"text/plain": [
|
| 209 |
+
"<IPython.core.display.HTML object>"
|
| 210 |
+
]
|
| 211 |
+
},
|
| 212 |
+
"metadata": {},
|
| 213 |
+
"output_type": "display_data"
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"data": {
|
| 217 |
+
"text/plain": []
|
| 218 |
+
},
|
| 219 |
+
"execution_count": 4,
|
| 220 |
+
"metadata": {},
|
| 221 |
+
"output_type": "execute_result"
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"name": "stdout",
|
| 225 |
+
"output_type": "stream",
|
| 226 |
+
"text": [
|
| 227 |
+
"<class 'numpy.ndarray'>\n",
|
| 228 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 150ms/step\n"
|
| 229 |
+
]
|
| 230 |
+
}
|
| 231 |
+
],
|
| 232 |
+
"source": [
|
| 233 |
+
"# Create the Gradio interface\n",
|
| 234 |
+
"input_image = gr.Image()\n",
|
| 235 |
+
"iface = gr.Interface(\n",
|
| 236 |
+
" fn=predict_figure,\n",
|
| 237 |
+
" inputs=input_image, \n",
|
| 238 |
+
" outputs=gr.Label(),\n",
|
| 239 |
+
" description=\"A simple mlp classification model for image classification using the mnist dataset.\")\n",
|
| 240 |
+
"iface.launch(share=True)"
|
| 241 |
+
]
|
| 242 |
+
}
|
| 243 |
+
],
|
| 244 |
+
"metadata": {
|
| 245 |
+
"kernelspec": {
|
| 246 |
+
"display_name": "Python 3",
|
| 247 |
+
"language": "python",
|
| 248 |
+
"name": "python3"
|
| 249 |
+
},
|
| 250 |
+
"language_info": {
|
| 251 |
+
"codemirror_mode": {
|
| 252 |
+
"name": "ipython",
|
| 253 |
+
"version": 3
|
| 254 |
+
},
|
| 255 |
+
"file_extension": ".py",
|
| 256 |
+
"mimetype": "text/x-python",
|
| 257 |
+
"name": "python",
|
| 258 |
+
"nbconvert_exporter": "python",
|
| 259 |
+
"pygments_lexer": "ipython3",
|
| 260 |
+
"version": "3.10.8"
|
| 261 |
+
}
|
| 262 |
+
},
|
| 263 |
+
"nbformat": 4,
|
| 264 |
+
"nbformat_minor": 2
|
| 265 |
+
}
|