Delete Untitled0.ipynb
Browse files- Untitled0.ipynb +0 -1
Untitled0.ipynb
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":12008,"status":"ok","timestamp":1706445806053,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"},"user_tz":-540},"id":"D1uRmN-FUV5j","outputId":"16a860c1-7535-4048-d173-f960cc679093"},"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (4.16.0)\n","Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n","Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n","Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio) (0.109.0)\n","Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.3.1)\n","Requirement already satisfied: gradio-client==0.8.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.8.1)\n","Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from gradio) (0.26.0)\n","Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.20.3)\n","Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.1.1)\n","Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.3)\n","Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.4)\n","Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n","Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.23.5)\n","Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.9.12)\n","Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2)\n","Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.5.3)\n","Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n","Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.5.3)\n","Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n","Requirement already satisfied: python-multipart in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.6)\n","Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n","Requirement already satisfied: ruff>=0.1.7 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.1.14)\n","Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n","Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n","Requirement already satisfied: typer[all]<1.0,>=0.9 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.9.0)\n","Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.9.0)\n","Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.27.0)\n","Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.1->gradio) (2023.6.0)\n","Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.1->gradio) (11.0.3)\n","Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n","Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n","Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n","Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.13.1)\n","Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n","Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.1)\n","Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.0)\n","Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n","Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.47.2)\n","Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n","Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.1)\n","Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n","Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n","Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.6.0)\n","Requirement already satisfied: pydantic-core==2.14.6 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.14.6)\n","Requirement already satisfied: click<9.0.0,>=7.1.1 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (8.1.7)\n","Requirement already satisfied: colorama<0.5.0,>=0.4.3 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n","Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n","Requirement already satisfied: rich<14.0.0,>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (13.7.0)\n","Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n","Requirement already satisfied: starlette<0.36.0,>=0.35.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.35.1)\n","Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.7.1)\n","Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (2023.11.17)\n","Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.0.2)\n","Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.6)\n","Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.3.0)\n","Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n","Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n","Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.32.1)\n","Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.17.1)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n","Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n","Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.16.1)\n","Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->gradio) (1.2.0)\n","Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n","Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (2.0.7)\n","Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n"]}],"source":["!pip install gradio"]},{"cell_type":"code","source":["!pip install Pillow"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"K066wO5xfUTH","executionInfo":{"status":"ok","timestamp":1706452419978,"user_tz":-540,"elapsed":8668,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"}},"outputId":"aeda66ae-0c02-4f44-e49f-f5e09f6efc4c"},"execution_count":65,"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (9.4.0)\n"]}]},{"cell_type":"code","source":["import gradio as gr\n","from keras.models import load_model # TensorFlow is required for Keras to work\n","from PIL import Image, ImageOps # Install pillow instead of PIL\n","import numpy as np\n","\n","def image_classifier(image):\n","\n"," # Disable scientific notation for clarity\n"," np.set_printoptions(suppress=True)\n","\n"," # Load the model\n"," model = load_model(\"/content/drive/My Drive/chishiki/keras_model.h5\", compile=False)\n","\n"," # Load the labels\n"," class_names = open(\"/content/drive/My Drive/chishiki/labels.txt\", \"r\").readlines()\n","\n"," # Create the array of the right shape to feed into the keras model\n"," # The 'length' or number of images you can put into the array is\n"," # determined by the first position in the shape tuple, in this case 1\n"," data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)\n","\n"," # Replace this with the path to your image\n"," #image = Image.open(\"/content/drive/My Drive/chishiki/979.png\").convert(\"RGB\")\n"," image = Image.fromarray(image.astype(\"uint8\"),\"RGB\")\n","\n"," # resizing the image to be at least 224x224 and then cropping from the center\n"," size = (224, 224)\n"," image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)\n","\n"," # turn the image into a numpy array\n"," image_array = np.asarray(image)\n","\n"," # Normalize the image\n"," normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1\n","\n"," # Load the image into the array\n"," data[0] = normalized_image_array\n","\n"," # Predicts the model\n"," prediction = model.predict(data)\n"," index = np.argmax(prediction)\n"," class_name = class_names[index]\n"," confidence_score = prediction[0][index]\n","\n"," # Print prediction and confidence score\n"," result = class_name[2:]\n"," if index == 2:\n"," text1 ='δΊθ§γ§γ'\n"," elif index == 0:\n"," text1 ='θ¦ζγ§γ'\n"," elif index == 1:\n"," text1 ='ζε©γ§γ'\n"," ans = result + text1\n"," return ans\n","\n","iface = gr.Interface(\n"," fn=image_classifier,\n"," inputs=gr.Image(), # η»εγε
₯εγ¨γγ¦εγεγγΎγγ\n"," outputs=\"text\" # η΅ζγγγγΉγγ§θ‘¨η€ΊγγΎγγ\n",")\n","\n","iface.launch()\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":626},"id":"90VsNIntA06u","executionInfo":{"status":"ok","timestamp":1706453544600,"user_tz":-540,"elapsed":7769,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"}},"outputId":"33bc03a2-734c-41bd-baa6-0e2200850c76"},"execution_count":72,"outputs":[{"output_type":"stream","name":"stdout","text":["Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n","\n","Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n","Running on public URL: https://b09d13b015af2aa186.gradio.live\n","\n","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"]},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["<div><iframe src=\"https://b09d13b015af2aa186.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"]},"metadata":{}},{"output_type":"execute_result","data":{"text/plain":[]},"metadata":{},"execution_count":72}]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"id":"fZTp19Ho4GcK","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1706442385084,"user_tz":-540,"elapsed":4549,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"}},"outputId":"06ae9ed8-35f4-43ee-8434-658d8f23ae2b"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},{"cell_type":"code","execution_count":59,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":5117,"status":"ok","timestamp":1706451692269,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"},"user_tz":-540},"id":"quXIphz3UbSv","outputId":"457e9900-e203-412a-d9e7-b91290a087e5"},"outputs":[{"output_type":"stream","name":"stdout","text":["1/1 [==============================] - 1s 990ms/step\n","Class: γΏγ\n","\n","Confidence Score: 0.9757186\n"]}],"source":["from keras.models import load_model # TensorFlow is required for Keras to work\n","from PIL import Image, ImageOps # Install pillow instead of PIL\n","import numpy as np\n","\n","\n","\n","# Disable scientific notation for clarity\n","np.set_printoptions(suppress=True)\n","\n","# Load the model\n","model = load_model(\"/content/drive/My Drive/chishiki/keras_model.h5\", compile=False)\n","\n","# Load the labels\n","class_names = open(\"/content/drive/My Drive/chishiki/labels.txt\", \"r\").readlines()\n","\n","# Create the array of the right shape to feed into the keras model\n","# The 'length' or number of images you can put into the array is\n","# determined by the first position in the shape tuple, in this case 1\n","data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)\n","\n","# Replace this with the path to your image\n","image = Image.open(\"/content/drive/My Drive/chishiki/933.png\").convert(\"RGB\")\n","\n","# resizing the image to be at least 224x224 and then cropping from the center\n","size = (224, 224)\n","image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)\n","\n","# turn the image into a numpy array\n","image_array = np.asarray(image)\n","\n","# Normalize the image\n","normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1\n","\n","# Load the image into the array\n","data[0] = normalized_image_array\n","\n","# Predicts the model\n","prediction = model.predict(data)\n","index = np.argmax(prediction)\n","class_name = class_names[index]\n","confidence_score = prediction[0][index]\n","\n","# Print prediction and confidence score\n","print(\"Class:\", class_name[2:])\n","print(\"Confidence Score:\", confidence_score)\n"]},{"cell_type":"code","source":["import streamlit as st\n","from keras.models import load_model\n","from PIL import Image, ImageOps\n","import numpy as np\n","\n","# Load the model\n","model = load_model(\"/content/drive/My Drive/chishiki/keras_model.h5\", compile=False)\n","\n","# Load the labels\n","class_names = open(\"/content/drive/My Drive/chishiki/labels.txt\", \"r\").readlines()\n","\n","# Create the array of the right shape to feed into the keras model\n","data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)\n","\n","# Define a function for prediction\n","def predict_image(image):\n"," # Open and preprocess the image\n"," image = Image.open(image).convert(\"RGB\")\n"," size = (224, 224)\n"," image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)\n"," image_array = np.asarray(image)\n"," normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1\n"," data[0] = normalized_image_array\n","\n"," # Make prediction\n"," prediction = model.predict(data)\n"," index = np.argmax(prediction)\n"," class_name = class_names[index][2:]\n"," confidence_score = prediction[0][index]\n","\n"," # Return a formatted string with the prediction result\n"," result_text = f\"Class: {class_name}, Confidence Score: {confidence_score:.2f}\"\n"," return result_text\n","\n","# Streamlit app\n","st.title(\"Image Classification\")\n","uploaded_file = st.file_uploader(\"Choose an image...\", type=\"jpg\")\n","\n","if uploaded_file is not None:\n"," # Display the image\n"," image = Image.open(uploaded_file)\n"," st.image(image, caption=\"Uploaded Image\", use_column_width=True)\n","\n"," # Make prediction\n"," result = predict_image(uploaded_file)\n"," st.write(result)\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_9Gfxcq-_WyY","executionInfo":{"status":"ok","timestamp":1706444454414,"user_tz":-540,"elapsed":15020,"user":{"displayName":"ε·η°η’§","userId":"04564060522052257536"}},"outputId":"499a13aa-4f1f-42e1-9f5b-1bd9aff3fb60"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stderr","text":["2024-01-28 12:20:53.669 \n"," \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n"," command:\n","\n"," streamlit run /usr/local/lib/python3.10/dist-packages/colab_kernel_launcher.py [ARGUMENTS]\n"]}]}],"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNMaisCoc6wY0Ev2mWjAi7T"},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.4"}},"nbformat":4,"nbformat_minor":0}
|
|
|
|
|
|