{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing imscdr_ac_in___8.png...\n", "Status Code: 500\n", "Response Text: {\"detail\":\"conv2d() received an invalid combination of arguments - got (str, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:\\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)\\n didn't match because some of the arguments have invalid types: (!str!, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (int, int)!, int)\\n * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)\\n didn't match because some of the arguments have invalid types: (!str!, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (int, int)!, int)\\n\"}\n", "Finished processing imscdr_ac_in___8.png in 10.38 seconds\n", "Processing imscdr_ac_in___9.png...\n", "Status Code: 500\n", "Response Text: \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " Hugging Face – The AI community building the future.\n", " \n", " \n", "\n", "\n", "\n", "
\n", " \n", "
\n", "

500

\n", "

Sorry, there is an error on our side.

\n", "
\n", "
\n", "\n", "\n", "\n", "Finished processing imscdr_ac_in___9.png in 11.36 seconds\n", "{}\n" ] } ], "source": [ "import os\n", "import requests\n", "import base64\n", "from PIL import Image\n", "import time\n", "\n", "api_url = \"https://banao-tech-omniapi.hf.space/process_image\"\n", "\n", "def process_image_folder(input_folder, output_folder, box_threshold=0.03, iou_threshold=0.1):\n", " if not os.path.exists(output_folder):\n", " os.makedirs(output_folder)\n", "\n", " results = {}\n", " image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.jpg', '.jpeg', '.png'))]\n", "\n", " for image_file in image_files:\n", " image_path = os.path.join(input_folder, image_file)\n", " print(f\"Processing {image_file}...\")\n", "\n", " start_time = time.time()\n", "\n", " try:\n", " with open(image_path, \"rb\") as img_file:\n", " files = {\"image_file\": img_file}\n", " data = {\n", " \"box_threshold\": box_threshold,\n", " \"iou_threshold\": iou_threshold,\n", " }\n", " response = requests.post(api_url, files=files, data=data)\n", " print(\"Status Code:\", response.status_code)\n", " print(\"Response Text:\", response.text)\n", "\n", " if response.status_code == 200:\n", " result = response.json()\n", " results[image_file] = {\n", " \"parsed_content_list\": result.get(\"parsed_content_list\", []),\n", " \"label_coordinates\": result.get(\"label_coordinates\", []),\n", " }\n", " output_image_data = base64.b64decode(result[\"image\"])\n", " output_image_path = os.path.join(output_folder, f\"labeled_{image_file}\")\n", " with open(output_image_path, \"wb\") as img_file:\n", " img_file.write(output_image_data)\n", "\n", " except Exception as e:\n", " print(f\"Error processing {image_file}: {e}\")\n", "\n", " end_time = time.time()\n", " print(f\"Finished processing {image_file} in {end_time - start_time:.2f} seconds\")\n", "\n", " return results\n", "\n", "# # Example call\n", "res = process_image_folder('test', 'output_folder')\n", "print(res)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "audit", "language": "python", "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.10" } }, "nbformat": 4, "nbformat_minor": 2 }