La til transformers og torch
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
-
from transformers import TimeSeriesTransformerForPrediction
|
| 2 |
-
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
import
|
| 5 |
-
from prophet import Prophet
|
| 6 |
|
| 7 |
-
#
|
| 8 |
url = "https://data.ssb.no/api/v0/no/table/11000"
|
|
|
|
|
|
|
| 9 |
query = {
|
| 10 |
"query": [
|
| 11 |
{"code": "Region", "selection": {"filter": "item", "values": ["0301"]}}, # Oslo
|
|
@@ -13,25 +12,20 @@ query = {
|
|
| 13 |
],
|
| 14 |
"response": {"format": "json-stat2"}
|
| 15 |
}
|
| 16 |
-
response = requests.post(url, json=query)
|
| 17 |
-
data = response.json()
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
df["year"] = pd.to_datetime(df["year"])
|
| 22 |
-
df["population"] = df["population"].astype(int)
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
model = Prophet()
|
| 27 |
-
model.fit(df)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
import json
|
|
|
|
| 3 |
|
| 4 |
+
# API-endepunkt for befolkningsdata
|
| 5 |
url = "https://data.ssb.no/api/v0/no/table/11000"
|
| 6 |
+
|
| 7 |
+
# API-forespørsel (Oslo, siste 20 år)
|
| 8 |
query = {
|
| 9 |
"query": [
|
| 10 |
{"code": "Region", "selection": {"filter": "item", "values": ["0301"]}}, # Oslo
|
|
|
|
| 12 |
],
|
| 13 |
"response": {"format": "json-stat2"}
|
| 14 |
}
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Send forespørselen
|
| 17 |
+
response = requests.post(url, json=query)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Skriv ut hele responsen for feilsøking
|
| 20 |
+
print("API Response:", response.text)
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Prøv å konvertere til JSON
|
| 23 |
+
try:
|
| 24 |
+
data = response.json()
|
| 25 |
+
print("Parsed JSON:", json.dumps(data, indent=4, ensure_ascii=False))
|
| 26 |
+
except json.JSONDecodeError:
|
| 27 |
+
print("❌ Feil: API-et returnerte ikke gyldig JSON")
|
| 28 |
|
| 29 |
+
# Sjekk om "dataset" finnes
|
| 30 |
+
if "dataset" not in data:
|
| 31 |
+
raise ValueError(f"❌ SSB API returnerte ikke forventede data: {data}")
|