Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,16 +18,24 @@ model = TimeSeriesTransformerForPrediction.from_pretrained(
|
|
18 |
|
19 |
def prever_vendas(historico):
|
20 |
# Converter entrada em tensor
|
21 |
-
historico = [float(x) for x in historico.split(",") if x.strip()]
|
22 |
if len(historico) != config.context_length:
|
23 |
-
raise ValueError(f"
|
24 |
|
25 |
-
# Formatar dados
|
26 |
inputs = torch.tensor(historico).unsqueeze(0)
|
27 |
|
|
|
|
|
|
|
|
|
28 |
# Gerar previs茫o
|
29 |
with torch.no_grad():
|
30 |
-
outputs = model(
|
|
|
|
|
|
|
|
|
31 |
forecast = outputs.mean.squeeze().tolist()
|
32 |
|
33 |
return np.round(forecast, 2)
|
@@ -39,7 +47,8 @@ iface = gr.Interface(
|
|
39 |
outputs=gr.Textbox(label=f"Previs茫o para os Pr贸ximos {config.prediction_length} Meses"),
|
40 |
examples=[
|
41 |
["140,155,160,145,150,165,170,160,175,160,155,170"], # 12 meses
|
42 |
-
]
|
|
|
43 |
)
|
44 |
|
45 |
iface.launch()
|
|
|
18 |
|
19 |
def prever_vendas(historico):
|
20 |
# Converter entrada em tensor
|
21 |
+
historico = [float(x) for x in historico.split(",") if x.strip()]
|
22 |
if len(historico) != config.context_length:
|
23 |
+
raise ValueError(f"Hist贸rico deve ter {config.context_length} valores.")
|
24 |
|
25 |
+
# Formatar dados
|
26 |
inputs = torch.tensor(historico).unsqueeze(0)
|
27 |
|
28 |
+
# Adicionar par芒metros ausentes (valores dummy para exemplo)
|
29 |
+
past_time_features = torch.zeros(1, config.context_length, 1) # Ex: timestamps normalizados
|
30 |
+
past_observed_mask = torch.ones(1, config.context_length) # Todos os dados observados
|
31 |
+
|
32 |
# Gerar previs茫o
|
33 |
with torch.no_grad():
|
34 |
+
outputs = model(
|
35 |
+
inputs,
|
36 |
+
past_time_features=past_time_features,
|
37 |
+
past_observed_mask=past_observed_mask
|
38 |
+
)
|
39 |
forecast = outputs.mean.squeeze().tolist()
|
40 |
|
41 |
return np.round(forecast, 2)
|
|
|
47 |
outputs=gr.Textbox(label=f"Previs茫o para os Pr贸ximos {config.prediction_length} Meses"),
|
48 |
examples=[
|
49 |
["140,155,160,145,150,165,170,160,175,160,155,170"], # 12 meses
|
50 |
+
],
|
51 |
+
cache_examples=False # Desativar cache para evitar erro de arquivo
|
52 |
)
|
53 |
|
54 |
iface.launch()
|