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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Processing imscdr_ac_in___8.png...\n",
|
13 |
+
"Status Code: 500\n",
|
14 |
+
"Response Text: {\"detail\":\"BaseModel.predict() got an unexpected keyword argument 'source'\"}\n",
|
15 |
+
"Finished processing imscdr_ac_in___8.png in 43.56 seconds\n",
|
16 |
+
"Processing imscdr_ac_in___9.png...\n",
|
17 |
+
"Status Code: 500\n",
|
18 |
+
"Response Text: <!DOCTYPE html>\n",
|
19 |
+
"<html class=\"\">\n",
|
20 |
+
"<head>\n",
|
21 |
+
" <meta charset=\"utf-8\"/>\n",
|
22 |
+
" <meta\n",
|
23 |
+
" name=\"viewport\"\n",
|
24 |
+
" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"\n",
|
25 |
+
" />\n",
|
26 |
+
" <meta\n",
|
27 |
+
" name=\"description\"\n",
|
28 |
+
" content=\"We’re on a journey to advance and democratize artificial intelligence through open source and open science.\"\n",
|
29 |
+
" />\n",
|
30 |
+
" <meta property=\"fb:app_id\" content=\"1321688464574422\"/>\n",
|
31 |
+
" <meta name=\"twitter:card\" content=\"summary_large_image\"/>\n",
|
32 |
+
" <meta name=\"twitter:site\" content=\"@huggingface\"/>\n",
|
33 |
+
" <meta\n",
|
34 |
+
" property=\"og:title\"\n",
|
35 |
+
" content=\"Hugging Face – The AI community building the future.\"\n",
|
36 |
+
" />\n",
|
37 |
+
" <meta property=\"og:type\" content=\"website\"/>\n",
|
38 |
+
"\n",
|
39 |
+
" <title>Hugging Face – The AI community building the future.</title>\n",
|
40 |
+
" <style>\n",
|
41 |
+
" body {\n",
|
42 |
+
" margin: 0;\n",
|
43 |
+
" }\n",
|
44 |
+
"\n",
|
45 |
+
" main {\n",
|
46 |
+
" background-color: white;\n",
|
47 |
+
" min-height: 100vh;\n",
|
48 |
+
" padding: 7rem 1rem 8rem 1rem;\n",
|
49 |
+
" text-align: center;\n",
|
50 |
+
" font-family: Source Sans Pro, ui-sans-serif, system-ui, -apple-system,\n",
|
51 |
+
" BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans,\n",
|
52 |
+
" sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol,\n",
|
53 |
+
" Noto Color Emoji;\n",
|
54 |
+
" }\n",
|
55 |
+
"\n",
|
56 |
+
" img {\n",
|
57 |
+
" width: 6rem;\n",
|
58 |
+
" height: 6rem;\n",
|
59 |
+
" margin: 0 auto 1rem;\n",
|
60 |
+
" }\n",
|
61 |
+
"\n",
|
62 |
+
" h1 {\n",
|
63 |
+
" font-size: 3.75rem;\n",
|
64 |
+
" line-height: 1;\n",
|
65 |
+
" color: rgba(31, 41, 55, 1);\n",
|
66 |
+
" font-weight: 700;\n",
|
67 |
+
" box-sizing: border-box;\n",
|
68 |
+
" margin: 0 auto;\n",
|
69 |
+
" }\n",
|
70 |
+
"\n",
|
71 |
+
" p {\n",
|
72 |
+
" color: rgba(107, 114, 128, 1);\n",
|
73 |
+
" font-size: 1.125rem;\n",
|
74 |
+
" line-height: 1.75rem;\n",
|
75 |
+
" max-width: 28rem;\n",
|
76 |
+
" box-sizing: border-box;\n",
|
77 |
+
" margin: 0 auto;\n",
|
78 |
+
" }\n",
|
79 |
+
"\n",
|
80 |
+
" .dark main {\n",
|
81 |
+
" background-color: rgb(11, 15, 25);\n",
|
82 |
+
" }\n",
|
83 |
+
"\n",
|
84 |
+
" .dark h1 {\n",
|
85 |
+
" color: rgb(209, 213, 219);\n",
|
86 |
+
" }\n",
|
87 |
+
"\n",
|
88 |
+
" .dark p {\n",
|
89 |
+
" color: rgb(156, 163, 175);\n",
|
90 |
+
" }\n",
|
91 |
+
" </style>\n",
|
92 |
+
" <script>\n",
|
93 |
+
" // On page load or when changing themes, best to add inline in `head` to avoid FOUC\n",
|
94 |
+
" const key = \"_tb_global_settings\";\n",
|
95 |
+
" let theme = window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n",
|
96 |
+
" ? \"dark\"\n",
|
97 |
+
" : \"light\";\n",
|
98 |
+
" try {\n",
|
99 |
+
" const storageTheme = JSON.parse(window.localStorage.getItem(key)).theme;\n",
|
100 |
+
" if (storageTheme) {\n",
|
101 |
+
" theme = storageTheme === \"dark\" ? \"dark\" : \"light\";\n",
|
102 |
+
" }\n",
|
103 |
+
" } catch (e) {\n",
|
104 |
+
" }\n",
|
105 |
+
" if (theme === \"dark\") {\n",
|
106 |
+
" document.documentElement.classList.add(\"dark\");\n",
|
107 |
+
" } else {\n",
|
108 |
+
" document.documentElement.classList.remove(\"dark\");\n",
|
109 |
+
" }\n",
|
110 |
+
" </script>\n",
|
111 |
+
"</head>\n",
|
112 |
+
"\n",
|
113 |
+
"<body>\n",
|
114 |
+
"<main>\n",
|
115 |
+
" <img\n",
|
116 |
+
" src=\"https://huggingface.co/front/assets/huggingface_logo.svg\"\n",
|
117 |
+
" alt=\"\"\n",
|
118 |
+
" />\n",
|
119 |
+
" <div>\n",
|
120 |
+
" <h1>500</h1>\n",
|
121 |
+
" <p>Sorry, there is an error on our side.</p>\n",
|
122 |
+
" </div>\n",
|
123 |
+
"</main>\n",
|
124 |
+
"</body>\n",
|
125 |
+
"</html>\n",
|
126 |
+
"\n",
|
127 |
+
"Finished processing imscdr_ac_in___9.png in 9.98 seconds\n",
|
128 |
+
"{}\n"
|
129 |
+
]
|
130 |
+
}
|
131 |
+
],
|
132 |
+
"source": [
|
133 |
+
"import os\n",
|
134 |
+
"import requests\n",
|
135 |
+
"import base64\n",
|
136 |
+
"from PIL import Image\n",
|
137 |
+
"import time\n",
|
138 |
+
"\n",
|
139 |
+
"api_url = \"https://banao-tech-omniapi.hf.space/process_image\"\n",
|
140 |
+
"\n",
|
141 |
+
"def process_image_folder(input_folder, output_folder, box_threshold=0.03, iou_threshold=0.1):\n",
|
142 |
+
" if not os.path.exists(output_folder):\n",
|
143 |
+
" os.makedirs(output_folder)\n",
|
144 |
+
"\n",
|
145 |
+
" results = {}\n",
|
146 |
+
" image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.jpg', '.jpeg', '.png'))]\n",
|
147 |
+
"\n",
|
148 |
+
" for image_file in image_files:\n",
|
149 |
+
" image_path = os.path.join(input_folder, image_file)\n",
|
150 |
+
" print(f\"Processing {image_file}...\")\n",
|
151 |
+
"\n",
|
152 |
+
" start_time = time.time()\n",
|
153 |
+
"\n",
|
154 |
+
" try:\n",
|
155 |
+
" with open(image_path, \"rb\") as img_file:\n",
|
156 |
+
" files = {\"image_file\": img_file}\n",
|
157 |
+
" data = {\n",
|
158 |
+
" \"box_threshold\": box_threshold,\n",
|
159 |
+
" \"iou_threshold\": iou_threshold,\n",
|
160 |
+
" }\n",
|
161 |
+
" response = requests.post(api_url, files=files, data=data)\n",
|
162 |
+
" print(\"Status Code:\", response.status_code)\n",
|
163 |
+
" print(\"Response Text:\", response.text)\n",
|
164 |
+
"\n",
|
165 |
+
" if response.status_code == 200:\n",
|
166 |
+
" result = response.json()\n",
|
167 |
+
" results[image_file] = {\n",
|
168 |
+
" \"parsed_content_list\": result.get(\"parsed_content_list\", []),\n",
|
169 |
+
" \"label_coordinates\": result.get(\"label_coordinates\", []),\n",
|
170 |
+
" }\n",
|
171 |
+
" output_image_data = base64.b64decode(result[\"image\"])\n",
|
172 |
+
" output_image_path = os.path.join(output_folder, f\"labeled_{image_file}\")\n",
|
173 |
+
" with open(output_image_path, \"wb\") as img_file:\n",
|
174 |
+
" img_file.write(output_image_data)\n",
|
175 |
+
"\n",
|
176 |
+
" except Exception as e:\n",
|
177 |
+
" print(f\"Error processing {image_file}: {e}\")\n",
|
178 |
+
"\n",
|
179 |
+
" end_time = time.time()\n",
|
180 |
+
" print(f\"Finished processing {image_file} in {end_time - start_time:.2f} seconds\")\n",
|
181 |
+
"\n",
|
182 |
+
" return results\n",
|
183 |
+
"\n",
|
184 |
+
"# # Example call\n",
|
185 |
+
"res = process_image_folder('test', 'output_folder')\n",
|
186 |
+
"print(res)"
|
187 |
+
]
|
188 |
+
},
|
189 |
+
{
|
190 |
+
"cell_type": "code",
|
191 |
+
"execution_count": 2,
|
192 |
+
"metadata": {},
|
193 |
+
"outputs": [
|
194 |
+
{
|
195 |
+
"data": {
|
196 |
+
"text/plain": [
|
197 |
+
"{}"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
"execution_count": 2,
|
201 |
+
"metadata": {},
|
202 |
+
"output_type": "execute_result"
|
203 |
+
}
|
204 |
+
],
|
205 |
+
"source": [
|
206 |
+
"res"
|
207 |
+
]
|
208 |
+
},
|
209 |
+
{
|
210 |
+
"cell_type": "code",
|
211 |
+
"execution_count": null,
|
212 |
+
"metadata": {},
|
213 |
+
"outputs": [],
|
214 |
+
"source": []
|
215 |
+
}
|
216 |
+
],
|
217 |
+
"metadata": {
|
218 |
+
"kernelspec": {
|
219 |
+
"display_name": "audit",
|
220 |
+
"language": "python",
|
221 |
+
"name": "python3"
|
222 |
+
},
|
223 |
+
"language_info": {
|
224 |
+
"codemirror_mode": {
|
225 |
+
"name": "ipython",
|
226 |
+
"version": 3
|
227 |
+
},
|
228 |
+
"file_extension": ".py",
|
229 |
+
"mimetype": "text/x-python",
|
230 |
+
"name": "python",
|
231 |
+
"nbconvert_exporter": "python",
|
232 |
+
"pygments_lexer": "ipython3",
|
233 |
+
"version": "3.11.10"
|
234 |
+
}
|
235 |
+
},
|
236 |
+
"nbformat": 4,
|
237 |
+
"nbformat_minor": 2
|
238 |
+
}
|
test/imscdr_ac_in___8.png
ADDED
![]() |
test/imscdr_ac_in___9.png
ADDED
![]() |