Spaces:
Sleeping
Sleeping
Update ImageNet.py
Browse files- ImageNet.py +28 -27
ImageNet.py
CHANGED
|
@@ -1,27 +1,28 @@
|
|
| 1 |
-
from CV2Net import cv2net
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import pandas as pd
|
| 4 |
-
|
| 5 |
-
def image2net(img_file,api_key):
|
| 6 |
-
try:
|
| 7 |
-
if isinstance(img_file, list) and len(img_file) > 1:
|
| 8 |
-
df_list = []
|
| 9 |
-
for i in img_file:
|
| 10 |
-
df_list.append(cv2net(i,api_key))
|
| 11 |
-
|
| 12 |
-
else:
|
| 13 |
-
df_list = [cv2net(img_file,api_key)]
|
| 14 |
-
|
| 15 |
-
except Exception:
|
| 16 |
-
gr.Info("The model is overloaded. Please try again later!")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
| 1 |
+
from CV2Net import cv2net
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
def image2net(img_file,api_key):
|
| 6 |
+
try:
|
| 7 |
+
if isinstance(img_file, list) and len(img_file) > 1:
|
| 8 |
+
df_list = []
|
| 9 |
+
for i in img_file:
|
| 10 |
+
df_list.append(cv2net(i,api_key))
|
| 11 |
+
|
| 12 |
+
else:
|
| 13 |
+
df_list = [cv2net(img_file,api_key)]
|
| 14 |
+
|
| 15 |
+
except Exception:
|
| 16 |
+
gr.Info("The model is overloaded. Please try again later!")
|
| 17 |
+
return None, None
|
| 18 |
+
|
| 19 |
+
# Filter out None values before concatenating
|
| 20 |
+
valid_dfs = [df for df in df_list if df is not None]
|
| 21 |
+
|
| 22 |
+
if valid_dfs:
|
| 23 |
+
df = pd.concat(valid_dfs)
|
| 24 |
+
file_path = "network_data.csv"
|
| 25 |
+
df.to_csv(file_path, index=False)
|
| 26 |
+
return df, file_path
|
| 27 |
+
else:
|
| 28 |
+
return None, None
|