Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
# Install necessary packages (only for local environment)
|
2 |
-
# !pip install pandas gradio transformers torch
|
3 |
-
|
4 |
import pandas as pd
|
5 |
import gradio as gr
|
6 |
import torch
|
@@ -16,19 +13,29 @@ def load_model():
|
|
16 |
model, tokenizer = load_model()
|
17 |
|
18 |
def forecast(csv_file):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
24 |
-
|
|
|
25 |
with torch.no_grad():
|
26 |
-
predictions = model.generate(**inputs, max_length=200)
|
27 |
-
|
|
|
28 |
forecast_text = tokenizer.decode(predictions[0], skip_special_tokens=True)
|
|
|
|
|
29 |
forecasts = pd.DataFrame({'forecast': [forecast_text]})
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
33 |
# Gradio Interface
|
34 |
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
import gradio as gr
|
3 |
import torch
|
|
|
13 |
model, tokenizer = load_model()
|
14 |
|
15 |
def forecast(csv_file):
|
16 |
+
# Read CSV with correct delimiter and parse timestamps
|
17 |
+
data = pd.read_csv(csv_file.name, sep=";", parse_dates=['timestamp_column'])
|
18 |
+
|
19 |
+
# Ensure timestamp format is correct
|
20 |
+
data['timestamp_column'] = pd.to_datetime(data['timestamp_column'], format="%Y%m%d %H:%M")
|
21 |
+
|
22 |
+
# Convert data to a structured format for the model
|
23 |
+
input_text = "\n".join([f"{row['timestamp_column']}: {row['Inbound']}" for _, row in data.iterrows()])
|
24 |
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
25 |
+
|
26 |
+
# Generate forecast
|
27 |
with torch.no_grad():
|
28 |
+
predictions = model.generate(**inputs, max_length=200, num_return_sequences=1)
|
29 |
+
|
30 |
+
# Decode the generated forecast
|
31 |
forecast_text = tokenizer.decode(predictions[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
# Save forecast result to CSV
|
34 |
forecasts = pd.DataFrame({'forecast': [forecast_text]})
|
35 |
+
output_file = "forecasts.csv"
|
36 |
+
forecasts.to_csv(output_file, index=False)
|
37 |
+
|
38 |
+
return output_file
|
39 |
|
40 |
# Gradio Interface
|
41 |
iface = gr.Interface(
|