Skip to content

Instantly share code, notes, and snippets.

@Oxygenesis
Last active October 17, 2023 02:19
Show Gist options
  • Save Oxygenesis/8ef4b548eea2072570a40066f6e3ff8f to your computer and use it in GitHub Desktop.
Save Oxygenesis/8ef4b548eea2072570a40066f6e3ff8f to your computer and use it in GitHub Desktop.
Testing nb viewer, local to online jupyter notebook
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"language_info": {
"name": "python",
"version": "3.8"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"nbformat": 4,
"nbformat_minor": 4,
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"source": [
"%%writefile iris_classifier.py",
"#writing script for BentoML Service Class",
"from bentoml import env, artifacts, api, BentoService",
"from bentoml.artifact import SklearnModelArtifact",
"from bentoml.adapters import DataframeInput",
"@env(auto_pip_dependencies=True, conda_dependencies=['bentoml'])",
"@artifacts([SklearnModelArtifact('model')])",
"class IrisClassifier(BentoService):",
" @api(input=DataframeInput(), batch=True)",
" def predict(self, df):",
" return self.artifacts.model.predict(df)"
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting iris_classifier.py\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"import pandas as pd",
"import matplotlib.pyplot as plt",
"data = {",
" 'Product': ['A', 'B', 'C', 'D'],",
" 'Sales': [1000, 1500, 800, 950]",
"}",
"df = pd.DataFrame(data)",
"total_sales = df['Sales'].sum()",
"print(f'Total Sales: ${total_sales}')",
"plt.figure(figsize=(10, 6))",
"plt.bar(df['Product'], df['Sales'], color=['blue', 'green', 'red', 'cyan'])",
"plt.title('Sales by Product')",
"plt.xlabel('Product')",
"plt.ylabel('Sales ($)')",
"plt.show()"
],
"outputs": [],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment