Commit
·
1b1427d
1
Parent(s):
4014f2e
feat: adicionar índice inicial ao retorno de métricas e corrigir a ordem dos resultados
Browse files
app.py
CHANGED
@@ -93,7 +93,7 @@ class MetricsStorage:
|
|
93 |
(limit,),
|
94 |
)
|
95 |
results = cursor.fetchall()
|
96 |
-
return [r[0] for r in results]
|
97 |
|
98 |
def get_total_inferences(self):
|
99 |
"""Get the total number of inferences recorded"""
|
@@ -134,10 +134,17 @@ class SignatureDetector:
|
|
134 |
|
135 |
def get_metrics(self):
|
136 |
"""Get current metrics from storage"""
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
return {
|
138 |
-
"times":
|
139 |
-
"total_inferences":
|
140 |
-
"avg_time":
|
|
|
141 |
}
|
142 |
|
143 |
def load_initial_metrics(self):
|
@@ -149,9 +156,13 @@ class SignatureDetector:
|
|
149 |
|
150 |
# Criar plots data
|
151 |
hist_data = pd.DataFrame({"Tempo (ms)": metrics["times"]})
|
|
|
|
|
|
|
|
|
152 |
line_data = pd.DataFrame(
|
153 |
{
|
154 |
-
"Inferência":
|
155 |
"Tempo (ms)": metrics["times"],
|
156 |
"Média": [metrics["avg_time"]] * len(metrics["times"]),
|
157 |
}
|
@@ -161,7 +172,7 @@ class SignatureDetector:
|
|
161 |
hist_fig, line_fig = self.create_plots(hist_data, line_data)
|
162 |
|
163 |
return (
|
164 |
-
None,
|
165 |
f"Total de Inferências: {metrics['total_inferences']}",
|
166 |
hist_fig,
|
167 |
line_fig,
|
@@ -219,6 +230,10 @@ class SignatureDetector:
|
|
219 |
hist_fig.tight_layout()
|
220 |
line_fig.tight_layout()
|
221 |
|
|
|
|
|
|
|
|
|
222 |
return hist_fig, line_fig
|
223 |
|
224 |
def preprocess(self, img):
|
@@ -381,9 +396,13 @@ def create_gradio_interface():
|
|
381 |
|
382 |
# Create plots data
|
383 |
hist_data = pd.DataFrame({"Tempo (ms)": metrics["times"]})
|
|
|
|
|
|
|
|
|
384 |
line_data = pd.DataFrame(
|
385 |
{
|
386 |
-
"Inferência":
|
387 |
"Tempo (ms)": metrics["times"],
|
388 |
"Média": [metrics["avg_time"]] * len(metrics["times"]),
|
389 |
}
|
|
|
93 |
(limit,),
|
94 |
)
|
95 |
results = cursor.fetchall()
|
96 |
+
return [r[0] for r in reversed(results)]
|
97 |
|
98 |
def get_total_inferences(self):
|
99 |
"""Get the total number of inferences recorded"""
|
|
|
134 |
|
135 |
def get_metrics(self):
|
136 |
"""Get current metrics from storage"""
|
137 |
+
times = self.metrics_storage.get_recent_metrics()
|
138 |
+
total = self.metrics_storage.get_total_inferences()
|
139 |
+
avg = self.metrics_storage.get_average_time()
|
140 |
+
|
141 |
+
start_index = max(0, total - len(times))
|
142 |
+
|
143 |
return {
|
144 |
+
"times": times,
|
145 |
+
"total_inferences": total,
|
146 |
+
"avg_time": avg,
|
147 |
+
"start_index": start_index, # Adicionar índice inicial
|
148 |
}
|
149 |
|
150 |
def load_initial_metrics(self):
|
|
|
156 |
|
157 |
# Criar plots data
|
158 |
hist_data = pd.DataFrame({"Tempo (ms)": metrics["times"]})
|
159 |
+
indices = range(
|
160 |
+
metrics["start_index"], metrics["start_index"] + len(metrics["times"])
|
161 |
+
)
|
162 |
+
|
163 |
line_data = pd.DataFrame(
|
164 |
{
|
165 |
+
"Inferência": indices,
|
166 |
"Tempo (ms)": metrics["times"],
|
167 |
"Média": [metrics["avg_time"]] * len(metrics["times"]),
|
168 |
}
|
|
|
172 |
hist_fig, line_fig = self.create_plots(hist_data, line_data)
|
173 |
|
174 |
return (
|
175 |
+
None,
|
176 |
f"Total de Inferências: {metrics['total_inferences']}",
|
177 |
hist_fig,
|
178 |
line_fig,
|
|
|
230 |
hist_fig.tight_layout()
|
231 |
line_fig.tight_layout()
|
232 |
|
233 |
+
# Fechar as figuras para liberar memória
|
234 |
+
plt.close(hist_fig)
|
235 |
+
plt.close(line_fig)
|
236 |
+
|
237 |
return hist_fig, line_fig
|
238 |
|
239 |
def preprocess(self, img):
|
|
|
396 |
|
397 |
# Create plots data
|
398 |
hist_data = pd.DataFrame({"Tempo (ms)": metrics["times"]})
|
399 |
+
indices = range(
|
400 |
+
metrics["start_index"], metrics["start_index"] + len(metrics["times"])
|
401 |
+
)
|
402 |
+
|
403 |
line_data = pd.DataFrame(
|
404 |
{
|
405 |
+
"Inferência": indices,
|
406 |
"Tempo (ms)": metrics["times"],
|
407 |
"Média": [metrics["avg_time"]] * len(metrics["times"]),
|
408 |
}
|