{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/robert/Documents/scalable-ml/hbg-weather/.venv/lib/python3.12/site-packages/gradio_client/documentation.py:106: UserWarning: Could not get documentation group for : No known documentation group for module 'gradio.mix'\n", " warnings.warn(f\"Could not get documentation group for {cls}: {exc}\")\n", "/home/robert/Documents/scalable-ml/hbg-weather/.venv/lib/python3.12/site-packages/gradio_client/documentation.py:106: UserWarning: Could not get documentation group for : No known documentation group for module 'gradio.mix'\n", " warnings.warn(f\"Could not get documentation group for {cls}: {exc}\")\n" ] } ], "source": [ "import gradio as gr\n", "import pandas as pd\n", "import numpy as np\n", "import random\n", "import os \n", "import hopsworks" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected. Call `.close()` to terminate connection gracefully.\n", "\n", "Logged in to project, explore it here https://c.app.hopsworks.ai:443/p/1160340\n", "2024-11-19 17:58:26,633 WARNING: using legacy validation callback\n", "Connected. Call `.close()` to terminate connection gracefully.\n", "Finished: Reading data from Hopsworks, using Hopsworks Feature Query Service (2.16s) \n", "\n", "RangeIndex: 1589 entries, 0 to 1588\n", "Data columns (total 6 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 date 1589 non-null object \n", " 1 pm25 1589 non-null float32\n", " 2 country 1589 non-null object \n", " 3 city 1589 non-null object \n", " 4 street 1589 non-null object \n", " 5 url 1589 non-null object \n", "dtypes: float32(1), object(5)\n", "memory usage: 68.4+ KB\n", "None\n", " date pm25 country city street \\\n", "0 2024-02-23 18.0 Sweden Helsingborg Drottninggatan \n", "1 2021-09-22 36.0 Sweden Helsingborg Drottninggatan \n", "2 2022-09-25 55.0 Sweden Helsingborg Drottninggatan \n", "3 2024-08-25 24.0 Sweden Helsingborg Drottninggatan \n", "4 2023-01-06 18.0 Sweden Helsingborg Drottninggatan \n", "\n", " url \n", "0 https://api.waqi.info/feed/@12519/ \n", "1 https://api.waqi.info/feed/@12519/ \n", "2 https://api.waqi.info/feed/@12519/ \n", "3 https://api.waqi.info/feed/@12519/ \n", "4 https://api.waqi.info/feed/@12519/ \n" ] } ], "source": [ "\n", "from datetime import datetime, timedelta\n", "now = datetime.now()\n", "\n", "api_key = os.getenv('HOPSWORKS_API_KEY')\n", "project_name = os.getenv('HOPSWORKS_PROJECT')\n", "\n", "project = hopsworks.login(project=project_name, api_key_value=api_key)\n", "fs = project.get_feature_store() \n", "\n", "air_quality_fg = fs.get_feature_group(\n", " name='air_quality',\n", " version=1,\n", ")\n", "air_quality_df = air_quality_fg.read()\n", "air_quality_df\n", "\n", "print(air_quality_df.info())\n", "print(air_quality_df.head())" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datepm25
02024-02-2318.0
12021-09-2236.0
22022-09-2555.0
32024-08-2524.0
42023-01-0618.0
.........
15842022-11-2642.0
15852021-02-2735.0
15862021-10-2636.0
15872022-05-1221.0
15882024-11-1634.0
\n", "

1589 rows × 2 columns

\n", "
" ], "text/plain": [ " date pm25\n", "0 2024-02-23 18.0\n", "1 2021-09-22 36.0\n", "2 2022-09-25 55.0\n", "3 2024-08-25 24.0\n", "4 2023-01-06 18.0\n", "... ... ...\n", "1584 2022-11-26 42.0\n", "1585 2021-02-27 35.0\n", "1586 2021-10-26 36.0\n", "1587 2022-05-12 21.0\n", "1588 2024-11-16 34.0\n", "\n", "[1589 rows x 2 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "air_quality_df[['date', 'pm25']]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Helsingborg Air Quality Forecast\")\n", " gr.LinePlot(air_quality_df, x=\"time\", y=\"price\")\n", " gr.ScatterPlot(air_quality_df['pm25'], x=\"time\", y=\"price\", color=\"origin\")\n", "\n", "demo.launch() " ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 2 }