Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,33 @@ import os
|
|
4 |
import csv
|
5 |
import time
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
uploaded_images = {'characters': {}, 'terrain': {}}
|
8 |
|
9 |
def get_image_path(img, name, image_type):
|
@@ -33,16 +60,16 @@ def display_images_from_csv():
|
|
33 |
for row in files_info:
|
34 |
if row[2] == 'characters':
|
35 |
img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
|
36 |
-
st.sidebar.image(img_path, width=100, caption=row[0])
|
37 |
else:
|
38 |
img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
|
39 |
-
st.image(img_path, width=100, caption=row[0])
|
40 |
|
41 |
|
42 |
# Rewrite for gradio
|
43 |
-
image_type = gr.selectbox('Choose image type:', options=['characters', 'terrain'])
|
44 |
-
name = gr.text_input('Enter a name for the image:')
|
45 |
-
uploaded_files = gr.file_uploader('Upload image(s)', type=['png', 'jpg'], accept_multiple_files=True)
|
46 |
|
47 |
|
48 |
|
@@ -54,7 +81,7 @@ for uploaded_file in uploaded_files:
|
|
54 |
uploaded_images[image_type][name].append(bytes_data)
|
55 |
|
56 |
# Rewrite for gradio
|
57 |
-
gr.image(bytes_data, use_column_width=True)
|
58 |
|
59 |
update_csv_file(uploaded_file, name, image_type)
|
60 |
|
@@ -62,15 +89,15 @@ if image_type == 'characters':
|
|
62 |
if uploaded_images['characters']:
|
63 |
|
64 |
# Rewrite for gradio
|
65 |
-
|
66 |
for name, files in uploaded_images['characters'].items():
|
67 |
for file in files:
|
68 |
|
69 |
# Rewrite for gradio
|
70 |
-
gr.sidebar.image(file, width=100, caption=name)
|
71 |
else:
|
72 |
if uploaded_images['terrain']:
|
73 |
-
st.write('**Terrain**')
|
74 |
row = []
|
75 |
for name, files in uploaded_images['terrain'].items():
|
76 |
for file in files:
|
@@ -78,17 +105,17 @@ else:
|
|
78 |
if len(row) == 3:
|
79 |
|
80 |
# Rewrite for gradio
|
81 |
-
gr.image(row, width=100 * 3)
|
82 |
row = []
|
83 |
if row:
|
84 |
|
85 |
# Rewrite for gradio
|
86 |
-
gr.image(row, width=100 * len(row)) # Last row, if not complete
|
87 |
|
88 |
while True:
|
89 |
time.sleep(20)
|
90 |
|
91 |
# Rewrite for gradio
|
92 |
-
gr.empty()
|
93 |
|
94 |
display_images_from_csv()
|
|
|
4 |
import csv
|
5 |
import time
|
6 |
|
7 |
+
|
8 |
+
import requests
|
9 |
+
from PIL import Image
|
10 |
+
from torchvision import transforms
|
11 |
+
|
12 |
+
# Download human-readable labels for ImageNet.
|
13 |
+
response = requests.get("https://git.io/JJkYN")
|
14 |
+
labels = response.text.split("\n")
|
15 |
+
|
16 |
+
def predict(inp):
|
17 |
+
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
18 |
+
with torch.no_grad():
|
19 |
+
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
20 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
21 |
+
return confidences
|
22 |
+
|
23 |
+
import gradio as gr
|
24 |
+
|
25 |
+
gr.Interface(fn=predict,
|
26 |
+
inputs=gr.Image(type="pil"),
|
27 |
+
outputs=gr.Label(num_top_classes=3),
|
28 |
+
examples=["lion.jpg", "cheetah.jpg"]).launch()
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
uploaded_images = {'characters': {}, 'terrain': {}}
|
35 |
|
36 |
def get_image_path(img, name, image_type):
|
|
|
60 |
for row in files_info:
|
61 |
if row[2] == 'characters':
|
62 |
img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
|
63 |
+
#st.sidebar.image(img_path, width=100, caption=row[0])
|
64 |
else:
|
65 |
img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
|
66 |
+
#st.image(img_path, width=100, caption=row[0])
|
67 |
|
68 |
|
69 |
# Rewrite for gradio
|
70 |
+
#image_type = gr.selectbox('Choose image type:', options=['characters', 'terrain'])
|
71 |
+
#name = gr.text_input('Enter a name for the image:')
|
72 |
+
#uploaded_files = gr.file_uploader('Upload image(s)', type=['png', 'jpg'], accept_multiple_files=True)
|
73 |
|
74 |
|
75 |
|
|
|
81 |
uploaded_images[image_type][name].append(bytes_data)
|
82 |
|
83 |
# Rewrite for gradio
|
84 |
+
#gr.image(bytes_data, use_column_width=True)
|
85 |
|
86 |
update_csv_file(uploaded_file, name, image_type)
|
87 |
|
|
|
89 |
if uploaded_images['characters']:
|
90 |
|
91 |
# Rewrite for gradio
|
92 |
+
# gr.sidebar.write('**Characters**')
|
93 |
for name, files in uploaded_images['characters'].items():
|
94 |
for file in files:
|
95 |
|
96 |
# Rewrite for gradio
|
97 |
+
#gr.sidebar.image(file, width=100, caption=name)
|
98 |
else:
|
99 |
if uploaded_images['terrain']:
|
100 |
+
#st.write('**Terrain**')
|
101 |
row = []
|
102 |
for name, files in uploaded_images['terrain'].items():
|
103 |
for file in files:
|
|
|
105 |
if len(row) == 3:
|
106 |
|
107 |
# Rewrite for gradio
|
108 |
+
#gr.image(row, width=100 * 3)
|
109 |
row = []
|
110 |
if row:
|
111 |
|
112 |
# Rewrite for gradio
|
113 |
+
#gr.image(row, width=100 * len(row)) # Last row, if not complete
|
114 |
|
115 |
while True:
|
116 |
time.sleep(20)
|
117 |
|
118 |
# Rewrite for gradio
|
119 |
+
#gr.empty()
|
120 |
|
121 |
display_images_from_csv()
|