Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,10 @@ status = pn.pane.Markdown("")
|
|
27 |
|
28 |
# Leaderboard display
|
29 |
leaderboard = pn.pane.DataFrame(pd.DataFrame(), width=600)
|
|
|
30 |
|
|
|
|
|
31 |
def submit_file(event):
|
32 |
if file_input.value is None:
|
33 |
status.object = "⚠️ Please upload a .zip file before submitting."
|
@@ -64,141 +67,3 @@ app = pn.Column(
|
|
64 |
)
|
65 |
|
66 |
app.servable()
|
67 |
-
|
68 |
-
|
69 |
-
# ICON_URLS = {
|
70 |
-
# "brand-github": "https://github.com/holoviz/panel",
|
71 |
-
# "brand-twitter": "https://twitter.com/Panel_Org",
|
72 |
-
# "brand-linkedin": "https://www.linkedin.com/company/panel-org",
|
73 |
-
# "message-circle": "https://discourse.holoviz.org/",
|
74 |
-
# "brand-discord": "https://discord.gg/AXRHnJU6sP",
|
75 |
-
# }
|
76 |
-
|
77 |
-
|
78 |
-
# async def random_url(_):
|
79 |
-
# pet = random.choice(["cat", "dog"])
|
80 |
-
# api_url = f"https://api.the{pet}api.com/v1/images/search"
|
81 |
-
# async with aiohttp.ClientSession() as session:
|
82 |
-
# async with session.get(api_url) as resp:
|
83 |
-
# return (await resp.json())[0]["url"]
|
84 |
-
|
85 |
-
|
86 |
-
# @pn.cache
|
87 |
-
# def load_processor_model(
|
88 |
-
# processor_name: str, model_name: str
|
89 |
-
# ) -> Tuple[CLIPProcessor, CLIPModel]:
|
90 |
-
# processor = CLIPProcessor.from_pretrained(processor_name)
|
91 |
-
# model = CLIPModel.from_pretrained(model_name)
|
92 |
-
# return processor, model
|
93 |
-
|
94 |
-
|
95 |
-
# async def open_image_url(image_url: str) -> Image:
|
96 |
-
# async with aiohttp.ClientSession() as session:
|
97 |
-
# async with session.get(image_url) as resp:
|
98 |
-
# return Image.open(io.BytesIO(await resp.read()))
|
99 |
-
|
100 |
-
|
101 |
-
# def get_similarity_scores(class_items: List[str], image: Image) -> List[float]:
|
102 |
-
# processor, model = load_processor_model(
|
103 |
-
# "openai/clip-vit-base-patch32", "openai/clip-vit-base-patch32"
|
104 |
-
# )
|
105 |
-
# inputs = processor(
|
106 |
-
# text=class_items,
|
107 |
-
# images=[image],
|
108 |
-
# return_tensors="pt", # pytorch tensors
|
109 |
-
# )
|
110 |
-
# outputs = model(**inputs)
|
111 |
-
# logits_per_image = outputs.logits_per_image
|
112 |
-
# class_likelihoods = logits_per_image.softmax(dim=1).detach().numpy()
|
113 |
-
# return class_likelihoods[0]
|
114 |
-
|
115 |
-
|
116 |
-
# async def process_inputs(class_names: List[str], image_url: str):
|
117 |
-
# """
|
118 |
-
# High level function that takes in the user inputs and returns the
|
119 |
-
# classification results as panel objects.
|
120 |
-
# """
|
121 |
-
# try:
|
122 |
-
# main.disabled = True
|
123 |
-
# if not image_url:
|
124 |
-
# yield "##### ⚠️ Provide an image URL"
|
125 |
-
# return
|
126 |
-
|
127 |
-
# yield "##### ⚙ Fetching image and running model..."
|
128 |
-
# try:
|
129 |
-
# pil_img = await open_image_url(image_url)
|
130 |
-
# img = pn.pane.Image(pil_img, height=400, align="center")
|
131 |
-
# except Exception as e:
|
132 |
-
# yield f"##### 😔 Something went wrong, please try a different URL!"
|
133 |
-
# return
|
134 |
-
|
135 |
-
# class_items = class_names.split(",")
|
136 |
-
# class_likelihoods = get_similarity_scores(class_items, pil_img)
|
137 |
-
|
138 |
-
# # build the results column
|
139 |
-
# results = pn.Column("##### 🎉 Here are the results!", img)
|
140 |
-
|
141 |
-
# for class_item, class_likelihood in zip(class_items, class_likelihoods):
|
142 |
-
# row_label = pn.widgets.StaticText(
|
143 |
-
# name=class_item.strip(), value=f"{class_likelihood:.2%}", align="center"
|
144 |
-
# )
|
145 |
-
# row_bar = pn.indicators.Progress(
|
146 |
-
# value=int(class_likelihood * 100),
|
147 |
-
# sizing_mode="stretch_width",
|
148 |
-
# bar_color="secondary",
|
149 |
-
# margin=(0, 10),
|
150 |
-
# design=pn.theme.Material,
|
151 |
-
# )
|
152 |
-
# results.append(pn.Column(row_label, row_bar))
|
153 |
-
# yield results
|
154 |
-
# finally:
|
155 |
-
# main.disabled = False
|
156 |
-
|
157 |
-
|
158 |
-
# # create widgets
|
159 |
-
# randomize_url = pn.widgets.Button(name="Randomize URL", align="end")
|
160 |
-
|
161 |
-
# image_url = pn.widgets.TextInput(
|
162 |
-
# name="Image URL to classify",
|
163 |
-
# value=pn.bind(random_url, randomize_url),
|
164 |
-
# )
|
165 |
-
# class_names = pn.widgets.TextInput(
|
166 |
-
# name="Comma separated class names",
|
167 |
-
# placeholder="Enter possible class names, e.g. cat, dog",
|
168 |
-
# value="cat, dog, parrot",
|
169 |
-
# )
|
170 |
-
|
171 |
-
# input_widgets = pn.Column(
|
172 |
-
# "##### 😊 Click randomize or paste a URL to start classifying!",
|
173 |
-
# pn.Row(image_url, randomize_url),
|
174 |
-
# class_names,
|
175 |
-
# )
|
176 |
-
|
177 |
-
# # add interactivity
|
178 |
-
# interactive_result = pn.panel(
|
179 |
-
# pn.bind(process_inputs, image_url=image_url, class_names=class_names),
|
180 |
-
# height=600,
|
181 |
-
# )
|
182 |
-
|
183 |
-
# # add footer
|
184 |
-
# footer_row = pn.Row(pn.Spacer(), align="center")
|
185 |
-
# for icon, url in ICON_URLS.items():
|
186 |
-
# href_button = pn.widgets.Button(icon=icon, width=35, height=35)
|
187 |
-
# href_button.js_on_click(code=f"window.open('{url}')")
|
188 |
-
# footer_row.append(href_button)
|
189 |
-
# footer_row.append(pn.Spacer())
|
190 |
-
|
191 |
-
# # create dashboard
|
192 |
-
# main = pn.WidgetBox(
|
193 |
-
# input_widgets,
|
194 |
-
# interactive_result,
|
195 |
-
# footer_row,
|
196 |
-
# )
|
197 |
-
|
198 |
-
# title = "Panel Demo - Image Classification"
|
199 |
-
# pn.template.BootstrapTemplate(
|
200 |
-
# title=title,
|
201 |
-
# main=main,
|
202 |
-
# main_max_width="min(50%, 698px)",
|
203 |
-
# header_background="#F08080",
|
204 |
-
# ).servable(title=title)
|
|
|
27 |
|
28 |
# Leaderboard display
|
29 |
leaderboard = pn.pane.DataFrame(pd.DataFrame(), width=600)
|
30 |
+
import tempfile
|
31 |
|
32 |
+
temp_dir = tempfile.gettempdir()
|
33 |
+
submission_path = os.path.join(temp_dir, filename)
|
34 |
def submit_file(event):
|
35 |
if file_input.value is None:
|
36 |
status.object = "⚠️ Please upload a .zip file before submitting."
|
|
|
67 |
)
|
68 |
|
69 |
app.servable()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|